org.apache.pig.data.Tuple

Here are the examples of the java api class org.apache.pig.data.Tuple taken from open source projects.

1. TestBuiltin#testROUND_TO()

Project: pig
File: TestBuiltin.java
@Test
public void testROUND_TO() throws Exception {
    Double dbl_out;
    EvalFunc<Double> rounder = new ROUND_TO();
    Tuple tup;
    String expected;
    // Returns double given double
    tup = TupleFactory.getInstance().newTuple(2);
    tup.set(0, 1234.1789d);
    tup.set(1, 8);
    expected = "1234.1789";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, 4);
    expected = "1234.1789";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, 2);
    expected = "1234.18";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, 1);
    expected = "1234.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, 0);
    expected = "1234.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, -1);
    expected = "1230.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, -3);
    expected = "1000.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, -4);
    expected = "0.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 1234.1789d);
    tup.set(1, -5);
    expected = "0.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    // default rounding mode is round-half-to-even
    tup.set(0, 3.25000001d);
    tup.set(1, 1);
    expected = "3.3";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.25d);
    tup.set(1, 1);
    expected = "3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.25d);
    tup.set(1, 1);
    expected = "-3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.15d);
    tup.set(1, 1);
    expected = "3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.15d);
    tup.set(1, 1);
    expected = "-3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.5d);
    tup.set(1, 0);
    expected = "4.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.5d);
    tup.set(1, 0);
    expected = "-4.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 2.5d);
    tup.set(1, 0);
    expected = "2.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -2.5d);
    tup.set(1, 0);
    expected = "-2.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    // Returns double given double; rounding mode is round-half-to-even (but explicitly now)
    tup = TupleFactory.getInstance().newTuple(3);
    // java.math.RoundingMode.HALF_EVEN
    tup.set(2, 6);
    tup.set(0, 3.25d);
    tup.set(1, 1);
    expected = "3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.25d);
    tup.set(1, 1);
    expected = "-3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.15d);
    tup.set(1, 1);
    expected = "3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.15d);
    tup.set(1, 1);
    expected = "-3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.5d);
    tup.set(1, 0);
    expected = "4.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.5d);
    tup.set(1, 0);
    expected = "-4.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 2.5d);
    tup.set(1, 0);
    expected = "2.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -2.5d);
    tup.set(1, 0);
    expected = "-2.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    // Returns double given double; rounding mode is round-half-away-from-zero
    tup = TupleFactory.getInstance().newTuple(3);
    // java.math.RoundingMode.HALF_UP
    tup.set(2, 4);
    tup.set(0, 3.25000001d);
    tup.set(1, 1);
    expected = "3.3";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.25d);
    tup.set(1, 1);
    expected = "3.3";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.25d);
    tup.set(1, 1);
    expected = "-3.3";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.15d);
    tup.set(1, 1);
    expected = "3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.15d);
    tup.set(1, 1);
    expected = "-3.2";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 3.5d);
    tup.set(1, 0);
    expected = "4.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -3.5d);
    tup.set(1, 0);
    expected = "-4.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, 2.5d);
    tup.set(1, 0);
    expected = "3.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
    tup.set(0, -2.5d);
    tup.set(1, 0);
    expected = "-3.0";
    dbl_out = rounder.exec(tup);
    assertEquals(expected, dbl_out.toString());
}

2. TestBuiltin#testConversionBetweenDateTimeAndString()

Project: pig
File: TestBuiltin.java
@Test
public void testConversionBetweenDateTimeAndString() throws Exception {
    ToDate func1 = new ToDate();
    Tuple t1 = TupleFactory.getInstance().newTuple(1);
    t1.set(0, 1231290421000L);
    DateTime dt1 = func1.exec(t1);
    assertEquals(dt1.compareTo(new DateTime("2009-01-07T01:07:01.000Z")), 0);
    ToDateISO func2 = new ToDateISO();
    Tuple t2 = TupleFactory.getInstance().newTuple(1);
    t2.set(0, "2009-01-07T01:07:01.000Z");
    DateTime dt2 = func2.exec(t2);
    assertEquals(dt2.compareTo(new DateTime("2009-01-07T01:07:01.000Z")), 0);
    Tuple t2space = TupleFactory.getInstance().newTuple(1);
    t2space.set(0, "2009-01-07 01:07:01.000Z");
    DateTime dt2space = func2.exec(t2space);
    assertEquals(dt2space.compareTo(new DateTime("2009-01-07T01:07:01.000Z")), 0);
    Tuple t2dateOnly = TupleFactory.getInstance().newTuple(1);
    t2dateOnly.set(0, "2015-05-29");
    DateTime dt2dateOnly = func2.exec(t2dateOnly);
    assertEquals(dt2dateOnly.compareTo(new DateTime("2015-05-29")), 0);
    Tuple t2dateSpaceHour = TupleFactory.getInstance().newTuple(1);
    t2dateSpaceHour.set(0, "2015-05-29 11");
    DateTime dt2dateSpaceHour = func2.exec(t2dateSpaceHour);
    assertEquals(dt2dateSpaceHour.compareTo(new DateTime("2015-05-29T11")), 0);
    Tuple t2dateSpaceHourMin = TupleFactory.getInstance().newTuple(1);
    t2dateSpaceHourMin.set(0, "2015-05-29 11:38");
    DateTime dt2dateSpaceHourMin = func2.exec(t2dateSpaceHourMin);
    assertEquals(dt2dateSpaceHourMin.compareTo(new DateTime("2015-05-29T11:38")), 0);
    Tuple t2dateSpaceHourMinSec = TupleFactory.getInstance().newTuple(1);
    t2dateSpaceHourMinSec.set(0, "2015-05-29 11:38:39");
    DateTime dt2dateSpaceHourMinSec = func2.exec(t2dateSpaceHourMinSec);
    assertEquals(dt2dateSpaceHourMinSec.compareTo(new DateTime("2015-05-29T11:38:39")), 0);
    Tuple t3 = TupleFactory.getInstance().newTuple(1);
    t3.set(0, "2009-01-07T01:07:01.000+08:00");
    DateTime dt3 = func2.exec(t3);
    assertEquals(dt3.compareTo(new DateTime("2009-01-07T01:07:01.000+08:00", DateTimeZone.forID("+08:00"))), 0);
    Tuple t3space = TupleFactory.getInstance().newTuple(1);
    t3space.set(0, "2009-01-07 01:07:01.000+08:00");
    DateTime dt3space = func2.exec(t3space);
    assertEquals(dt3space.compareTo(new DateTime("2009-01-07T01:07:01.000+08:00", DateTimeZone.forID("+08:00"))), 0);
    ToDate2ARGS func3 = new ToDate2ARGS();
    Tuple t4 = TupleFactory.getInstance().newTuple(2);
    t4.set(0, "2009.01.07 AD at 01:07:01");
    t4.set(1, "yyyy.MM.dd G 'at' HH:mm:ss");
    DateTime dt4 = func3.exec(t4);
    assertEquals(dt4.compareTo(new DateTime("2009-01-07T01:07:01.000")), 0);
    Tuple t5 = TupleFactory.getInstance().newTuple(2);
    t5.set(0, "2009.01.07 AD at 01:07:01 +0800");
    t5.set(1, "yyyy.MM.dd G 'at' HH:mm:ss Z");
    DateTime dt5 = func3.exec(t5);
    assertEquals(dt5.compareTo(new DateTime("2009-01-07T01:07:01.000+08:00")), 0);
    ToDate3ARGS func4 = new ToDate3ARGS();
    Tuple t6 = TupleFactory.getInstance().newTuple(3);
    t6.set(0, "2009.01.07 AD at 01:07:01");
    t6.set(1, "yyyy.MM.dd G 'at' HH:mm:ss");
    t6.set(2, "+00:00");
    DateTime dt6 = func4.exec(t6);
    assertEquals(dt6.compareTo(new DateTime("2009-01-07T01:07:01.000", DateTimeZone.forID("+00:00"))), 0);
    Tuple t7 = TupleFactory.getInstance().newTuple(3);
    t7.set(0, "2009.01.07 AD at 01:07:01 +0800");
    t7.set(1, "yyyy.MM.dd G 'at' HH:mm:ss Z");
    t7.set(2, "Asia/Singapore");
    DateTime dt7 = func4.exec(t7);
    assertEquals(dt7.compareTo(new DateTime("2009-01-07T01:07:01.000+08:00", DateTimeZone.forID("+08:00"))), 0);
    ToUnixTime func5 = new ToUnixTime();
    Tuple t8 = TupleFactory.getInstance().newTuple(1);
    t8.set(0, new DateTime(1231290421000L));
    Long ut1 = func5.exec(t8);
    assertEquals(ut1.longValue(), 1231290421L);
    ToString func6 = new ToString();
    Tuple t9 = TupleFactory.getInstance().newTuple(1);
    t9.set(0, ToDate.extractDateTime("2009-01-07T01:07:01.000Z"));
    String dtStr1 = func6.exec(t9);
    assertEquals(dtStr1, "2009-01-07T01:07:01.000Z");
    Tuple t10 = TupleFactory.getInstance().newTuple(1);
    t10.set(0, new DateTime("2009-01-07T09:07:01.000+08:00", DateTimeZone.UTC));
    String dtStr2 = func6.exec(t10);
    assertEquals(dtStr2, "2009-01-07T01:07:01.000Z");
    Tuple t11 = TupleFactory.getInstance().newTuple(2);
    t11.set(0, ToDate.extractDateTime("2009-01-07T01:07:01.000Z"));
    t11.set(1, "yyyy.MM.dd G 'at' HH:mm:ss");
    String dtStr3 = func6.exec(t11);
    assertEquals(dtStr3, "2009.01.07 AD at 01:07:01");
    Tuple t12 = TupleFactory.getInstance().newTuple(2);
    t12.set(0, new DateTime("2009-01-07T01:07:01.000+08:00", DateTimeZone.forID("+08:00")));
    t12.set(1, "yyyy.MM.dd G 'at' HH:mm:ss Z");
    String dtStr4 = func6.exec(t12);
    assertEquals(dtStr4, "2009.01.07 AD at 01:07:01 +0800");
    ToMilliSeconds func7 = new ToMilliSeconds();
    Tuple t13 = TupleFactory.getInstance().newTuple(1);
    t13.set(0, new DateTime(1231290421000L));
    Long ut2 = func7.exec(t11);
    assertEquals(ut2.longValue(), 1231290421000L);
    // Null handling
    t1.set(0, null);
    assertEquals(func1.exec(t1), null);
    assertEquals(func2.exec(t1), null);
    assertEquals(func3.exec(t1), null);
    assertEquals(func4.exec(t1), null);
    assertEquals(func5.exec(t1), null);
    assertEquals(func6.exec(t1), null);
    assertEquals(func7.exec(t1), null);
}

3. TestDecode#testBin()

Project: pig
File: TestDecode.java
@Test
public void testBin() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(8);
    t1.set(0, new Integer(19));
    t1.set(1, "infant");
    t1.set(2, new Integer(5));
    t1.set(3, "young");
    t1.set(4, new Integer(20));
    t1.set(5, "normal");
    t1.set(6, new Integer(60));
    t1.set(7, "old");
    Tuple t2 = TupleFactory.getInstance().newTuple(8);
    t2.set(0, new Double(1.78));
    t2.set(1, "S");
    t2.set(2, new Double(1.70));
    t2.set(3, "M");
    t2.set(4, new Double(1.80));
    t2.set(5, "L");
    t2.set(6, new Double(1.90));
    t2.set(7, "XL");
    Tuple t3 = TupleFactory.getInstance().newTuple(8);
    t3.set(0, null);
    t3.set(1, "S");
    t3.set(2, new Double(1.70));
    t3.set(3, "M");
    t3.set(4, new Double(1.80));
    t3.set(5, "L");
    t3.set(6, new Double(1.90));
    t3.set(7, "XL");
    Tuple t4 = TupleFactory.getInstance().newTuple(8);
    t4.set(0, new Double(1.78));
    t4.set(1, null);
    t4.set(2, new Double(1.70));
    t3.set(3, "M");
    t3.set(4, new Double(1.80));
    t3.set(5, "L");
    t3.set(6, new Double(1.90));
    t4.set(7, "XL");
    Bin func = new Bin();
    String r = func.exec(t1);
    assertTrue(r.equals("young"));
    r = func.exec(t2);
    assertTrue(r.equals("M"));
    r = func.exec(t3);
    assertTrue(r == null);
    try {
        r = func.exec(t4);
        fail("Exception not triggered");
    } catch (IOException e) {
        assertTrue(e.getMessage().equals("Bin : Encounter null in the input"));
    }
}

4. GenRandomData#genRandSmallBagTextTupleWithNulls()

Project: pig
File: GenRandomData.java
public static Tuple genRandSmallBagTextTupleWithNulls(Random r, int num, int limit) {
    if (r == null) {
        Tuple t = new DefaultTuple();
        t.append("RANDOM");
        return t;
    }
    Tuple t = new DefaultTuple();
    t.append(genRandSmallTupDataBag(r, num, limit));
    //TODO Fix
    //The text representation of byte array and char array
    //cannot be disambiguated without annotation. For now,
    //the tuples will not contain byte array
    t.append(genRandTextDBA(r));
    t.append(genRandString(r));
    t.append(r.nextDouble());
    t.append(r.nextFloat());
    t.append(r.nextInt());
    t.append(r.nextLong());
    t.append(genRandMap(r, num));
    t.append(genRandSmallTuple(r, 100));
    t.append(new Boolean(r.nextBoolean()));
    t.append(new DateTime(r.nextLong()));
    t.append(null);
    return t;
}

5. GenRandomData#genRandSmallBagTupleWithNulls()

Project: pig
File: GenRandomData.java
public static Tuple genRandSmallBagTupleWithNulls(Random r, int num, int limit) {
    if (r == null) {
        Tuple t = new DefaultTuple();
        t.append("RANDOM");
        return t;
    }
    Tuple t = new DefaultTuple();
    t.append(genRandSmallTupDataBag(r, num, limit));
    t.append(genRandDBA(r));
    t.append(genRandString(r));
    t.append(r.nextDouble());
    t.append(r.nextFloat());
    t.append(r.nextInt());
    t.append(r.nextLong());
    t.append(genRandMap(r, num));
    t.append(genRandSmallTuple(r, 100));
    t.append(new Boolean(r.nextBoolean()));
    t.append(new DateTime(r.nextLong()));
    t.append(null);
    return t;
}

6. GenRandomData#genRandSmallBagTextTuple()

Project: pig
File: GenRandomData.java
public static Tuple genRandSmallBagTextTuple(Random r, int num, int limit) {
    if (r == null) {
        Tuple t = new DefaultTuple();
        t.append("RANDOM");
        return t;
    }
    Tuple t = new DefaultTuple();
    t.append(genRandSmallTupDataBag(r, num, limit));
    //TODO Fix
    //The text representation of byte array and char array
    //cannot be disambiguated without annotation. For now,
    //the tuples will not contain byte array
    t.append(genRandTextDBA(r));
    t.append(genRandString(r));
    t.append(r.nextDouble());
    t.append(r.nextFloat());
    t.append(r.nextInt());
    t.append(r.nextLong());
    t.append(genRandMap(r, num));
    t.append(genRandSmallTuple(r, 100));
    t.append(new Boolean(r.nextBoolean()));
    t.append(new DateTime(r.nextLong()));
    return t;
}

7. GenRandomData#genRandSmallBagTuple()

Project: pig
File: GenRandomData.java
public static Tuple genRandSmallBagTuple(Random r, int num, int limit) {
    if (r == null) {
        Tuple t = new DefaultTuple();
        t.append("RANDOM");
        return t;
    }
    Tuple t = new DefaultTuple();
    t.append(genRandSmallTupDataBag(r, num, limit));
    t.append(genRandDBA(r));
    t.append(genRandString(r));
    t.append(r.nextDouble());
    t.append(r.nextFloat());
    t.append(r.nextInt());
    t.append(r.nextLong());
    t.append(genRandMap(r, num));
    t.append(genRandSmallTuple(r, 100));
    t.append(new Boolean(r.nextBoolean()));
    t.append(new DateTime(r.nextLong()));
    return t;
}

8. TestTuple#testToDelimitedString()

Project: pig
File: TestTuple.java
@Test
public void testToDelimitedString() {
    Tuple t = mTupleFactory.newTuple();
    t.append(new Integer(1));
    t.append(new Long(2));
    t.append(new Float(1.1f));
    t.append(new Double(2.3));
    t.append("howdy howdy howdy");
    t.append(null);
    t.append("woah there");
    t.append(new Double(2000000.3000000001));
    t.append(new Float(1000000000.1000001f));
    t.append(new Long(2001010101));
    t.append(new Integer(100010101));
    try {
        String expected = "1,2,1.1,2.3,howdy howdy howdy,,woah there,2000000.3,1.0E9,2001010101,100010101";
        assertEquals(expected, t.toDelimitedString(","));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

9. ScorePMML_ElNinoTest#buildElNinoInputEvent()

Project: Surus
File: ScorePMML_ElNinoTest.java
private Tuple buildElNinoInputEvent(String buoy_day_ID, String buoy, String day, String latitude, String longitude, String zon_winds, String mer_winds, String humidity, String airtemp, String s_s_temp) {
    Tuple newTuple = tf.newTuple();
    newTuple.append(buoy_day_ID);
    newTuple.append(buoy);
    newTuple.append(day);
    newTuple.append(latitude);
    newTuple.append(longitude);
    newTuple.append(zon_winds);
    newTuple.append(mer_winds);
    newTuple.append(humidity);
    newTuple.append(airtemp);
    newTuple.append(s_s_temp);
    return newTuple;
}

10. GenRandomData#genMixedTupleToConvert()

Project: pig
File: GenRandomData.java
public static Tuple genMixedTupleToConvert(Random r) {
    Tuple t = TupleFactory.getInstance().newTuple();
    t.append(r.nextInt());
    t.append(r.nextInt());
    long l = 0;
    while (l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) l = r.nextLong();
    t.append(l);
    t.append(r.nextFloat() * 1000);
    t.append(r.nextDouble() * 10000);
    t.append(genRandString(r));
    t.append("K" + genRandString(r));
    t.append("K" + genRandString(r));
    t.append("K" + genRandString(r));
    if (r.nextFloat() > 0.5)
        t.append("true");
    else
        t.append("false");
    t.append(new DateTime(r.nextLong()));
    return t;
}

11. TestBuiltin#testStatsFunc()

Project: pig
File: TestBuiltin.java
@Test
public void testStatsFunc() throws Exception {
    COV cov = new COV("a", "b");
    DataBag dBag = DefaultBagFactory.getInstance().newDefaultBag();
    Tuple tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 1.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 4.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 8.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 4.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 7.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 8.0);
    dBag.add(tup1);
    DataBag dBag1 = DefaultBagFactory.getInstance().newDefaultBag();
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 2.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 2.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 3.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 3.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 2.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 4.0);
    dBag1.add(tup1);
    Tuple input = TupleFactory.getInstance().newTuple(2);
    input.set(0, dBag);
    input.set(1, dBag1);
    DataBag output = cov.exec(input);
    Iterator<Tuple> it = output.iterator();
    Tuple ans = it.next();
    assertEquals(ans.get(0), "a");
    assertEquals(ans.get(1), "b");
    assertEquals(1.11111, (Double) ans.get(2), 0.0005);
    COR cor = new COR("a", "b");
    dBag = DefaultBagFactory.getInstance().newDefaultBag();
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 1.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 4.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 8.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 4.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 7.0);
    dBag.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 8.0);
    dBag.add(tup1);
    dBag1 = DefaultBagFactory.getInstance().newDefaultBag();
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 2.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 2.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 3.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 3.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 2.0);
    dBag1.add(tup1);
    tup1 = TupleFactory.getInstance().newTuple(1);
    tup1.set(0, 4.0);
    dBag1.add(tup1);
    input = TupleFactory.getInstance().newTuple(2);
    input.set(0, dBag);
    input.set(1, dBag1);
    output = cor.exec(input);
    it = output.iterator();
    ans = it.next();
    assertEquals(ans.get(0), "a");
    assertEquals(ans.get(1), "b");
    assertEquals(0.582222509739582, (Double) ans.get(2), 0.0005);
}

12. TestBinInterSedes#testTupleWriteReadLongDiffSizes()

Project: pig
File: TestBinInterSedes.java
/*
     * test sedes of long of diff sizes
     * @throws IOException
     */
@Test
public void testTupleWriteReadLongDiffSizes() throws IOException {
    Random r = new Random(100L);
    Tuple tuple = TupleFactory.getInstance().newTuple();
    tuple.append(new Long(0));
    tuple.append(new Long(1));
    tuple.append(new Long(-1));
    tuple.append(new Long(300));
    tuple.append(new Long(600));
    tuple.append(new Long(10000));
    tuple.append(new Long(-10000));
    tuple.append(new Long(5000000000000000000L));
    tuple.append(new Long(-5000000000000000000L));
    for (int i = 0; i < 100000; i++) {
        tuple.append(new Long(r.nextLong()));
    }
    testTupleSedes(tuple);
}

13. TestBinInterSedes#testTupleWriteRead1()

Project: pig
File: TestBinInterSedes.java
@Test
public void testTupleWriteRead1() throws IOException {
    //create a tuple with columns of different type
    Tuple tuplein = TupleFactory.getInstance().newTuple(7);
    tuplein.set(0, 12);
    Map<String, String> map = new HashMap<String, String>();
    map.put("pig", "scalability");
    tuplein.set(1, map);
    tuplein.set(2, null);
    tuplein.set(3, 12L);
    tuplein.set(4, 1.2F);
    Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
    innerTuple.set(0, "innerTuple");
    tuplein.set(5, innerTuple);
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    bag.add(innerTuple);
    tuplein.set(6, bag);
    testTupleSedes(tuplein);
    assertEquals("(12,[pig#scalability],,12,1.2,(innerTuple),{(innerTuple)})", TupleFormat.format(tuplein));
}

14. TestStuff#testWithOtherTypes()

Project: pig
File: TestStuff.java
@Test
public void testWithOtherTypes() throws IOException {
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, "Replace me now!");
    t.set(1, new Double(8));
    t.set(2, 2);
    t.set(3, "ZZ");
    String result = udf.exec(t);
    assertEquals("Replace ZZ now!", result);
    t = TupleFactory.getInstance().newTuple(4);
    t.set(0, "Replace me now!");
    t.set(1, new Float(14));
    t.set(2, 1);
    t.set(3, ";");
    result = udf.exec(t);
    assertEquals("Replace me now;", result);
}

15. TestRegex#testRegexMatch()

Project: pig
File: TestRegex.java
@Test
public void testRegexMatch() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(2);
    t1.set(0, "/search/iy/xxx");
    t1.set(1, "^\\/search\\/iy\\/.*");
    Tuple t2 = TupleFactory.getInstance().newTuple(2);
    t2.set(0, "http://yahoo.com");
    t2.set(1, "^\\/search\\/iy\\/.*");
    Tuple t3 = TupleFactory.getInstance().newTuple(2);
    t3.set(0, null);
    t3.set(1, "^\\/search\\/iy\\/.*");
    RegexMatch func = new RegexMatch();
    Integer r = func.exec(t1);
    assertTrue(r == 1);
    r = func.exec(t2);
    assertTrue(r == 0);
    r = func.exec(t3);
    assertTrue(r == null);
}

16. TestBuiltInBagToTupleOrString#testBasicBagToStringUDF()

Project: pig
File: TestBuiltInBagToTupleOrString.java
@Test
public void testBasicBagToStringUDF() throws Exception {
    BagFactory bf = BagFactory.getInstance();
    TupleFactory tf = TupleFactory.getInstance();
    Tuple t1 = tf.newTuple(2);
    t1.set(0, "a");
    t1.set(1, 5);
    Tuple t2 = tf.newTuple(2);
    t2.set(0, "c");
    t2.set(1, 6);
    DataBag bag = bf.newDefaultBag();
    bag.add(t1);
    bag.add(t2);
    BagToString udf = new BagToString();
    Tuple udfInput = tf.newTuple(2);
    udfInput.set(0, bag);
    udfInput.set(1, "-");
    String result = udf.exec(udfInput);
    assertEquals("a-5-c-6", result);
}

17. TestBuiltin#testAddSubtractDuration()

Project: pig
File: TestBuiltin.java
@Test
public void testAddSubtractDuration() throws Exception {
    AddDuration func1 = new AddDuration();
    SubtractDuration func2 = new SubtractDuration();
    Tuple t1 = TupleFactory.getInstance().newTuple(2);
    t1.set(0, new DateTime("2009-01-07T01:07:01.000Z"));
    t1.set(1, "PT1S");
    Tuple t2 = TupleFactory.getInstance().newTuple(2);
    t2.set(0, new DateTime("2008-02-06T02:06:02.000Z"));
    t2.set(1, "PT1M");
    Tuple t3 = TupleFactory.getInstance().newTuple(2);
    t3.set(0, new DateTime("2007-03-05T03:05:03.000Z"));
    t3.set(1, "P1D");
    assertEquals(func1.exec(t1), new DateTime("2009-01-07T01:07:02.000Z"));
    assertEquals(func1.exec(t2), new DateTime("2008-02-06T02:07:02.000Z"));
    assertEquals(func1.exec(t3), new DateTime("2007-03-06T03:05:03.000Z"));
    assertEquals(func2.exec(t1), new DateTime("2009-01-07T01:07:00.000Z"));
    assertEquals(func2.exec(t2), new DateTime("2008-02-06T02:05:02.000Z"));
    assertEquals(func2.exec(t3), new DateTime("2007-03-04T03:05:03.000Z"));
}

18. TestPigStreamingUDF#testSerialize__allDataTypes()

Project: pig
File: TestPigStreamingUDF.java
@Test
public void testSerialize__allDataTypes() throws IOException {
    Tuple t = tf.newTuple(8);
    t.set(0, null);
    t.set(1, true);
    t.set(2, 2);
    t.set(3, 3L);
    t.set(4, 4.0f);
    t.set(5, 5.0d);
    t.set(6, new DataByteArray("six"));
    t.set(7, "seven");
    byte[] expectedOutput = "|-_|\t_Btrue|\t_I2|\t_L3|\t_F4.0|\t_D5.0|\t_Asix|\t_Cseven|_\n".getBytes();
    Assert.assertTrue(assertEquals(expectedOutput, ps.serializeToBytes(t)));
}

19. TestPigStreaming#testSerialize__allDataTypes()

Project: pig
File: TestPigStreaming.java
@Test
public void testSerialize__allDataTypes() throws IOException {
    Tuple t = tf.newTuple(8);
    t.set(0, null);
    t.set(1, true);
    t.set(2, 2);
    t.set(3, 3L);
    t.set(4, 4.0f);
    t.set(5, 5.0d);
    t.set(6, new DataByteArray("six"));
    t.set(7, "seven");
    byte[] expectedOutput = "\ttrue\t2\t3\t4.0\t5.0\tsix\tseven\n".getBytes();
    byte[] output = ps.serialize(t);
    Assert.assertArrayEquals(expectedOutput, output);
}

20. TestBuiltInBagToTupleOrString#testUseDefaultDelimiterBagToStringUDF()

Project: pig
File: TestBuiltInBagToTupleOrString.java
@Test
public void testUseDefaultDelimiterBagToStringUDF() throws Exception {
    BagFactory bf = BagFactory.getInstance();
    TupleFactory tf = TupleFactory.getInstance();
    Tuple t1 = tf.newTuple(2);
    t1.set(0, "a");
    t1.set(1, 5);
    Tuple t2 = tf.newTuple(2);
    t2.set(0, "c");
    t2.set(1, 6);
    DataBag bag = bf.newDefaultBag();
    bag.add(t1);
    bag.add(t2);
    BagToString udf = new BagToString();
    Tuple udfInput = tf.newTuple(1);
    udfInput.set(0, bag);
    String result = udf.exec(udfInput);
    assertEquals("a_5_c_6", result);
}

21. TestPigStreamingUDF#testSerialize__bag()

Project: pig
File: TestPigStreamingUDF.java
@Test
public void testSerialize__bag() throws IOException {
    Tuple t = tf.newTuple(1);
    Tuple t1 = tf.newTuple(2);
    Tuple t2 = tf.newTuple(2);
    List<Tuple> bagTuples = new ArrayList<Tuple>();
    bagTuples.add(t1);
    bagTuples.add(t2);
    t1.set(0, "A");
    t1.set(1, "B");
    t2.set(0, 1);
    t2.set(1, 2);
    DataBag b = DefaultBagFactory.getInstance().newDefaultBag(bagTuples);
    t.set(0, b);
    byte[] expectedOutput = "|{_|(_CA|,_CB|)_|,_|(_I1|,_I2|)_|}_|_\n".getBytes();
    Assert.assertTrue(assertEquals(expectedOutput, ps.serializeToBytes(t)));
}

22. TestDecode#testDecode()

Project: pig
File: TestDecode.java
@Test
public void testDecode() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(6);
    t1.set(0, new Integer(1));
    t1.set(1, 0);
    t1.set(2, "Sales");
    t1.set(3, 1);
    t1.set(4, "Engineering");
    t1.set(5, "Other");
    Tuple t2 = TupleFactory.getInstance().newTuple(6);
    t2.set(0, new Integer(3));
    t2.set(1, 0);
    t2.set(2, "Sales");
    t2.set(3, 1);
    t2.set(4, "Engineering");
    t2.set(5, "Other");
    Tuple t3 = TupleFactory.getInstance().newTuple(6);
    t3.set(0, null);
    t3.set(1, 0);
    t3.set(2, "Sales");
    t3.set(3, 1);
    t3.set(4, "Engineering");
    t3.set(5, "Other");
    Tuple t4 = TupleFactory.getInstance().newTuple(6);
    t4.set(0, new Integer(1));
    t4.set(1, null);
    t4.set(2, "Sales");
    t4.set(3, 1);
    t4.set(4, "Engineering");
    t4.set(5, "Other");
    Decode func = new Decode();
    String r = func.exec(t1);
    assertTrue(r.equals("Engineering"));
    r = func.exec(t2);
    assertTrue(r.equals("Other"));
    r = func.exec(t3);
    assertTrue(r == null);
    try {
        r = func.exec(t4);
        fail("Exception not triggered");
    } catch (IOException e) {
        assertTrue(e.getMessage().equals("Decode : Encounter null in the input"));
    }
}

23. TestOver#testDenseRankWithMultiKey()

Project: pig
File: TestOver.java
@Test
public void testDenseRankWithMultiKey() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    Random r = new Random();
    Tuple t = TupleFactory.getInstance().newTuple(3);
    t.set(0, null);
    t.set(1, r.nextInt(100));
    t.set(2, "a");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, null);
    t.set(1, r.nextInt(100));
    t.set(2, "b");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 2);
    t.set(1, r.nextInt(100));
    t.set(2, "b");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 5);
    t.set(1, r.nextInt(100));
    inbag.add(t);
    t.set(2, "b");
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 5);
    t.set(1, r.nextInt(100));
    t.set(2, "c");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 5);
    t.set(1, r.nextInt(100));
    t.set(2, "c");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 7);
    t.set(1, r.nextInt(100));
    t.set(2, "z");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(6);
    t.set(0, inbag);
    t.set(1, "dense_rank");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 0);
    t.set(5, 2);
    DataBag outbag = func.exec(t);
    assertEquals(7, outbag.size());
    Iterator<Tuple> iter = outbag.iterator();
    t = iter.next();
    assertEquals(1, t.get(0));
    t = iter.next();
    assertEquals(2, t.get(0));
    t = iter.next();
    assertEquals(3, t.get(0));
    t = iter.next();
    assertEquals(4, t.get(0));
    t = iter.next();
    assertEquals(5, t.get(0));
    t = iter.next();
    assertEquals(5, t.get(0));
    t = iter.next();
    assertEquals(6, t.get(0));
}

24. TestOver#testRankWithMultiKey()

Project: pig
File: TestOver.java
@Test
public void testRankWithMultiKey() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    Random r = new Random();
    Tuple t = TupleFactory.getInstance().newTuple(3);
    t.set(0, null);
    t.set(1, r.nextInt(100));
    t.set(2, "a");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, null);
    t.set(1, r.nextInt(100));
    t.set(2, "b");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 2);
    t.set(1, r.nextInt(100));
    t.set(2, "b");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 5);
    t.set(1, r.nextInt(100));
    inbag.add(t);
    t.set(2, "b");
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 5);
    t.set(1, r.nextInt(100));
    t.set(2, "c");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 5);
    t.set(1, r.nextInt(100));
    t.set(2, "c");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(3);
    t.set(0, 7);
    t.set(1, r.nextInt(100));
    t.set(2, "z");
    inbag.add(t);
    t = TupleFactory.getInstance().newTuple(6);
    t.set(0, inbag);
    t.set(1, "rank");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 0);
    t.set(5, 2);
    DataBag outbag = func.exec(t);
    assertEquals(7, outbag.size());
    Iterator<Tuple> iter = outbag.iterator();
    t = iter.next();
    assertEquals(1, t.get(0));
    t = iter.next();
    assertEquals(2, t.get(0));
    t = iter.next();
    assertEquals(3, t.get(0));
    t = iter.next();
    assertEquals(4, t.get(0));
    t = iter.next();
    assertEquals(5, t.get(0));
    t = iter.next();
    assertEquals(5, t.get(0));
    t = iter.next();
    assertEquals(7, t.get(0));
}

25. TestOver#testLeadWithRowsAheadDefault()

Project: pig
File: TestOver.java
@Test
public void testLeadWithRowsAheadDefault() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(6);
    t.set(0, inbag);
    t.set(1, "lead");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 3);
    t.set(5, 99);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 3;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        if (count < 10)
            assertEquals(new Integer(count++), to.get(0));
        else
            assertEquals(new Integer(99), to.get(0));
    }
}

26. TestPigStreaming#testSerialize__bag()

Project: pig
File: TestPigStreaming.java
@Test
public void testSerialize__bag() throws IOException {
    Tuple t = tf.newTuple(1);
    Tuple t1 = tf.newTuple(2);
    Tuple t2 = tf.newTuple(2);
    List<Tuple> bagTuples = new ArrayList<Tuple>();
    bagTuples.add(t1);
    bagTuples.add(t2);
    t1.set(0, "A");
    t1.set(1, "B");
    t2.set(0, 1);
    t2.set(1, 2);
    DataBag b = DefaultBagFactory.getInstance().newDefaultBag(bagTuples);
    t.set(0, b);
    byte[] expectedOutput = "{(A,B),(1,2)}\n".getBytes();
    byte[] output = ps.serialize(t);
    Assert.assertArrayEquals(expectedOutput, output);
}

27. TestOver#testNtileHundred()

Project: pig
File: TestOver.java
@Test
public void testNtileHundred() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    Random r = new Random();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(2);
        t.set(0, i);
        t.set(1, r.nextInt(100));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(5);
    t.set(0, inbag);
    t.set(1, "ntile");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 100);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 1;
    for (Tuple to : outbag) {
        assertEquals(count, to.get(0));
        count++;
    }
}

28. TestOver#testNtileTen()

Project: pig
File: TestOver.java
@Test
public void testNtileTen() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    Random r = new Random();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(2);
        t.set(0, i);
        t.set(1, r.nextInt(100));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(5);
    t.set(0, inbag);
    t.set(1, "ntile");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 10);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 1;
    for (Tuple to : outbag) {
        assertEquals(count, to.get(0));
        count++;
    }
}

29. TestOver#testDenseRankSimple()

Project: pig
File: TestOver.java
@Test
public void testDenseRankSimple() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    Random r = new Random();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(2);
        t.set(0, i);
        t.set(1, r.nextInt(100));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(5);
    t.set(0, inbag);
    t.set(1, "dense_rank");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 0);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 1;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(count++, to.get(0));
    }
}

30. TestOver#testRankSimple()

Project: pig
File: TestOver.java
@Test
public void testRankSimple() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    Random r = new Random();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(2);
        t.set(0, i);
        t.set(1, r.nextInt(100));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(5);
    t.set(0, inbag);
    t.set(1, "rank");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 0);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 1;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(count++, to.get(0));
    }
}

31. TestOver#testLeadWithRowsAheadNoDefault()

Project: pig
File: TestOver.java
@Test
public void testLeadWithRowsAheadNoDefault() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(5);
    t.set(0, inbag);
    t.set(1, "lead");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, 3);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 3;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        if (count < 10)
            assertEquals(new Integer(count++), to.get(0));
        else
            assertNull(to.get(0));
    }
}

32. ChukwaArchive#getNext()

Project: HiTune
File: ChukwaArchive.java
@Override
public Tuple getNext() throws IOException {
    ChukwaArchiveKey key = new ChukwaArchiveKey();
    ChunkImpl val = ChunkImpl.getBlankChunk();
    if (r.getPosition() > end || !r.next(key, val)) {
        return null;
    }
    Tuple t = tf.newTuple(schemaFieldCount);
    t.set(0, new Long(val.seqID));
    t.set(1, val.getDataType());
    t.set(2, val.getStreamName());
    t.set(3, val.getSource());
    t.set(4, val.getTags());
    byte[] data = val.getData();
    t.set(5, (data == null) ? new DataByteArray() : new DataByteArray(data));
    //    System.out.println("returning " + t);
    return t;
}

33. TestDataModel#testTupleEquals()

Project: pig
File: TestDataModel.java
@Test
public void testTupleEquals() throws Exception {
    TupleFactory tf = TupleFactory.getInstance();
    Tuple t1 = tf.newTuple();
    Tuple t2 = tf.newTuple();
    t1.append(new Integer(3));
    t2.append(new Integer(3));
    assertFalse("different object", t1.equals(new String()));
    assertTrue("same data", t1.equals(t2));
    t2 = tf.newTuple();
    t2.append(new Integer(4));
    assertFalse("different data", t1.equals(t2));
    t2 = tf.newTuple();
    t2.append(new Integer(3));
    t2.append(new Integer(3));
    assertFalse("different size", t1.equals(t2));
}

34. TestPigStreaming#testSerialize__nestedTuple()

Project: pig
File: TestPigStreaming.java
@Test
public void testSerialize__nestedTuple() throws IOException {
    Tuple t = tf.newTuple(2);
    Tuple nestedTuple = tf.newTuple(2);
    nestedTuple.set(0, "sam");
    nestedTuple.set(1, "oes");
    t.set(0, nestedTuple);
    t.set(1, "basil");
    byte[] expectedOutput = "(sam,oes)\tbasil\n".getBytes();
    byte[] output = ps.serialize(t);
    Assert.assertArrayEquals(expectedOutput, output);
}

35. TestTop#testTopAlgebraic()

Project: pig
File: TestTop.java
@Test
public void testTopAlgebraic() throws IOException {
    setup();
    // two initial results
    Tuple init1 = (new Top.Initial()).exec(inputTuple_);
    Tuple init2 = (new Top.Initial()).exec(inputTuple_);
    // two intermediate results
    DataBag intermedBag = bagFactory_.newDefaultBag();
    intermedBag.add(init1);
    intermedBag.add(init2);
    Tuple intermedInput = tupleFactory_.newTuple(intermedBag);
    Tuple intermedOutput1 = (new Top.Intermed()).exec(intermedInput);
    Tuple intermedOutput2 = (new Top.Intermed()).exec(intermedInput);
    checkItemsGT((DataBag) intermedOutput1.get(2), 1, 94);
    // final result
    DataBag finalInputBag = bagFactory_.newDefaultBag();
    finalInputBag.add(intermedOutput1);
    finalInputBag.add(intermedOutput2);
    Tuple finalInput = tupleFactory_.newTuple(finalInputBag);
    DataBag outBag = (new Top.Final()).exec(finalInput);
    assertEquals(outBag.size(), 10L);
    checkItemsGT(outBag, 1, 96);
}

36. TestBinInterSedes#testTupleWriteReadIntDiffSizes()

Project: pig
File: TestBinInterSedes.java
/**
     * test sedes of int of diff sizes
     * @throws IOException
     */
@Test
public void testTupleWriteReadIntDiffSizes() throws IOException {
    //create a tuple with integer columns of different sizes
    Tuple tuple = TupleFactory.getInstance().newTuple();
    //boolean rep
    tuple.append(new Integer(0));
    //boolean rep
    tuple.append(new Integer(1));
    //fits into byte
    tuple.append(new Integer(125));
    //fits into short
    tuple.append(new Integer(1024));
    //fits into int (=~ 2 ^30)
    tuple.append(new Integer(1024 * 1024 * 1024));
    testTupleSedes(tuple);
}

37. TestOver#testNtileBadArgs()

Project: pig
File: TestOver.java
@Test
public void testNtileBadArgs() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(5);
    t.set(0, inbag);
    t.set(1, "ntile");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, "fred");
    boolean caught = false;
    try {
        DataBag outbag = func.exec(t);
    } catch (ExecException ioe) {
        caught = true;
        assertTrue(ioe.getMessage().contains("Ntile expected integer"));
    }
    assertTrue(caught);
}

38. TestOver#testRankBadArgs()

Project: pig
File: TestOver.java
@Test
public void testRankBadArgs() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(5);
    t.set(0, inbag);
    t.set(1, "rank");
    t.set(2, -1);
    t.set(3, -1);
    t.set(4, "fred");
    boolean caught = false;
    try {
        DataBag outbag = func.exec(t);
    } catch (ExecException ioe) {
        caught = true;
        assertTrue(ioe.getMessage().contains("Rank expected column number"));
    }
    assertTrue(caught);
}

39. TestOver#testLeadDefaults()

Project: pig
File: TestOver.java
@Test
public void testLeadDefaults() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "lead");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 1;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        if (count < 10)
            assertEquals(new Integer(count++), to.get(0));
        else
            assertNull(to.get(0));
    }
}

40. TestOver#testRowNumber()

Project: pig
File: TestOver.java
@Test
public void testRowNumber() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (double) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "row_number");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 1;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Integer(count++), to.get(0));
    }
}

41. TestOver#testMaxString()

Project: pig
File: TestOver.java
@Test
public void testMaxString() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new Integer(i).toString());
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "max(chararray)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals("9", to.get(0));
    }
}

42. TestOver#testAvgBigDecimal()

Project: pig
File: TestOver.java
@Test
public void testAvgBigDecimal() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new BigDecimal(i));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "avg(bigdecimal)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new BigDecimal(4.5), to.get(0));
    }
}

43. TestOver#testAvgLong()

Project: pig
File: TestOver.java
@Test
public void testAvgLong() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (long) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "avg(long)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(4.5), to.get(0));
    }
}

44. TestOver#testAvgInt()

Project: pig
File: TestOver.java
@Test
public void testAvgInt() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "avg(int)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(4.5), to.get(0));
    }
}

45. TestOver#testAvgFloat()

Project: pig
File: TestOver.java
@Test
public void testAvgFloat() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (float) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "avg(float)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(4.5), to.get(0));
    }
}

46. TestOver#testAvgByteArray()

Project: pig
File: TestOver.java
@Test
public void testAvgByteArray() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new DataByteArray("1"));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "avg(bytearray)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(1.0), to.get(0));
    }
}

47. TestOver#testAvgDouble()

Project: pig
File: TestOver.java
@Test
public void testAvgDouble() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (double) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "avg(double)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(4.5), to.get(0));
    }
}

48. TestOver#testSumBigDecimal()

Project: pig
File: TestOver.java
@Test
public void testSumBigDecimal() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new BigDecimal(1));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "sum(bigdecimal)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new BigDecimal(10), to.get(0));
    }
}

49. TestOver#testSumLong()

Project: pig
File: TestOver.java
@Test
public void testSumLong() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, 1L);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "sum(long)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Long(10), to.get(0));
    }
}

50. TestOver#testSumInt()

Project: pig
File: TestOver.java
@Test
public void testSumInt() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, 1);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "sum(int)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Long(10), to.get(0));
    }
}

51. TestOver#testSumFloat()

Project: pig
File: TestOver.java
@Test
public void testSumFloat() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, 1.0f);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "sum(float)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(10.0), to.get(0));
    }
}

52. TestOver#testSumByteArray()

Project: pig
File: TestOver.java
@Test
public void testSumByteArray() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new DataByteArray("1"));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "sum(bytearray)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(10.0), to.get(0));
    }
}

53. TestOver#testSumDouble()

Project: pig
File: TestOver.java
@Test
public void testSumDouble() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, 1.0);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "sum(double)");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(10.0), to.get(0));
    }
}

54. TestOver#testCountCurrentToUnboundedFollowing()

Project: pig
File: TestOver.java
@Test
public void testCountCurrentToUnboundedFollowing() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, 1);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "count");
    t.set(2, 0);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int cnt = 10;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Long(cnt--), to.get(0));
    }
}

55. TestOver#testCountNoWindow()

Project: pig
File: TestOver.java
@Test
public void testCountNoWindow() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, 1);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(4);
    t.set(0, inbag);
    t.set(1, "count");
    t.set(2, -1);
    t.set(3, -1);
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Long(10), to.get(0));
    }
}

56. TestTextDataParser#testBag()

Project: pig
File: TestTextDataParser.java
@Test
public void testBag() throws Exception {
    String myBag = "{(1,a),(2,b)}";
    Object o = ps.getLoadCaster().bytesToBag(myBag.getBytes(), getBagFieldSchema());
    assertTrue(o instanceof DataBag);
    DataBag b = (DataBag) o;
    DataBag expectedBag = bagFactory.newDefaultBag();
    Tuple expectedTuple = tupleFactory.newTuple(2);
    expectedTuple.set(0, 1);
    expectedTuple.set(1, "a");
    expectedBag.add(expectedTuple);
    expectedTuple = tupleFactory.newTuple(2);
    expectedTuple.set(0, 2);
    expectedTuple.set(1, "b");
    expectedBag.add(expectedTuple);
    assertEquals(expectedBag, b);
}

57. Fixtures#buildPersonTuple()

Project: elephant-bird
File: Fixtures.java
public static Tuple buildPersonTuple() throws ExecException {
    DataBag phoneBag = new NonSpillableDataBag(Lists.newArrayList(makePhoneNumberTuple("415-999-9999", null), makePhoneNumberTuple("415-666-6666", "MOBILE"), makePhoneNumberTuple("415-333-3333", "WORK")));
    Tuple entryTuple = tf_.newTuple(4);
    entryTuple.set(0, "Elephant Bird");
    entryTuple.set(1, 123);
    entryTuple.set(2, "[email protected]");
    entryTuple.set(3, phoneBag);
    return entryTuple;
}

58. DataGenerator#generateSequentialTuples()

Project: Cubert
File: DataGenerator.java
public List<Tuple> generateSequentialTuples(final int N, final BlockSchema schema) throws ExecException {
    List<Tuple> tuples = new ArrayList<Tuple>();
    Tuple prev = newTuple(schema.getNumColumns());
    prev.set(0, 1);
    prev.set(1, 1L);
    prev.set(2, 1.0);
    prev.set(3, nextString());
    for (int i = 1; i <= N; i++) {
        Tuple t = createSequentialTuple(schema, prev);
        tuples.add(t);
        prev = t;
    }
    return tuples;
}

59. TestPOUserFunc#udfCompare()

Project: pig
File: TestPOUserFunc.java
public void udfCompare(DataBag input) throws ExecException {
    String funcSpec = WeirdComparator.class.getName() + "()";
    POUserComparisonFunc userFunc = new POUserComparisonFunc(new OperatorKey("", r.nextLong()), -1, null, new FuncSpec(funcSpec));
    Iterator<Tuple> it = input.iterator();
    Tuple t1 = it.next();
    Tuple t2 = it.next();
    t1.append(2);
    t2.append(3);
    userFunc.attachInput(t1, t2);
    Integer i = null;
    // System.out.println(t1 + " " + t2);
    int result = (Integer) (userFunc.getNextInteger().result);
    assertEquals(-1, result);
}

60. TestInvoker#testStringInvoker()

Project: pig
File: TestInvoker.java
@Test
public void testStringInvoker() throws SecurityException, ClassNotFoundException, NoSuchMethodException, IOException {
    // Test non-static method
    InvokeForString is = new InvokeForString("java.lang.String.toUpperCase", "String", "false");
    assertEquals("FOO", is.exec(tf_.newTuple("foo")));
    // both "static" and "true" should work
    // Test static method
    is = new InvokeForString("java.lang.String.valueOf", "int", "true");
    Tuple t = tf_.newTuple(1);
    t.set(0, 231);
    assertEquals("231", is.exec(t));
    // test default (should be static)
    is = new InvokeForString("java.lang.String.valueOf", "int");
    assertEquals("231", is.exec(t));
    // Test method with multiple args
    is = new InvokeForString(TestInvoker.class.getName() + ".concatStrings", "String String");
    t = tf_.newTuple(2);
    t.set(0, "foo");
    t.set(1, "bar");
    assertEquals("foobar", is.exec(t));
}

61. TestStringUDFs#testEndsWith()

Project: pig
File: TestStringUDFs.java
@Test
public void testEndsWith() throws IOException {
    ENDSWITH endsWith = new ENDSWITH();
    Tuple testTuple1 = Util.buildTuple("foo", "bar");
    assertFalse("String suffix should not match", endsWith.exec(testTuple1));
    Tuple testTuple2 = Util.buildTuple("foobaz", "foo");
    assertFalse("String suffix should not match", endsWith.exec(testTuple2));
    Tuple testTuple3 = Util.buildTuple("foobaz", "baz");
    assertTrue("String suffix should match", endsWith.exec(testTuple3));
    Tuple testTuple4 = Util.buildTuple(null, "bar");
    assertNull("Should return null", endsWith.exec(testTuple4));
}

62. TestBinInterSedes#testTupleWriteReadMapDiffSizes()

Project: pig
File: TestBinInterSedes.java
/**
     * test sedes  with maps of diff sizes
     * @throws IOException
     */
@Test
public void testTupleWriteReadMapDiffSizes() throws IOException {
    // tuple with ByteArray and strings of different sizes
    Tuple tuple = TupleFactory.getInstance().newTuple();
    Map<String, Object> tinyMap = createMap(10);
    Map<String, Object> smallMap = createMap(1000);
    Map<String, Object> largeMap = createMap(100 * 1024);
    tuple.append(tinyMap);
    tuple.append(smallMap);
    tuple.append(largeMap);
    testTupleSedes(tuple);
}

63. TestBinInterSedes#testTupleWriteReadBagDiffSizes()

Project: pig
File: TestBinInterSedes.java
/**
     * test sedes  with bags of diff sizes
     * @throws IOException
     */
@Test
public void testTupleWriteReadBagDiffSizes() throws IOException {
    // tuple with ByteArray and strings of different sizes
    Tuple tuple = TupleFactory.getInstance().newTuple();
    DataBag tinyBag = createBag(10);
    DataBag smallBag = createBag(1000);
    DataBag largeBag = createBag(100 * 1024);
    tuple.append(tinyBag);
    tuple.append(smallBag);
    tuple.append(largeBag);
    testTupleSedes(tuple);
}

64. TestBagFormat#testBagFormat()

Project: pig
File: TestBagFormat.java
@Test
public void testBagFormat() throws Exception {
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    Tuple tuple_1 = TupleFactory.getInstance().newTuple(1);
    tuple_1.set(0, 12);
    bag.add(tuple_1);
    Tuple tuple_2 = TupleFactory.getInstance().newTuple(1);
    DataBag innerBag = BagFactory.getInstance().newDefaultBag();
    innerBag.add(tuple_1);
    tuple_2.set(0, (innerBag));
    bag.add(tuple_2);
    System.out.println(BagFormat.format(bag));
    assertEquals("{(12),({(12)})}", BagFormat.format(bag));
}

65. TestDecode#testBinCond()

Project: pig
File: TestDecode.java
@Test
public void testBinCond() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(7);
    t1.set(0, false);
    t1.set(1, "s&a");
    t1.set(2, false);
    t1.set(3, "a");
    t1.set(4, true);
    t1.set(5, "s");
    t1.set(6, "n");
    Tuple t2 = TupleFactory.getInstance().newTuple(7);
    t2.set(0, null);
    t2.set(1, "s&a");
    t2.set(2, false);
    t2.set(3, "a");
    t2.set(4, true);
    t2.set(5, "s");
    t2.set(6, "n");
    Tuple t3 = TupleFactory.getInstance().newTuple(7);
    t3.set(0, false);
    t3.set(1, "s&a");
    t3.set(2, null);
    t3.set(3, "a");
    t3.set(4, true);
    t3.set(5, "s");
    t3.set(6, "n");
    BinCond func = new BinCond();
    String r = func.exec(t1);
    assertTrue(r.equals("s"));
    r = func.exec(t2);
    assertTrue(r == null);
    try {
        r = func.exec(t3);
        fail("Exception not triggered");
    } catch (IOException e) {
        assertTrue(e.getMessage().equals("BinCond : Encounter null in the input"));
    }
}

66. TestOver#testLastValue()

Project: pig
File: TestOver.java
@Test
public void testLastValue() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "last_value");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 0;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Integer(count++), to.get(0));
    }
}

67. TestOver#testFirstValue()

Project: pig
File: TestOver.java
@Test
public void testFirstValue() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (double) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "first_value");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(0.0), to.get(0));
    }
}

68. TestOver#testMaxBigDecimal()

Project: pig
File: TestOver.java
@Test
public void testMaxBigDecimal() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new BigDecimal(i));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "max(bigdecimal)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 0;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new BigDecimal(count++), to.get(0));
    }
}

69. TestOver#testMaxLong()

Project: pig
File: TestOver.java
@Test
public void testMaxLong() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (long) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "max(long)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 0;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Long(count++), to.get(0));
    }
}

70. TestOver#testMaxInt()

Project: pig
File: TestOver.java
@Test
public void testMaxInt() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "max(int)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 0;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Integer(count++), to.get(0));
    }
}

71. TestOver#testMaxFloat()

Project: pig
File: TestOver.java
@Test
public void testMaxFloat() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (float) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "max(float)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 0;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Float(count++), to.get(0));
    }
}

72. TestOver#testMaxByteArray()

Project: pig
File: TestOver.java
@Test
public void testMaxByteArray() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new DataByteArray(new Integer(i).toString()));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "max(bytearray)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 0;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(count++), to.get(0));
    }
}

73. TestOver#testMaxDouble()

Project: pig
File: TestOver.java
@Test
public void testMaxDouble() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (double) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "max(double)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int count = 0;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(count++), to.get(0));
    }
}

74. TestOver#testMinBigDecimal()

Project: pig
File: TestOver.java
@Test
public void testMinBigDecimal() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new BigDecimal(i));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "min(bigdecimal)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new BigDecimal(0), to.get(0));
    }
}

75. TestOver#testMinString()

Project: pig
File: TestOver.java
@Test
public void testMinString() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new Integer(i).toString());
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "min(chararray)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals("0", to.get(0));
    }
}

76. TestOver#testMinLong()

Project: pig
File: TestOver.java
@Test
public void testMinLong() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (long) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "min(long)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Long(0), to.get(0));
    }
}

77. TestOver#testMinInt()

Project: pig
File: TestOver.java
@Test
public void testMinInt() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "min(int)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Integer(0), to.get(0));
    }
}

78. TestOver#testMinFloat()

Project: pig
File: TestOver.java
@Test
public void testMinFloat() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (float) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "min(float)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Float(0.0), to.get(0));
    }
}

79. TestOver#testMinByteArray()

Project: pig
File: TestOver.java
@Test
public void testMinByteArray() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, new DataByteArray(new Integer(i).toString()));
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "min(bytearray)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(0.0), to.get(0));
    }
}

80. TestOver#testMinDouble()

Project: pig
File: TestOver.java
@Test
public void testMinDouble() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, (double) i);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "min(double)");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Double(0.0), to.get(0));
    }
}

81. TestOver#testCountPrecedingUnboundedToCurrent()

Project: pig
File: TestOver.java
@Test
public void testCountPrecedingUnboundedToCurrent() throws Exception {
    Over func = new Over();
    DataBag inbag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 10; i++) {
        Tuple t = TupleFactory.getInstance().newTuple(1);
        t.set(0, 1);
        inbag.add(t);
    }
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, inbag);
    t.set(1, "count");
    DataBag outbag = func.exec(t);
    assertEquals(10, outbag.size());
    int cnt = 1;
    for (Tuple to : outbag) {
        assertEquals(1, to.size());
        assertEquals(new Long(cnt++), to.get(0));
    }
}

82. TestInvoker#testStringInvoker()

Project: elephant-bird
File: TestInvoker.java
@Test
public void testStringInvoker() throws SecurityException, ClassNotFoundException, NoSuchMethodException, IOException {
    // Test non-static method
    InvokeForString is = new InvokeForString("java.lang.String.toUpperCase", "String", "false");
    assertEquals("FOO", is.exec(tf_.newTuple("foo")));
    // both "static" and "true" should work
    // Test static method
    is = new InvokeForString("java.lang.String.valueOf", "int", "true");
    Tuple t = tf_.newTuple(1);
    t.set(0, 231);
    assertEquals("231", is.exec(t));
    // test default (should be static)
    is = new InvokeForString("java.lang.String.valueOf", "int");
    assertEquals("231", is.exec(t));
    // Test method with multiple args
    is = new InvokeForString(TestInvoker.class.getName() + ".concatStrings", "String String");
    t = tf_.newTuple(2);
    t.set(0, "foo");
    t.set(1, "bar");
    assertEquals("foobar", is.exec(t));
}

83. TestFunctions#testTypecast()

Project: Cubert
File: TestFunctions.java
@Test
public void testTypecast() throws PreconditionException, ExecException {
    DataType inputType = DataType.BOOLEAN;
    DataType outputType = DataType.STRING;
    BlockSchema inputSchema = new BlockSchema(inputType.toString() + " col");
    Typecast function = new Typecast(outputType);
    function.outputSchema(inputSchema);
    Tuple tuple = TupleFactory.getInstance().newTuple(1);
    tuple.set(0, null);
    Assert.assertEquals(null, function.eval(tuple));
    tuple.set(0, true);
    Assert.assertEquals("true", function.eval(tuple));
    tuple.set(0, false);
    Assert.assertEquals("false", function.eval(tuple));
}

84. TestTOP#fillTuple()

Project: pig
File: TestTOP.java
public static Tuple fillTuple(int start, int stop) throws ExecException {
    Tuple tuple = tupleFactory_.newTuple(3);
    DataBag dBag = bagFactory_.newDefaultBag();
    // set N = 10 i.e retain top 10 tuples
    tuple.set(0, 10);
    // compare tuples by field number 1
    tuple.set(1, 1);
    // set the data bag containing the tuples
    tuple.set(2, dBag);
    // generate tuples of the form (group-1, 1), (group-2, 2) ...
    for (long i = start; i < stop; i++) {
        Tuple nestedTuple = tupleFactory_.newTuple(2);
        nestedTuple.set(0, "group-" + i);
        nestedTuple.set(1, i);
        dBag.add(nestedTuple);
    }
    return tuple;
}

85. TestRank3#verifyExpected()

Project: pig
File: TestRank3.java
public void verifyExpected(List<Tuple> out, Multiset<Tuple> expected) {
    Multiset<Tuple> resultMultiset = TreeMultiset.create();
    for (Tuple tup : out) {
        resultMultiset.add(tup);
    }
    StringBuilder error = new StringBuilder("Result does not match.\nActual result:\n");
    for (Tuple tup : resultMultiset.elementSet()) {
        error.append(tup).append(" x ").append(resultMultiset.count(tup)).append("\n");
    }
    error.append("Expceted result:\n");
    for (Tuple tup : ImmutableSortedSet.copyOf(expected)) {
        error.append(tup).append(" x ").append(expected.count(tup)).append("\n");
    }
    //This one line test should be sufficient but adding the above
    //for-loop for better error messages
    assertTrue(error.toString(), resultMultiset.equals(expected));
}

86. TestRank2#verifyExpected()

Project: pig
File: TestRank2.java
public void verifyExpected(List<Tuple> out, Multiset<Tuple> expected) {
    Multiset<Tuple> resultMultiset = TreeMultiset.create();
    for (Tuple tup : out) {
        resultMultiset.add(tup);
    }
    StringBuilder error = new StringBuilder("Result does not match.\nActual result:\n");
    for (Tuple tup : resultMultiset.elementSet()) {
        error.append(tup).append(" x ").append(resultMultiset.count(tup)).append("\n");
    }
    error.append("Expceted result:\n");
    for (Tuple tup : ImmutableSortedSet.copyOf(expected)) {
        error.append(tup).append(" x ").append(expected.count(tup)).append("\n");
    }
    //This one line test should be sufficient but adding the above
    //for-loop for better error messages
    assertTrue(error.toString(), resultMultiset.equals(expected));
}

87. TestRank1#verifyExpected()

Project: pig
File: TestRank1.java
public void verifyExpected(List<Tuple> out, Multiset<Tuple> expected) {
    Multiset<Tuple> resultMultiset = TreeMultiset.create();
    for (Tuple tup : out) {
        resultMultiset.add(tup);
    }
    StringBuilder error = new StringBuilder("Result does not match.\nActual result:\n");
    for (Tuple tup : resultMultiset.elementSet()) {
        error.append(tup).append(" x ").append(resultMultiset.count(tup)).append("\n");
    }
    error.append("Expceted result:\n");
    for (Tuple tup : ImmutableSortedSet.copyOf(expected)) {
        error.append(tup).append(" x ").append(expected.count(tup)).append("\n");
    }
    assertTrue(error.toString(), resultMultiset.equals(expected));
}

88. TestGFCross#testParallelSet()

Project: pig
File: TestGFCross.java
// Test GFCross handles a different parallel  case.
@Test
public void testParallelSet() throws Exception {
    Configuration cfg = new Configuration();
    cfg.set(PigImplConstants.PIG_CROSS_PARALLELISM + ".1", "10");
    UDFContext.getUDFContext().addJobConf(cfg);
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, 2);
    t.set(1, 0);
    GFCross cross = new GFCross("1");
    DataBag bag = cross.exec(t);
    assertEquals(4, bag.size());
}

89. TestGFCross#testSerial()

Project: pig
File: TestGFCross.java
// Test GFCross handles the parallel 1 case.
@Test
public void testSerial() throws Exception {
    Configuration cfg = new Configuration();
    cfg.set(PigImplConstants.PIG_CROSS_PARALLELISM + ".1", "1");
    UDFContext.getUDFContext().addJobConf(cfg);
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, 2);
    t.set(1, 0);
    GFCross cross = new GFCross("1");
    DataBag bag = cross.exec(t);
    assertEquals(1, bag.size());
}

90. TestGFCross#testDefault()

Project: pig
File: TestGFCross.java
// Test GFCross returns the correct number of default
// join groups
@Test
public void testDefault() throws Exception {
    UDFContext.getUDFContext().addJobConf(null);
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, 2);
    t.set(1, 0);
    GFCross cross = new GFCross("1");
    DataBag bag = cross.exec(t);
    assertEquals(10, bag.size());
}

91. TestForEachStar#testForeachStarSchemaUnkown()

Project: pig
File: TestForEachStar.java
@Test
public void testForeachStarSchemaUnkown() throws Exception {
    PigServer pig = new PigServer(Util.getLocalTestMode());
    String query = "  l1 = load '" + INPUT_FILE + "' ;" + "f1 = foreach l1 generate * ;";
    Util.registerMultiLineQuery(pig, query);
    pig.explain("f1", System.out);
    Iterator<Tuple> it = pig.openIterator("f1");
    Tuple expectedResCharArray = (Tuple) Util.getPigConstant("('one','two')");
    Tuple expectedRes = TupleFactory.getInstance().newTuple();
    for (Object field : expectedResCharArray.getAll()) {
        expectedRes.append(new DataByteArray(field.toString()));
    }
    assertTrue("has output", it.hasNext());
    assertEquals(expectedRes, it.next());
}

92. TestExtremalTupleByNthField#testMax()

Project: pig
File: TestExtremalTupleByNthField.java
@Test
public void testMax() throws Exception {
    ExtremalTupleByNthField o = new ExtremalTupleByNthField("4", "max");
    DataBag input = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < 100; i++) {
        Tuple t = TupleFactory.getInstance().newTuple();
        t.append(i);
        t.append(" " + i);
        t.append(i);
        t.append(i);
        input.add(t);
    }
    Tuple tupleInput = TupleFactory.getInstance().newTuple();
    tupleInput.append(input);
    Tuple out = o.exec(tupleInput);
    Assert.assertEquals(" 99", (String) out.get(1));
}

93. TestExtremalTupleByNthField#testMin()

Project: pig
File: TestExtremalTupleByNthField.java
@Test
public void testMin() throws Exception {
    ExtremalTupleByNthField o = new ExtremalTupleByNthField("3", "min");
    DataBag input = BagFactory.getInstance().newDefaultBag();
    for (int i = 100; i > 0; --i) {
        Tuple t = TupleFactory.getInstance().newTuple();
        t.append(i);
        t.append(" " + i);
        t.append(i);
        input.add(t);
    }
    Tuple tupleInput = TupleFactory.getInstance().newTuple();
    tupleInput.append(input);
    Tuple out = o.exec(tupleInput);
    Assert.assertEquals(" 1", (String) out.get(1));
}

94. TestDiffDateTime#testSecondsDiff()

Project: pig
File: TestDiffDateTime.java
@Test
public void testSecondsDiff() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(2);
    t1.set(0, "2009-01-07T00:00:00.000Z");
    t1.set(1, "2002-01-01T00:00:00.000Z");
    ISOSecondsBetween func = new ISOSecondsBetween();
    Long secs = func.exec(t1);
    System.out.println("Seconds: " + secs.toString());
    Assert.assertTrue(secs == 221443200L);
}

95. TestDiffDateTime#testMinuteDiff()

Project: pig
File: TestDiffDateTime.java
@Test
public void testMinuteDiff() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(2);
    t1.set(0, "2009-01-07T00:00:00.000Z");
    t1.set(1, "2002-01-01T00:00:00.000Z");
    ISOMinutesBetween func = new ISOMinutesBetween();
    Long mins = func.exec(t1);
    System.out.println("Minutes: " + mins.toString());
    Assert.assertTrue(mins == 3690720L);
}

96. TestDiffDateTime#testDayDiff()

Project: pig
File: TestDiffDateTime.java
@Test
public void testDayDiff() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(2);
    t1.set(0, "2009-01-07T00:00:00.000Z");
    t1.set(1, "2002-01-01T00:00:00.000Z");
    ISODaysBetween func = new ISODaysBetween();
    Long days = func.exec(t1);
    System.out.println("Days: " + days.toString());
    Assert.assertTrue(days == 2563L);
}

97. TestDiffDateTime#testMonthDiff()

Project: pig
File: TestDiffDateTime.java
@Test
public void testMonthDiff() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(2);
    t1.set(0, "2009-01-07T00:00:00.000Z");
    t1.set(1, "2002-01-01T00:00:00.000Z");
    ISOMonthsBetween func = new ISOMonthsBetween();
    Long months = func.exec(t1);
    System.out.println("Months: " + months.toString());
    Assert.assertTrue(months == 84L);
}

98. TestDiffDateTime#testYearDiff()

Project: pig
File: TestDiffDateTime.java
@Test
public void testYearDiff() throws Exception {
    Tuple t1 = TupleFactory.getInstance().newTuple(2);
    t1.set(0, "2009-01-07T01:07:01.000Z");
    t1.set(1, "2002-01-01T00:00:00.000Z");
    ISOYearsBetween func = new ISOYearsBetween();
    Long years = func.exec(t1);
    System.out.println("Years: " + years.toString());
    Assert.assertTrue(years == 7L);
}

99. TestConvertDateTime#testCustomFormatToISOWithTimezone()

Project: pig
File: TestConvertDateTime.java
@Test
public void testCustomFormatToISOWithTimezone() throws Exception {
    Tuple t = TupleFactory.getInstance().newTuple(2);
    t.set(0, "10/10/2010 Z");
    t.set(1, "dd/MM/yyyy Z");
    CustomFormatToISO func = new CustomFormatToISO();
    String iso = func.exec(t);
    assertEquals("2010-10-10T00:00:00.000Z", iso);
    assertEquals("Should not change the default timezone", defaultDTZ, DateTimeZone.getDefault());
}

100. TestStitch#testSingleInput()

Project: pig
File: TestStitch.java
@Test
public void testSingleInput() throws Exception {
    Stitch func = new Stitch();
    Tuple t = TupleFactory.getInstance().newTuple();
    t.append(new Integer(1));
    DataBag b = BagFactory.getInstance().newDefaultBag();
    b.add(t);
    t = TupleFactory.getInstance().newTuple();
    t.append(b);
    DataBag out = func.exec(t);
    assertEquals(1, out.size());
    assertEquals(new Integer(1), out.iterator().next().get(0));
}