You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ch...@apache.org on 2012/11/08 18:06:50 UTC
svn commit: r1407167 [1/10] - in /pig/trunk: ./ test/org/apache/pig/test/
test/org/apache/pig/test/pigunit/
Author: cheolsoo
Date: Thu Nov 8 17:06:46 2012
New Revision: 1407167
URL: http://svn.apache.org/viewvc?rev=1407167&view=rev
Log:
PIG-3016: Modernize more tests (jcoveney via cheolsoo)
Modified:
pig/trunk/CHANGES.txt
pig/trunk/test/org/apache/pig/test/TestAccumulator.java
pig/trunk/test/org/apache/pig/test/TestAdd.java
pig/trunk/test/org/apache/pig/test/TestBestFitCast.java
pig/trunk/test/org/apache/pig/test/TestBloom.java
pig/trunk/test/org/apache/pig/test/TestBoolean.java
pig/trunk/test/org/apache/pig/test/TestCharArrayToNumeric.java
pig/trunk/test/org/apache/pig/test/TestCmdLineParser.java
pig/trunk/test/org/apache/pig/test/TestCombiner.java
pig/trunk/test/org/apache/pig/test/TestConstExpr.java
pig/trunk/test/org/apache/pig/test/TestDataModel.java
pig/trunk/test/org/apache/pig/test/TestDivide.java
pig/trunk/test/org/apache/pig/test/TestEqualTo.java
pig/trunk/test/org/apache/pig/test/TestFRJoin.java
pig/trunk/test/org/apache/pig/test/TestFilter.java
pig/trunk/test/org/apache/pig/test/TestFilterUDF.java
pig/trunk/test/org/apache/pig/test/TestFinish.java
pig/trunk/test/org/apache/pig/test/TestForEach.java
pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java
pig/trunk/test/org/apache/pig/test/TestGreaterThan.java
pig/trunk/test/org/apache/pig/test/TestJoin.java
pig/trunk/test/org/apache/pig/test/TestJoinSmoke.java
pig/trunk/test/org/apache/pig/test/TestLOLoadDeterminedSchema.java
pig/trunk/test/org/apache/pig/test/TestLTOrEqual.java
pig/trunk/test/org/apache/pig/test/TestLessThan.java
pig/trunk/test/org/apache/pig/test/TestMod.java
pig/trunk/test/org/apache/pig/test/TestMultiply.java
pig/trunk/test/org/apache/pig/test/TestNewPlanColumnPrune.java
pig/trunk/test/org/apache/pig/test/TestNewPlanLogicalOptimizer.java
pig/trunk/test/org/apache/pig/test/TestNotEqualTo.java
pig/trunk/test/org/apache/pig/test/TestNull.java
pig/trunk/test/org/apache/pig/test/TestPOBinCond.java
pig/trunk/test/org/apache/pig/test/TestPackage.java
pig/trunk/test/org/apache/pig/test/TestParser.java
pig/trunk/test/org/apache/pig/test/TestPhyOp.java
pig/trunk/test/org/apache/pig/test/TestPigContext.java
pig/trunk/test/org/apache/pig/test/TestPigScriptParser.java
pig/trunk/test/org/apache/pig/test/TestPlanGeneration.java
pig/trunk/test/org/apache/pig/test/TestPoissonSampleLoader.java
pig/trunk/test/org/apache/pig/test/TestProject.java
pig/trunk/test/org/apache/pig/test/TestRegexp.java
pig/trunk/test/org/apache/pig/test/TestSecondarySort.java
pig/trunk/test/org/apache/pig/test/TestSkewedJoin.java
pig/trunk/test/org/apache/pig/test/TestSplitStore.java
pig/trunk/test/org/apache/pig/test/TestSubtract.java
pig/trunk/test/org/apache/pig/test/TestTextDataParser.java
pig/trunk/test/org/apache/pig/test/TestTypeCheckingValidatorNewLP.java
pig/trunk/test/org/apache/pig/test/TestUnion.java
pig/trunk/test/org/apache/pig/test/pigunit/TestPigTest.java
Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Thu Nov 8 17:06:46 2012
@@ -24,6 +24,8 @@ INCOMPATIBLE CHANGES
IMPROVEMENTS
+PIG-3016: Modernize more tests (jcoveney via cheolsoo)
+
PIG-2582: Store size in bytes (not mbytes) in ResourceStatistics (prkommireddi via billgraham)
PIG-3006: Modernize a chunk of the tests (jcoveney via cheolsoo)
Modified: pig/trunk/test/org/apache/pig/test/TestAccumulator.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestAccumulator.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestAccumulator.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestAccumulator.java Thu Nov 8 17:06:46 2012
@@ -17,13 +17,18 @@
*/
package org.apache.pig.test;
-import java.io.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
@@ -33,36 +38,33 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-@RunWith(JUnit4.class)
-public class TestAccumulator extends TestCase{
+public class TestAccumulator {
private static final String INPUT_FILE = "AccumulatorInput.txt";
private static final String INPUT_FILE2 = "AccumulatorInput2.txt";
private static final String INPUT_FILE3 = "AccumulatorInput3.txt";
private static final String INPUT_FILE4 = "AccumulatorInput4.txt";
-
+
private PigServer pigServer;
private static MiniCluster cluster = MiniCluster.buildCluster();
public TestAccumulator() throws ExecException, IOException{
pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
// pigServer = new PigServer(ExecType.LOCAL);
- pigServer.getPigContext().getProperties().setProperty("pig.accumulative.batchsize", "2");
+ pigServer.getPigContext().getProperties().setProperty("pig.accumulative.batchsize", "2");
pigServer.getPigContext().getProperties().setProperty("pig.exec.batchsize", "2");
pigServer.getPigContext().getProperties().setProperty("pig.exec.nocombiner", "true");
// reducing the number of retry attempts to speed up test completion
pigServer.getPigContext().getProperties().setProperty("mapred.map.max.attempts","1");
pigServer.getPigContext().getProperties().setProperty("mapred.reduce.max.attempts","1");
}
-
+
@Before
public void setUp() throws Exception {
pigServer.getPigContext().getProperties().remove("opt.accumulator");
createFiles();
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
@@ -70,57 +72,57 @@ public class TestAccumulator extends Tes
private void createFiles() throws IOException {
PrintWriter w = new PrintWriter(new FileWriter(INPUT_FILE));
-
- w.println("100\tapple");
- w.println("200\torange");
- w.println("300\tstrawberry");
+
+ w.println("100\tapple");
+ w.println("200\torange");
+ w.println("300\tstrawberry");
w.println("300\tpear");
w.println("100\tapple");
w.println("300\tpear");
- w.println("400\tapple");
- w.close();
-
+ w.println("400\tapple");
+ w.close();
+
Util.copyFromLocalToCluster(cluster, INPUT_FILE, INPUT_FILE);
-
+
w = new PrintWriter(new FileWriter(INPUT_FILE2));
-
- w.println("100\t");
+
w.println("100\t");
- w.println("200\t");
- w.println("200\t");
+ w.println("100\t");
+ w.println("200\t");
+ w.println("200\t");
w.println("300\tstrawberry");
- w.close();
-
+ w.close();
+
Util.copyFromLocalToCluster(cluster, INPUT_FILE2, INPUT_FILE2);
-
+
w = new PrintWriter(new FileWriter(INPUT_FILE3));
-
- w.println("100\t1.0");
+
+ w.println("100\t1.0");
w.println("100\t2.0");
- w.println("200\t1.1");
+ w.println("200\t1.1");
w.println("200\t2.1");
- w.println("100\t3.0");
+ w.println("100\t3.0");
w.println("100\t4.0");
w.println("200\t3.1");
w.println("100\t5.0");
w.println("300\t3.3");
w.println("400\t");
w.println("400\t");
- w.close();
-
+ w.close();
+
Util.copyFromLocalToCluster(cluster, INPUT_FILE3, INPUT_FILE3);
-
+
w = new PrintWriter(new FileWriter(INPUT_FILE4));
-
- w.println("100\thttp://ibm.com,ibm");
+
w.println("100\thttp://ibm.com,ibm");
- w.println("200\thttp://yahoo.com,yahoo");
+ w.println("100\thttp://ibm.com,ibm");
+ w.println("200\thttp://yahoo.com,yahoo");
w.println("300\thttp://sun.com,sun");
- w.close();
-
+ w.close();
+
Util.copyFromLocalToCluster(cluster, INPUT_FILE4, INPUT_FILE4);
}
-
+
@After
public void tearDown() throws Exception {
new File(INPUT_FILE).delete();
@@ -128,328 +130,328 @@ public class TestAccumulator extends Tes
new File(INPUT_FILE2).delete();
Util.deleteFile(cluster, INPUT_FILE2);
new File(INPUT_FILE3).delete();
- Util.deleteFile(cluster, INPUT_FILE3);
+ Util.deleteFile(cluster, INPUT_FILE3);
new File(INPUT_FILE4).delete();
Util.deleteFile(cluster, INPUT_FILE4);
}
-
+
@Test
public void testAccumBasic() throws IOException{
// test group by
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
- pigServer.registerQuery("C = foreach B generate group, org.apache.pig.test.utils.AccumulatorBagCount(A);");
+ pigServer.registerQuery("C = foreach B generate group, org.apache.pig.test.utils.AccumulatorBagCount(A);");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 2);
expected.put(200, 1);
expected.put(300, 3);
expected.put(400, 1);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
- "org.apache.pig.test.utils.AccumulatorBagCount(A), org.apache.pig.test.utils.BagCount(A);");
-
+ "org.apache.pig.test.utils.AccumulatorBagCount(A), org.apache.pig.test.utils.BagCount(A);");
+
try{
iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
fail("accumulator should not be called.");
}catch(IOException e) {
// should throw exception from AccumulatorBagCount.
}
-
+
// test cogroup
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("C = cogroup A by id, B by id;");
pigServer.registerQuery("D = foreach C generate group, " +
- "org.apache.pig.test.utils.AccumulatorBagCount(A), org.apache.pig.test.utils.AccumulatorBagCount(B);");
+ "org.apache.pig.test.utils.AccumulatorBagCount(A), org.apache.pig.test.utils.AccumulatorBagCount(B);");
HashMap<Integer, String> expected2 = new HashMap<Integer, String>();
expected2.put(100, "2,2");
expected2.put(200, "1,1");
expected2.put(300, "3,3");
expected2.put(400, "1,1");
-
-
+
+
iter = pigServer.openIterator("D");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected2.get((Integer)t.get(0)), t.get(1).toString()+","+t.get(2).toString());
- }
- }
-
+ assertEquals(expected2.get((Integer)t.get(0)), t.get(1).toString()+","+t.get(2).toString());
+ }
+ }
+
@Test
public void testAccumWithNegative() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
- pigServer.registerQuery("C = foreach B generate group, -org.apache.pig.test.utils.AccumulatorBagCount(A);");
+ pigServer.registerQuery("C = foreach B generate group, -org.apache.pig.test.utils.AccumulatorBagCount(A);");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, -2);
expected.put(200, -1);
expected.put(300, -3);
expected.put(400, -1);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
}
-
+
@Test
public void testAccumWithAdd() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
- pigServer.registerQuery("C = foreach B generate group, org.apache.pig.test.utils.AccumulatorBagCount(A)+1.0;");
-
+ pigServer.registerQuery("C = foreach B generate group, org.apache.pig.test.utils.AccumulatorBagCount(A)+1.0;");
+
{
HashMap<Integer, Double> expected = new HashMap<Integer, Double>();
expected.put(100, 3.0);
expected.put(200, 2.0);
expected.put(300, 4.0);
expected.put(400, 2.0);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Double)t.get(1));
- }
+ assertEquals(expected.get((Integer)t.get(0)), (Double)t.get(1));
+ }
}
-
+
{
pigServer.registerQuery("C = foreach B generate group, " +
- "org.apache.pig.test.utils.AccumulatorBagCount(A)+org.apache.pig.test.utils.AccumulatorBagCount(A);");
+ "org.apache.pig.test.utils.AccumulatorBagCount(A)+org.apache.pig.test.utils.AccumulatorBagCount(A);");
HashMap<Integer, Integer>expected = new HashMap<Integer, Integer>();
expected.put(100, 4);
expected.put(200, 2);
expected.put(300, 6);
expected.put(400, 2);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
}
}
- }
-
+ }
+
@Test
public void testAccumWithMinus() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
- " org.apache.pig.test.utils.AccumulatorBagCount(A)*3.0-org.apache.pig.test.utils.AccumulatorBagCount(A);");
+ " org.apache.pig.test.utils.AccumulatorBagCount(A)*3.0-org.apache.pig.test.utils.AccumulatorBagCount(A);");
HashMap<Integer, Double> expected = new HashMap<Integer, Double>();
expected.put(100, 4.0);
expected.put(200, 2.0);
expected.put(300, 6.0);
expected.put(400, 2.0);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Double)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Double)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithMod() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
- "org.apache.pig.test.utils.AccumulatorBagCount(A) % 2;");
+ "org.apache.pig.test.utils.AccumulatorBagCount(A) % 2;");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 0);
expected.put(200, 1);
expected.put(300, 1);
expected.put(400, 1);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithDivide() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
- "org.apache.pig.test.utils.AccumulatorBagCount(A)/2;");
+ "org.apache.pig.test.utils.AccumulatorBagCount(A)/2;");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 1);
expected.put(200, 0);
expected.put(300, 1);
expected.put(400, 0);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithAnd() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
"((org.apache.pig.test.utils.AccumulatorBagCount(A)>1 and " +
- "org.apache.pig.test.utils.AccumulatorBagCount(A)<3)?0:1);");
+ "org.apache.pig.test.utils.AccumulatorBagCount(A)<3)?0:1);");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 0);
expected.put(200, 1);
expected.put(300, 1);
expected.put(400, 1);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithOr() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
"((org.apache.pig.test.utils.AccumulatorBagCount(A)>3 or " +
- "org.apache.pig.test.utils.AccumulatorBagCount(A)<2)?0:1);");
+ "org.apache.pig.test.utils.AccumulatorBagCount(A)<2)?0:1);");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 1);
expected.put(200, 0);
expected.put(300, 1);
expected.put(400, 0);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithRegexp() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
- "(((chararray)org.apache.pig.test.utils.AccumulatorBagCount(A)) matches '1*' ?0:1);");
+ "(((chararray)org.apache.pig.test.utils.AccumulatorBagCount(A)) matches '1*' ?0:1);");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 1);
expected.put(200, 0);
expected.put(300, 1);
expected.put(400, 0);
-
-
+
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithIsNull() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE2 + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, " +
- "((chararray)org.apache.pig.test.utils.AccumulativeSumBag(A) is null?0:1);");
+ "((chararray)org.apache.pig.test.utils.AccumulativeSumBag(A) is null?0:1);");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 0);
expected.put(200, 0);
- expected.put(300, 1);
-
+ expected.put(300, 1);
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithDistinct() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, f);");
pigServer.registerQuery("B = group A by id;");
- pigServer.registerQuery("C = foreach B { D = distinct A; generate group, org.apache.pig.test.utils.AccumulatorBagCount(D)+1;};");
+ pigServer.registerQuery("C = foreach B { D = distinct A; generate group, org.apache.pig.test.utils.AccumulatorBagCount(D)+1;};");
HashMap<Integer, Integer> expected = new HashMap<Integer, Integer>();
expected.put(100, 2);
expected.put(200, 2);
expected.put(300, 3);
expected.put(400, 2);
-
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Integer)t.get(0)), (Integer)t.get(1));
+ }
+ }
+
@Test
public void testAccumWithSort() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, f);");
pigServer.registerQuery("B = foreach A generate id, f, id as t;");
pigServer.registerQuery("C = group B by id;");
- pigServer.registerQuery("D = foreach C { E = order B by f; F = E.f; generate group, org.apache.pig.test.utils.AccumulativeSumBag(F);};");
+ pigServer.registerQuery("D = foreach C { E = order B by f; F = E.f; generate group, org.apache.pig.test.utils.AccumulativeSumBag(F);};");
HashMap<Integer, String> expected = new HashMap<Integer, String>();
expected.put(100, "(apple)(apple)");
expected.put(200, "(orange)");
expected.put(300, "(pear)(pear)(strawberry)");
expected.put(400, "(apple)");
-
+
Iterator<Tuple> iter = pigServer.openIterator("D");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (String)t.get(1));
- }
+ assertEquals(expected.get((Integer)t.get(0)), (String)t.get(1));
+ }
}
-
+
public void testAccumWithBuildinAvg() throws IOException {
HashMap<Integer, Double> expected = new HashMap<Integer, Double>();
expected.put(100, 3.0);
@@ -476,27 +478,27 @@ public class TestAccumulator extends Tes
assertEquals(v.doubleValue(), ((Number) t.get(1)).doubleValue(),
0.0001);
} else {
- assertEquals(null, t.get(1));
+ assertNull(t.get(1));
}
}
}
}
-
+
@Test
public void testAccumWithBuildin() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE3 + "' as (id:int, v:double);");
pigServer.registerQuery("C = group A by id;");
// moving AVG accumulator test to separate test case
- pigServer.registerQuery("D = foreach C generate group, SUM(A.v), COUNT(A.v), MIN(A.v), MAX(A.v);");
+ pigServer.registerQuery("D = foreach C generate group, SUM(A.v), COUNT(A.v), MIN(A.v), MAX(A.v);");
HashMap<Integer, Double[]> expected = new HashMap<Integer, Double[]>();
expected.put(100, new Double[]{15.0, 5.0, 1.0, 5.0});
expected.put(200, new Double[]{6.3, 3.0, 1.1, 3.1});
expected.put(300, new Double[]{3.3, 1.0, 3.3, 3.3});
expected.put(400, new Double[] { null, 0.0, null, null });
-
+
Iterator<Tuple> iter = pigServer.openIterator("D");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
Double[] v = expected.get((Integer)t.get(0));
@@ -505,25 +507,25 @@ public class TestAccumulator extends Tes
assertEquals(v[i].doubleValue(), ((Number) t.get(i + 1))
.doubleValue(), 0.0001);
} else {
- assertEquals(null, t.get(i + 1));
+ assertNull(t.get(i + 1));
}
- }
- }
+ }
+ }
}
-
+
@Test
public void testAccumWithMultiBuildin() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE + "' as (id:int, c:chararray);");
pigServer.registerQuery("C = group A by 1;");
- pigServer.registerQuery("D = foreach C generate SUM(A.id), 1+SUM(A.id)+SUM(A.id);");
+ pigServer.registerQuery("D = foreach C generate SUM(A.id), 1+SUM(A.id)+SUM(A.id);");
Iterator<Tuple> iter = pigServer.openIterator("D");
-
+
while(iter.hasNext()) {
- Tuple t = iter.next();
+ Tuple t = iter.next();
t.get(0).toString().equals("1700");
- t.get(1).toString().equals("3401");
- }
+ t.get(1).toString().equals("3401");
+ }
}
// Pig 1105
@@ -533,19 +535,15 @@ public class TestAccumulator extends Tes
pigServer.registerQuery("C = group A by id;");
pigServer.registerQuery("D = foreach C generate group, COUNT_STAR(A.id);");
- try {
- Iterator<Tuple> iter = pigServer.openIterator("D");
- } catch (Exception e) {
- fail("COUNT_STAR should be supported by accumulator interface");
- }
+ Iterator<Tuple> iter = pigServer.openIterator("D");
}
-
+
/**
* see PIG-1963.
- * If there is a POSort or PODistinct still remaining in the plan
- * (after secondary sort optimization), accumulative mode can't
+ * If there is a POSort or PODistinct still remaining in the plan
+ * (after secondary sort optimization), accumulative mode can't
* be used as they are blocking operators
- * @throws IOException
+ * @throws IOException
*/
@Test
public void testAccumulatorOffOnSort() throws IOException{
@@ -559,16 +557,16 @@ public class TestAccumulator extends Tes
" generate org.apache.pig.test.utils.AccumulativeSumBag(o1.fruit), " +
" org.apache.pig.test.utils.AccumulativeSumBag(o2.fruit); " +
"};");
-
- checkAccumulatorOff("C");
+
+ checkAccumulatorOff("C");
}
-
+
/**
* see PIG-1963.
- * If there is a POSort or PODistinct still remaining in the plan
- * (after secondary sort optimization), accumulative mode can't
+ * If there is a POSort or PODistinct still remaining in the plan
+ * (after secondary sort optimization), accumulative mode can't
* be used as they are blocking operators
- * @throws IOException
+ * @throws IOException
*/
@Test
public void testAccumulatorOffOnDistinct() throws IOException{
@@ -582,23 +580,22 @@ public class TestAccumulator extends Tes
" generate org.apache.pig.test.utils.AccumulativeSumBag(o1.fruit), " +
" org.apache.pig.test.utils.AccumulativeSumBag(d2); " +
"};");
-
- checkAccumulatorOff("C");
+
+ checkAccumulatorOff("C");
}
-
- @Test
+
+ @Test
public void testAccumulatorOff() throws IOException{
pigServer.getPigContext().getProperties().setProperty("opt.accumulator", "false");
-
+
pigServer.registerQuery("A = load '" + INPUT_FILE2 + "' as (id:int, fruit);");
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B generate group, org.apache.pig.test.utils.AccumulativeSumBag(A);");
-
+
checkAccumulatorOff("C");
pigServer.getPigContext().getProperties().setProperty("opt.accumulator", "true");
-
- }
-
+ }
+
private void checkAccumulatorOff(String alias) {
try {
Iterator<Tuple> iter = pigServer.openIterator(alias);
@@ -612,43 +609,43 @@ public class TestAccumulator extends Tes
// we should get exception
}
}
-
- @Test
+
+ @Test
public void testAccumWithMap() throws IOException{
pigServer.registerQuery("A = load '" + INPUT_FILE4 + "' as (id, url);");
pigServer.registerQuery("B = group A by (id, url);");
- pigServer.registerQuery("C = foreach B generate COUNT(A), org.apache.pig.test.utils.URLPARSE(group.url)#'url';");
+ pigServer.registerQuery("C = foreach B generate COUNT(A), org.apache.pig.test.utils.URLPARSE(group.url)#'url';");
HashMap<Integer, String> expected = new HashMap<Integer, String>();
expected.put(2, "http://ibm.com");
expected.put(1, "http://yahoo.com");
- expected.put(1, "http://sun.com");
-
+ expected.put(1, "http://sun.com");
+
Iterator<Tuple> iter = pigServer.openIterator("C");
-
+
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Long)t.get(0)), (String)t.get(1));
- }
- }
-
+ assertEquals(expected.get((Long)t.get(0)), (String)t.get(1));
+ }
+ }
+
@Test // PIG-1837
public void testBinCondCheck() throws Exception {
PrintWriter w = new PrintWriter(new FileWriter("data1"));
- w.println("1\t11");
- w.println("2\t15");
- w.close();
-
+ w.println("1\t11");
+ w.println("2\t15");
+ w.close();
+
Util.copyFromLocalToCluster(cluster, "data1", "data1");
-
+
w = new PrintWriter(new FileWriter("data2"));
- w.println("1\t10");
+ w.println("1\t10");
w.println("4\t11");
- w.println("5\t10");
- w.close();
-
+ w.println("5\t10");
+ w.close();
+
Util.copyFromLocalToCluster(cluster, "data2", "data2");
-
+
pigServer.registerQuery("A = load 'data1' as (x:int, y:int);");
pigServer.registerQuery("B = load 'data2' as (x:int, z:int);");
pigServer.registerQuery("C = cogroup A by x, B by x;");
@@ -657,18 +654,18 @@ public class TestAccumulator extends Tes
HashMap<Integer, Long> expected = new HashMap<Integer, Long>();
expected.put(1, 21l);
expected.put(2, 15l);
- expected.put(4, 11l);
- expected.put(5, 10l);
-
+ expected.put(4, 11l);
+ expected.put(5, 10l);
+
Iterator<Tuple> iter = pigServer.openIterator("D");
while(iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(expected.get((Integer)t.get(0)), (Long)t.get(1));
- }
+ assertEquals(expected.get((Integer)t.get(0)), (Long)t.get(1));
+ }
}
-
+
/**
- * see PIG-1911 .
+ * see PIG-1911 .
* accumulator udf reading from a nested relational op. generate projects
* only the accumulator udf.
* @throws IOException
@@ -681,10 +678,10 @@ public class TestAccumulator extends Tes
pigServer.registerQuery("B = group A by id;");
pigServer.registerQuery("C = foreach B " +
"{ o = order A by id; " +
- " generate org.apache.pig.test.utils.AccumulatorBagCount(o);}; ");
-
+ " generate org.apache.pig.test.utils.AccumulatorBagCount(o);}; ");
+
Iterator<Tuple> iter = pigServer.openIterator("C");
- List<Tuple> expectedRes =
+ List<Tuple> expectedRes =
Util.getTuplesFromConstantTupleStrings(
new String[] {
"(2)",
@@ -693,7 +690,5 @@ public class TestAccumulator extends Tes
"(1)"
});
Util.checkQueryOutputsAfterSort(iter, expectedRes);
- }
-
-
-}
+ }
+}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestAdd.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestAdd.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestAdd.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestAdd.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,73 +15,71 @@
*/
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.util.Map;
import java.util.Random;
-import junit.framework.TestCase;
-
-import org.joda.time.DateTime;
-
import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Add;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ConstantExpression;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.DataByteArray;
import org.apache.pig.data.DataType;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.plan.OperatorKey;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ConstantExpression;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Add;
import org.apache.pig.test.utils.GenRandomData;
+import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
-
-public class TestAdd extends TestCase{
-
- Random r = new Random();
+public class TestAdd {
+ Random r = new Random(42L);
ConstantExpression lt, rt;
Add op = new Add(new OperatorKey("", r.nextLong()));
@Before
public void setUp() throws Exception {
- lt = new ConstantExpression(new OperatorKey("",r.nextLong()));
- rt = new ConstantExpression(new OperatorKey("",r.nextLong()));
+ lt = new ConstantExpression(new OperatorKey("", r.nextLong()));
+ rt = new ConstantExpression(new OperatorKey("", r.nextLong()));
}
@Test
- public void testOperator() throws ExecException{
- //int TRIALS = 10;
- byte[] types = { DataType.BAG, DataType.BOOLEAN, DataType.BYTEARRAY, DataType.CHARARRAY,
- DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG, DataType.DATETIME, DataType.MAP, DataType.TUPLE};
- //Map<Byte,String> map = GenRandomData.genTypeToNameMap();
+ public void testOperator() throws ExecException {
+ // int TRIALS = 10;
+ byte[] types = { DataType.BAG, DataType.BOOLEAN, DataType.BYTEARRAY, DataType.CHARARRAY,
+ DataType.DOUBLE, DataType.FLOAT, DataType.INTEGER, DataType.LONG,
+ DataType.DATETIME, DataType.MAP, DataType.TUPLE };
+ // Map<Byte,String> map = GenRandomData.genTypeToNameMap();
System.out.println("Testing Add operator");
- for(byte type : types) {
+ for (byte type : types) {
lt.setResultType(type);
rt.setResultType(type);
op.setLhs(lt);
op.setRhs(rt);
- switch(type){
+ switch (type) {
case DataType.BAG:
DataBag inpdb1 = GenRandomData.genRandSmallTupDataBag(r, 10, 100);
DataBag inpdb2 = GenRandomData.genRandSmallTupDataBag(r, 10, 100);
lt.setValue(inpdb1);
rt.setValue(inpdb2);
Result resdb = op.getNext(inpdb1);
- assertEquals(resdb.returnStatus, POStatus.STATUS_ERR);
-
+ assertEquals(POStatus.STATUS_ERR, resdb.returnStatus);
+
// test with null in lhs
lt.setValue(null);
rt.setValue(inpdb2);
resdb = op.getNext(inpdb1);
- assertEquals(resdb.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resdb.returnStatus);
// test with null in rhs
lt.setValue(inpdb1);
rt.setValue(null);
resdb = op.getNext(inpdb1);
- assertEquals(resdb.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resdb.returnStatus);
break;
case DataType.BOOLEAN:
Boolean inpb1 = r.nextBoolean();
@@ -91,18 +87,18 @@ public class TestAdd extends TestCase{
lt.setValue(inpb1);
rt.setValue(inpb2);
Result resb = op.getNext(inpb1);
- assertEquals(resb.returnStatus, POStatus.STATUS_ERR);
-
+ assertEquals(POStatus.STATUS_ERR, resb.returnStatus);
+
// test with null in lhs
lt.setValue(null);
rt.setValue(inpb2);
resb = op.getNext(inpb1);
- assertEquals(resb.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resb.returnStatus);
// test with null in rhs
lt.setValue(inpb1);
rt.setValue(null);
resb = op.getNext(inpb1);
- assertEquals(resb.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resb.returnStatus);
break;
case DataType.BYTEARRAY: {
DataByteArray inpba1 = GenRandomData.genRandDBA(r);
@@ -110,20 +106,21 @@ public class TestAdd extends TestCase{
lt.setValue(inpba1);
rt.setValue(inpba2);
Result resba = op.getNext(inpba1);
- //DataByteArray expected = new DataByteArray(inpba1.toString() + inpba2.toString());
- //assertEquals(expected, (DataByteArray)resba.result);
+ // DataByteArray expected = new DataByteArray(inpba1.toString() +
+ // inpba2.toString());
+ // assertEquals(expected, (DataByteArray)resba.result);
assertEquals(POStatus.STATUS_ERR, resba.returnStatus);
-
+
// test with null in lhs
lt.setValue(null);
rt.setValue(inpba2);
resba = op.getNext(inpba1);
- assertEquals(resba.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resba.returnStatus);
// test with null in rhs
lt.setValue(inpba1);
rt.setValue(null);
resba = op.getNext(inpba1);
- assertEquals(resba.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resba.returnStatus);
break;
}
case DataType.CHARARRAY: {
@@ -132,20 +129,22 @@ public class TestAdd extends TestCase{
lt.setValue(inps1);
rt.setValue(inps2);
Result ress = op.getNext(inps1);
- /*String expected = new String(inps1 + inps2);
- assertEquals(expected, (String)ress.result);*/
+ /*
+ * String expected = new String(inps1 + inps2);
+ * assertEquals(expected, (String)ress.result);
+ */
assertEquals(POStatus.STATUS_ERR, ress.returnStatus);
-
+
// test with null in lhs
lt.setValue(null);
rt.setValue(inps2);
ress = op.getNext(inps1);
- assertEquals(ress.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, ress.returnStatus);
// test with null in rhs
lt.setValue(inps1);
rt.setValue(null);
ress = op.getNext(inps1);
- assertEquals(ress.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, ress.returnStatus);
break;
}
case DataType.DOUBLE: {
@@ -155,18 +154,18 @@ public class TestAdd extends TestCase{
rt.setValue(inpd2);
Result resd = op.getNext(inpd1);
Double expected = new Double(inpd1 + inpd2);
- assertEquals(expected, (Double)resd.result);
-
+ assertEquals(expected, (Double) resd.result);
+
// test with null in lhs
lt.setValue(null);
rt.setValue(inpd2);
resd = op.getNext(inpd1);
- assertEquals(null, (Double)resd.result);
+ assertNull(resd.result);
// test with null in rhs
lt.setValue(inpd1);
rt.setValue(null);
resd = op.getNext(inpd1);
- assertEquals(null, (Double)resd.result);
+ assertNull(resd.result);
break;
}
case DataType.FLOAT: {
@@ -176,18 +175,18 @@ public class TestAdd extends TestCase{
rt.setValue(inpf2);
Result resf = op.getNext(inpf1);
Float expected = new Float(inpf1 + inpf2);
- assertEquals(expected, (Float)resf.result);
+ assertEquals(expected, (Float) resf.result);
// test with null in lhs
lt.setValue(null);
rt.setValue(inpf2);
resf = op.getNext(inpf1);
- assertEquals(null, (Float)resf.result);
+ assertNull(resf.result);
// test with null in rhs
lt.setValue(inpf1);
rt.setValue(null);
resf = op.getNext(inpf1);
- assertEquals(null, (Float)resf.result);
+ assertNull(resf.result);
break;
}
case DataType.INTEGER: {
@@ -203,12 +202,12 @@ public class TestAdd extends TestCase{
lt.setValue(null);
rt.setValue(inpi2);
resi = op.getNext(inpi1);
- assertEquals(null, (Integer)resi.result);
+ assertNull(resi.result);
// test with null in rhs
lt.setValue(inpi1);
rt.setValue(null);
resi = op.getNext(inpi1);
- assertEquals(null, (Integer)resi.result);
+ assertNull(resi.result);
break;
}
case DataType.LONG: {
@@ -218,18 +217,18 @@ public class TestAdd extends TestCase{
rt.setValue(inpl2);
Result resl = op.getNext(inpl1);
Long expected = new Long(inpl1 + inpl2);
- assertEquals(expected, (Long)resl.result);
+ assertEquals(expected, (Long) resl.result);
// test with null in lhs
lt.setValue(null);
rt.setValue(inpl2);
resl = op.getNext(inpl1);
- assertEquals(null, (Long)resl.result);
+ assertNull(resl.result);
// test with null in rhs
lt.setValue(inpl1);
rt.setValue(null);
resl = op.getNext(inpl1);
- assertEquals(null, (Long)resl.result);
+ assertNull(resl.result);
break;
}
case DataType.DATETIME:
@@ -238,22 +237,22 @@ public class TestAdd extends TestCase{
lt.setValue(inpdt1);
rt.setValue(inpdt2);
Result resdt = op.getNext(inpdt1);
- assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
-
+ assertEquals(POStatus.STATUS_ERR, resdt.returnStatus);
+
// test with null in lhs
lt.setValue(null);
rt.setValue(inpdt2);
resdt = op.getNext(inpdt1);
- assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resdt.returnStatus);
// test with null in rhs
lt.setValue(inpdt1);
rt.setValue(null);
resdt = op.getNext(inpdt1);
- assertEquals(resdt.returnStatus, POStatus.STATUS_ERR);
+ assertEquals(POStatus.STATUS_ERR, resdt.returnStatus);
break;
case DataType.MAP: {
- Map<String,Object> inpm1 = GenRandomData.genRandMap(r, 10);
- Map<String,Object> inpm2 = GenRandomData.genRandMap(r, 10);
+ Map<String, Object> inpm1 = GenRandomData.genRandMap(r, 10);
+ Map<String, Object> inpm2 = GenRandomData.genRandMap(r, 10);
lt.setValue(inpm1);
rt.setValue(inpm2);
Result resm = op.getNext(inpm1);
@@ -294,5 +293,4 @@ public class TestAdd extends TestCase{
}
}
}
-}
-
+}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestBestFitCast.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestBestFitCast.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestBestFitCast.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestBestFitCast.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +15,9 @@
*/
package org.apache.pig.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -25,8 +25,6 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.pig.EvalFunc;
import org.apache.pig.ExecType;
import org.apache.pig.FuncSpec;
@@ -49,28 +47,24 @@ public class TestBestFitCast {
private static MiniCluster cluster = MiniCluster.buildCluster();
String inputFile, inputFile2;
int LOOP_SIZE = 20;
-
- public TestBestFitCast() throws ExecException, IOException{
- }
-
@Before
public void setUp() throws Exception {
pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
inputFile = "TestBestFitCast-input.txt";
String[] input = new String[LOOP_SIZE];
long l = 0;
- for(int i = 1; i <= LOOP_SIZE; i++) {
- input[i-1] = (l + "\t" + i);
+ for (int i = 1; i <= LOOP_SIZE; i++) {
+ input[i - 1] = (l + "\t" + i);
}
- Util.createInputFile(cluster, inputFile, input);
-
+ Util.createInputFile(cluster, inputFile, input);
+
inputFile2 = "TestBestFitCast-input2.txt";
l = 0;
- for(int i = 1; i <= LOOP_SIZE; i++) {
- input[i-1] = (l + "\t" + i + "\t" + i);
+ for (int i = 1; i <= LOOP_SIZE; i++) {
+ input[i - 1] = (l + "\t" + i + "\t" + i);
}
- Util.createInputFile(cluster, inputFile2, input);
+ Util.createInputFile(cluster, inputFile2, input);
}
@After
@@ -78,15 +72,16 @@ public class TestBestFitCast {
Util.deleteFile(cluster, inputFile);
Util.deleteFile(cluster, inputFile2);
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
- public static class UDF1 extends EvalFunc<Tuple>{
+
+ public static class UDF1 extends EvalFunc<Tuple> {
/**
* java level API
+ *
* @param input expects a single numeric DataAtom value
* @param output returns a single numeric DataAtom value, cosine value of the argument
*/
@@ -95,60 +90,78 @@ public class TestBestFitCast {
return input;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.apache.pig.EvalFunc#getArgToFuncMapping()
*/
@Override
public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
List<FuncSpec> funcList = new ArrayList<FuncSpec>();
- funcList.add(new FuncSpec(this.getClass().getName(), new Schema(Arrays.asList(new Schema.FieldSchema(null, DataType.FLOAT),new Schema.FieldSchema(null, DataType.FLOAT)))));
- funcList.add(new FuncSpec(this.getClass().getName(), new Schema(Arrays.asList(new Schema.FieldSchema(null, DataType.LONG),new Schema.FieldSchema(null, DataType.DOUBLE)))));
- funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.FLOAT))));
- funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.INTEGER))));
- funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.DOUBLE))));
- /*funcList.add(new FuncSpec(DoubleMax.class.getName(), Schema.generateNestedSchema(DataType.BAG, DataType.DOUBLE)));
- funcList.add(new FuncSpec(FloatMax.class.getName(), Schema.generateNestedSchema(DataType.BAG, DataType.FLOAT)));
- funcList.add(new FuncSpec(IntMax.class.getName(), Schema.generateNestedSchema(DataType.BAG, DataType.INTEGER)));
- funcList.add(new FuncSpec(LongMax.class.getName(), Schema.generateNestedSchema(DataType.BAG, DataType.LONG)));
- funcList.add(new FuncSpec(StringMax.class.getName(), Schema.generateNestedSchema(DataType.BAG, DataType.CHARARRAY)));*/
+ funcList.add(new FuncSpec(this.getClass().getName(), new Schema(Arrays.asList(
+ new Schema.FieldSchema(null, DataType.FLOAT), new Schema.FieldSchema(null,
+ DataType.FLOAT)))));
+ funcList.add(new FuncSpec(this.getClass().getName(), new Schema(Arrays.asList(
+ new Schema.FieldSchema(null, DataType.LONG), new Schema.FieldSchema(null,
+ DataType.DOUBLE)))));
+ funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(
+ null, DataType.FLOAT))));
+ funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(
+ null, DataType.INTEGER))));
+ funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(
+ null, DataType.DOUBLE))));
+ /*
+ * funcList.add(new FuncSpec(DoubleMax.class.getName(),
+ * Schema.generateNestedSchema(DataType.BAG, DataType.DOUBLE)));
+ * funcList.add(new FuncSpec(FloatMax.class.getName(),
+ * Schema.generateNestedSchema(DataType.BAG, DataType.FLOAT)));
+ * funcList.add(new FuncSpec(IntMax.class.getName(),
+ * Schema.generateNestedSchema(DataType.BAG, DataType.INTEGER)));
+ * funcList.add(new FuncSpec(LongMax.class.getName(),
+ * Schema.generateNestedSchema(DataType.BAG, DataType.LONG)));
+ * funcList.add(new FuncSpec(StringMax.class.getName(),
+ * Schema.generateNestedSchema(DataType.BAG, DataType.CHARARRAY)));
+ */
return funcList;
- }
+ }
}
-
- public static class UDF2 extends EvalFunc<String>{
+
+ public static class UDF2 extends EvalFunc<String> {
/**
* java level API
+ *
* @param input expects a single numeric DataAtom value
* @param output returns a single numeric DataAtom value, cosine value of the argument
*/
@Override
public String exec(Tuple input) throws IOException {
- try{
+ try {
String str = (String)input.get(0);
return str.toUpperCase();
- }catch (Exception e){
+ } catch (Exception e) {
return null;
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.apache.pig.EvalFunc#getArgToFuncMapping()
*/
@Override
public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
List<FuncSpec> funcList = new ArrayList<FuncSpec>();
- funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY))));
+ funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(
+ null, DataType.CHARARRAY))));
return funcList;
- }
+ }
}
-
+
/**
* For testing with input schemas which have byte arrays
*/
- public static class UDF3 extends EvalFunc<Tuple>{
-
+ public static class UDF3 extends EvalFunc<Tuple> {
+
/**
* a UDF which simply returns its input as output
*/
@@ -157,35 +170,35 @@ public class TestBestFitCast {
return input;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.apache.pig.EvalFunc#getArgToFuncMapping()
*/
@Override
public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
List<FuncSpec> funcList = new ArrayList<FuncSpec>();
-
+
// the following schema should match when the input is
// just a {bytearray} - exact match
- funcList.add(new FuncSpec(this.getClass().getName(),
+ funcList.add(new FuncSpec(this.getClass().getName(),
new Schema(new Schema.FieldSchema(null, DataType.BYTEARRAY))));
// the following schema should match when the input is
// just a {int} - exact match
- funcList.add(new FuncSpec(this.getClass().getName(),
+ funcList.add(new FuncSpec(this.getClass().getName(),
new Schema(new Schema.FieldSchema(null, DataType.INTEGER))));
-
+
// The following two schemas will cause conflict when input schema
// is {float, bytearray} since bytearray can be casted either to long
// or double. However when input schema is {bytearray, int}, it should work
// since bytearray should get casted to float and int to long. Likewise if
// input schema is {bytearray, long} or {bytearray, double} it should work
- funcList.add(new FuncSpec(this.getClass().getName(),
+ funcList.add(new FuncSpec(this.getClass().getName(),
new Schema(Arrays.asList(new Schema.FieldSchema(null, DataType.FLOAT),
new Schema.FieldSchema(null, DataType.DOUBLE)))));
- funcList.add(new FuncSpec(this.getClass().getName(),
+ funcList.add(new FuncSpec(this.getClass().getName(),
new Schema(Arrays.asList(new Schema.FieldSchema(null, DataType.FLOAT),
new Schema.FieldSchema(null, DataType.LONG)))));
-
-
+
// The following two schemas will cause conflict when input schema is
// {bytearray, int, int} since the two ints could be casted to long, double
// or double, long. Likewise input schema of either {bytearray, long, long}
@@ -194,43 +207,43 @@ public class TestBestFitCast {
// conflict since only the bytearray needs to be casted to float. Input schema
// of {float, bytearray, long} or {float, long, bytearray} should also
// work since only the bytearray needs to be casted. Input schema of
- // {float, bytearray, int} will cause conflict since we could cast int to
+ // {float, bytearray, int} will cause conflict since we could cast int to
// long or double and bytearray to long or double. Input schema of
- // {bytearray, long, int} should work and should match the first schema below for
+ // {bytearray, long, int} should work and should match the first schema below for
// matching wherein the bytearray is cast to float and the int to double.
- funcList.add(new FuncSpec(this.getClass().getName(),
+ funcList.add(new FuncSpec(this.getClass().getName(),
new Schema(Arrays.asList(new Schema.FieldSchema(null, DataType.FLOAT),
new Schema.FieldSchema(null, DataType.DOUBLE),
new Schema.FieldSchema(null, DataType.LONG)))));
- funcList.add(new FuncSpec(this.getClass().getName(),
+ funcList.add(new FuncSpec(this.getClass().getName(),
new Schema(Arrays.asList(new Schema.FieldSchema(null, DataType.FLOAT),
new Schema.FieldSchema(null, DataType.LONG),
new Schema.FieldSchema(null, DataType.DOUBLE)))));
-
+
return funcList;
- }
+ }
}
@Test
public void testByteArrayCast1() throws IOException {
- //Passing (float, bytearray)
- //Ambiguous matches: (float, long) , (float, double)
+ // Passing (float, bytearray)
+ // Ambiguous matches: (float, long) , (float, double)
boolean exceptionCaused = false;
try {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x:float, y);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- } catch(Exception e) {
+ } catch (Exception e) {
exceptionCaused = true;
PigException pe = LogUtils.getPigException(e);
- String msg = (pe == null? e.getMessage(): pe.getMessage());
+ String msg = (pe == null ? e.getMessage() : pe.getMessage());
assertTrue(msg.contains("Multiple matching functions"));
assertTrue(msg.contains("{float,double}, {float,long}"));
}
assertTrue(exceptionCaused);
}
-
+
@Test
public void testByteArrayCast2() throws IOException, ExecException {
// Passing (bytearray, int)
@@ -240,9 +253,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y:int);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -252,7 +265,7 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast3() throws IOException, ExecException {
// Passing (bytearray, long)
@@ -261,9 +274,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y:long);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x, y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -273,7 +286,7 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast4() throws IOException, ExecException {
// Passing (bytearray, double)
@@ -282,9 +295,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y:double);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -304,18 +317,19 @@ public class TestBestFitCast {
boolean exceptionCaused = false;
try {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y:int);");
- pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y, y);");
+ pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName()
+ + "(x,y, y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- }catch(Exception e) {
+ } catch (Exception e) {
exceptionCaused = true;
PigException pe = LogUtils.getPigException(e);
- String msg = (pe == null? e.getMessage(): pe.getMessage());
+ String msg = (pe == null ? e.getMessage() : pe.getMessage());
assertTrue(msg.contains("Multiple matching functions"));
assertTrue(msg.contains("({float,double,long}, {float,long,double})"));
}
assertTrue(exceptionCaused);
}
-
+
@Test
public void testByteArrayCast6() throws IOException, ExecException {
// Passing (bytearray, long, long )
@@ -325,38 +339,40 @@ public class TestBestFitCast {
boolean exceptionCaused = false;
try {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y:long);");
- pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y, y);");
+ pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName()
+ + "(x,y, y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- }catch(Exception e) {
+ } catch (Exception e) {
exceptionCaused = true;
PigException pe = LogUtils.getPigException(e);
- String msg = (pe == null? e.getMessage(): pe.getMessage());
+ String msg = (pe == null ? e.getMessage() : pe.getMessage());
assertTrue(msg.contains("Multiple matching functions"));
assertTrue(msg.contains("({float,double,long}, {float,long,double})"));
}
assertTrue(exceptionCaused);
}
-
+
@Test
public void testByteArrayCast7() throws IOException, ExecException {
// Passing (bytearray, double, double )
// Ambiguous matches: (float, long, double) , (float, double, long)
- // bytearray can be casted to float but the two doubles cannot be
+ // bytearray can be casted to float but the two doubles cannot be
// casted with a permissible cast
boolean exceptionCaused = false;
try {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y:double);");
- pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y, y);");
+ pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName()
+ + "(x,y, y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- }catch(Exception e) {
+ } catch (Exception e) {
exceptionCaused = true;
PigException pe = LogUtils.getPigException(e);
- String msg = (pe == null? e.getMessage(): pe.getMessage());
+ String msg = (pe == null ? e.getMessage() : pe.getMessage());
assertTrue(msg.contains("Could not infer the matching function"));
}
assertTrue(exceptionCaused);
}
-
+
@Test
public void testByteArrayCast8() throws IOException, ExecException {
// Passing (bytearray, long, double)
@@ -365,9 +381,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile2 + "' as (x, y:long, z:double);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y,z);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -379,7 +395,7 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast9() throws IOException, ExecException {
// Passing (bytearray, double, long)
@@ -388,9 +404,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile2 + "' as (x, y:double, z:long);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y,z);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -402,7 +418,7 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast10() throws IOException, ExecException {
// Passing (float, long, bytearray)
@@ -411,9 +427,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile2 + "' as (x:float, y:long, z);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y,z);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -425,7 +441,7 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast11() throws IOException, ExecException {
// Passing (float, bytearray, long)
@@ -434,9 +450,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile2 + "' as (x:float, y, z:long);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y,z);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -448,42 +464,43 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast12() throws IOException, ExecException {
// Passing (float, bytearray, int )
// Ambiguous matches: (float, long, double) , (float, double, long)
- // will cause conflict since we could cast int to
+ // will cause conflict since we could cast int to
// long or double and bytearray to long or double.
boolean exceptionCaused = false;
try {
pigServer.registerQuery("A = LOAD '" + inputFile2 + "' as (x:float, y, z:int);");
- pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y, y);");
+ pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName()
+ + "(x,y, y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- }catch(Exception e) {
+ } catch (Exception e) {
exceptionCaused = true;
PigException pe = LogUtils.getPigException(e);
- String msg = (pe == null? e.getMessage(): pe.getMessage());
+ String msg = (pe == null ? e.getMessage() : pe.getMessage());
assertTrue(msg.contains("Multiple matching functions"));
assertTrue(msg.contains("({float,double,long}, {float,long,double}"));
}
assertTrue(exceptionCaused);
}
-
+
@Test
public void testByteArrayCast13() throws IOException, ExecException {
// Passing (bytearray, long, int)
// Possible matches: (float, long, double) , (float, double, long)
- // Chooses (float, long, double) since for the bytearray there is a
+ // Chooses (float, long, double) since for the bytearray there is a
// single unambiguous cast to float. For the other two args, it is
// less "costlier" to cast the last int to double than cast the long
// to double and int to long
pigServer.registerQuery("A = LOAD '" + inputFile2 + "' as (x, y:long, z:int);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF3.class.getName() + "(x,y,z);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(1)).get(0) instanceof Float);
assertEquals((Float)((Tuple)t.get(1)).get(0), (Float)0.0f);
@@ -495,7 +512,7 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast14() throws IOException, ExecException {
// Passing (bag{(bytearray)})
@@ -509,7 +526,7 @@ public class TestBestFitCast {
assertTrue(t.get(0) instanceof Double);
assertEquals(new Double(210), (Double)t.get(0));
}
-
+
@Test
public void testByteArrayCast15() throws IOException, ExecException {
// Passing (bytearray)
@@ -518,22 +535,22 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y);");
pigServer.registerQuery("B = FOREACH A generate " + UDF3.class.getName() + "(y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(0)).get(0) instanceof DataByteArray);
byte[] expected = Integer.toString(cnt + 1).getBytes();
byte[] actual = ((DataByteArray)((Tuple)t.get(0)).get(0)).get();
assertEquals(expected.length, actual.length);
- for(int i = 0; i < expected.length; i++) {
+ for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], actual[i]);
}
++cnt;
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testByteArrayCast16() throws IOException, ExecException {
// Passing (int)
@@ -542,9 +559,9 @@ public class TestBestFitCast {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x, y:int);");
pigServer.registerQuery("B = FOREACH A generate " + UDF3.class.getName() + "(y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(((Tuple)t.get(0)).get(0) instanceof Integer);
assertEquals(new Integer(cnt + 1), (Integer)((Tuple)t.get(0)).get(0));
@@ -552,7 +569,7 @@ public class TestBestFitCast {
}
assertEquals(LOOP_SIZE, cnt);
}
-
+
@Test
public void testIntSum() throws IOException, ExecException {
// Passing (bag{(int)})
@@ -566,7 +583,7 @@ public class TestBestFitCast {
assertTrue(t.get(0) instanceof Long);
assertEquals(new Long(210), (Long)t.get(0));
}
-
+
@Test
public void testLongSum() throws IOException, ExecException {
// Passing (bag{(long)})
@@ -580,7 +597,7 @@ public class TestBestFitCast {
assertTrue(t.get(0) instanceof Long);
assertEquals(new Long(210), (Long)t.get(0));
}
-
+
@Test
public void testFloatSum() throws IOException, ExecException {
// Passing (bag{(float)})
@@ -594,7 +611,7 @@ public class TestBestFitCast {
assertTrue(t.get(0) instanceof Double);
assertEquals(new Double(210), (Double)t.get(0));
}
-
+
@Test
public void testDoubleSum() throws IOException, ExecException {
// Passing (bag{(double)})
@@ -608,106 +625,109 @@ public class TestBestFitCast {
assertTrue(t.get(0) instanceof Double);
assertEquals(new Double(210), (Double)t.get(0));
}
-
+
@Test
- public void test1() throws Exception{
- //Passing (long, int)
- //Possible matches: (float, float) , (long, double)
- //Chooses (long, double) as it has only one cast compared to two for (float, float)
+ public void test1() throws Exception {
+ // Passing (long, int)
+ // Possible matches: (float, float) , (long, double)
+ // Chooses (long, double) as it has only one cast compared to two for (float, float)
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x:long, y:int);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF1.class.getName() + "(x,y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(true,((Tuple)t.get(1)).get(0) instanceof Long);
- assertEquals(true,((Tuple)t.get(1)).get(1) instanceof Double);
+ assertEquals(true, ((Tuple)t.get(1)).get(0) instanceof Long);
+ assertEquals(true, ((Tuple)t.get(1)).get(1) instanceof Double);
++cnt;
}
assertEquals(20, cnt);
}
-
+
@Test
- public void test2() throws Exception{
- //Passing (int, int)
- //Possible matches: (float, float) , (long, double)
- //Throws Exception as ambiguous definitions found
- try{
+ public void test2() throws Exception {
+ // Passing (int, int)
+ // Possible matches: (float, float) , (long, double)
+ // Throws Exception as ambiguous definitions found
+ try {
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x:long, y:int);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF1.class.getName() + "(y,y);");
pigServer.openIterator("B");
- }catch (Exception e) {
+ } catch (Exception e) {
PigException pe = LogUtils.getPigException(e);
- String msg = (pe == null? e.getMessage(): pe.getMessage());
- assertEquals(true,msg.contains("as multiple or none of them fit"));
+ String msg = (pe == null ? e.getMessage() : pe.getMessage());
+ assertEquals(true, msg.contains("as multiple or none of them fit"));
}
-
+
}
-
+
@Test
- public void test3() throws Exception{
- //Passing (int, int)
- //Possible matches: (float, float) , (long, double)
- //Chooses (float, float) as both options lead to same score and (float, float) occurs first.
+ public void test3() throws Exception {
+ // Passing (int, int)
+ // Possible matches: (float, float) , (long, double)
+ // Chooses (float, float) as both options lead to same score and (float, float) occurs
+ // first.
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x:long, y:int);");
- pigServer.registerQuery("B = FOREACH A generate x, " + UDF1.class.getName() + "((float)y,(float)y);");
+ pigServer.registerQuery("B = FOREACH A generate x, " + UDF1.class.getName()
+ + "((float)y,(float)y);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(true,((Tuple)t.get(1)).get(0) instanceof Float);
- assertEquals(true,((Tuple)t.get(1)).get(1) instanceof Float);
+ assertEquals(true, ((Tuple)t.get(1)).get(0) instanceof Float);
+ assertEquals(true, ((Tuple)t.get(1)).get(1) instanceof Float);
++cnt;
}
assertEquals(20, cnt);
}
-
+
@Test
- public void test4() throws Exception{
- //Passing (long)
- //Possible matches: (float), (integer), (double)
- //Chooses (float) as it leads to a better score that to (double)
+ public void test4() throws Exception {
+ // Passing (long)
+ // Possible matches: (float), (integer), (double)
+ // Chooses (float) as it leads to a better score that to (double)
pigServer.registerQuery("A = LOAD '" + inputFile + "' as (x:long, y:int);");
pigServer.registerQuery("B = FOREACH A generate x, " + UDF1.class.getName() + "(x);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(true,((Tuple)t.get(1)).get(0) instanceof Float);
+ assertEquals(true, ((Tuple)t.get(1)).get(0) instanceof Float);
++cnt;
}
assertEquals(20, cnt);
}
-
+
@Test
- public void test5() throws Exception{
- //Passing bytearrays
- //Possible matches: (float, float) , (long, double)
- //Throws exception since more than one funcSpec and inp is bytearray
- try{
+ public void test5() throws Exception {
+ // Passing bytearrays
+ // Possible matches: (float, float) , (long, double)
+ // Throws exception since more than one funcSpec and inp is bytearray
+ try {
pigServer.registerQuery("A = LOAD '" + inputFile + "';");
- pigServer.registerQuery("B = FOREACH A generate $0, " + UDF1.class.getName() + "($1,$1);");
+ pigServer.registerQuery("B = FOREACH A generate $0, " + UDF1.class.getName()
+ + "($1,$1);");
pigServer.openIterator("B");
- }catch (Exception e) {
+ } catch (Exception e) {
PigException pe = LogUtils.getPigException(e);
- String msg = (pe == null? e.getMessage(): pe.getMessage());
- assertEquals(true,msg.contains("Multiple matching functions"));
+ String msg = (pe == null ? e.getMessage() : pe.getMessage());
+ assertEquals(true, msg.contains("Multiple matching functions"));
}
-
+
}
@Test
- public void test6() throws Exception{
- // test UDF with single mapping function
+ public void test6() throws Exception {
+ // test UDF with single mapping function
// where bytearray is passed in as input parameter
- Util.createInputFile(cluster, "test6", new String[] {"abc"});
+ Util.createInputFile(cluster, "test6", new String[] { "abc" });
pigServer.registerQuery("A = LOAD 'test6';");
pigServer.registerQuery("B = FOREACH A GENERATE " + UDF2.class.getName() + "($0);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
Tuple t = iter.next();
assertEquals("ABC", t.get(0));
Util.deleteFile(cluster, "test6");