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/07 06:58:06 UTC
svn commit: r1406469 [3/10] - in /pig/trunk: ./ test/org/apache/pig/test/
Modified: pig/trunk/test/org/apache/pig/test/TestJoin.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestJoin.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestJoin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestJoin.java Wed Nov 7 05:58:04 2012
@@ -18,6 +18,11 @@
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
@@ -37,42 +42,36 @@ import org.apache.pig.impl.logicalLayer.
import org.apache.pig.impl.util.LogUtils;
import org.apache.pig.newplan.Operator;
import org.apache.pig.newplan.logical.relational.LOJoin;
-import org.apache.pig.newplan.logical.relational.LogicalPlan;
import org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE;
+import org.apache.pig.newplan.logical.relational.LogicalPlan;
import org.apache.pig.parser.ParserException;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import junit.framework.TestCase;
/**
* Test cases to test join statement
*/
-@RunWith(JUnit4.class)
-public class TestJoin extends TestCase {
-
+public class TestJoin {
+
static MiniCluster cluster;
private PigServer pigServer;
TupleFactory mTf = TupleFactory.getInstance();
BagFactory mBf = BagFactory.getInstance();
ExecType[] execTypes = new ExecType[] {ExecType.LOCAL, ExecType.MAPREDUCE};
-
+
@Before
- @Override
public void setUp() throws Exception{
FileLocalizer.setR(new Random());
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
+
private void setUp(ExecType execType) throws ExecException {
// cause a reinitialization of FileLocalizer's
// internal state
@@ -81,10 +80,10 @@ public class TestJoin extends TestCase {
cluster = MiniCluster.buildCluster();
pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
} else if(execType == ExecType.LOCAL) {
- pigServer = new PigServer(ExecType.LOCAL);
+ pigServer = new PigServer(ExecType.LOCAL);
}
}
-
+
private String createInputFile(ExecType execType, String fileNameHint, String[] data) throws IOException {
String fileName = "";
if(execType == ExecType.MAPREDUCE) {
@@ -96,7 +95,7 @@ public class TestJoin extends TestCase {
}
return fileName;
}
-
+
private void deleteInputFile(ExecType execType, String fileName) throws IOException {
if(execType == ExecType.MAPREDUCE) {
Util.deleteFile(cluster, fileName);
@@ -126,7 +125,7 @@ public class TestJoin extends TestCase {
"",
""
};
-
+
String firstInput = createInputFile(ExecType.MAPREDUCE, "a.txt", input1);
String secondInput = createInputFile(ExecType.MAPREDUCE, "b.txt", input2);
String script = "a = load 'a.txt' using PigStorage(' ');" +
@@ -138,7 +137,7 @@ public class TestJoin extends TestCase {
deleteInputFile(ExecType.MAPREDUCE, firstInput);
deleteInputFile(ExecType.MAPREDUCE, secondInput);
}
-
+
@Test
public void testJoinUnkownSchema() throws Exception {
// If any of the input schema is unknown, the resulting schema should be unknown as well
@@ -149,7 +148,7 @@ public class TestJoin extends TestCase {
"c = join a by $0, b by $0;";
Util.registerMultiLineQuery(pigServer, script);
Schema schema = pigServer.dumpSchema("c");
- assertTrue(schema == null);
+ assertNull(schema);
}
}
@@ -167,36 +166,36 @@ public class TestJoin extends TestCase {
"good\tmorning",
"\tevening"
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
Tuple expectedResult = (Tuple)Util.getPigConstant("('hello',1,'hello','world')");
-
+
// with schema
String script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (n:chararray, a:int); " +
- "b = load '"+ Util.encodeEscape(secondInput) +"' as (n:chararray, m:chararray); " +
- "c = join a by $0, b by $0;";
+ "b = load '"+ Util.encodeEscape(secondInput) +"' as (n:chararray, m:chararray); " +
+ "c = join a by $0, b by $0;";
Util.registerMultiLineQuery(pigServer, script);
Iterator<Tuple> it = pigServer.openIterator("c");
- assertEquals(true, it.hasNext());
+ assertTrue(it.hasNext());
assertEquals(expectedResult, it.next());
- assertEquals(false, it.hasNext());
-
+ assertFalse(it.hasNext());
+
// without schema
script = "a = load '"+ Util.encodeEscape(firstInput) + "'; " +
"b = load '" + Util.encodeEscape(secondInput) + "'; " +
"c = join a by $0, b by $0;";
Util.registerMultiLineQuery(pigServer, script);
it = pigServer.openIterator("c");
- assertEquals(true, it.hasNext());
+ assertTrue(it.hasNext());
assertEquals(expectedResult.toString(), it.next().toString());
- assertEquals(false, it.hasNext());
+ assertFalse(it.hasNext());
deleteInputFile(execType, firstInput);
deleteInputFile(execType, secondInput);
}
}
-
-
+
+
@Test
public void testJoinSchema() throws Exception {
for (ExecType execType : execTypes) {
@@ -210,11 +209,11 @@ public class TestJoin extends TestCase {
"1\thello",
"4\tbye",
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
Tuple expectedResult = (Tuple)Util.getPigConstant("(1,2,1,'hello',1,2,1,'hello')");
-
+
// with schema
String script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (i:int, j:int); " +
"b = load '"+ Util.encodeEscape(secondInput) +"' as (k:int, l:chararray); " +
@@ -222,10 +221,10 @@ public class TestJoin extends TestCase {
"d = foreach c generate i,j,k,l,a::i as ai,a::j as aj,b::k as bk,b::l as bl;";
Util.registerMultiLineQuery(pigServer, script);
Iterator<Tuple> it = pigServer.openIterator("d");
- assertEquals(true, it.hasNext());
+ assertTrue(it.hasNext());
assertEquals(expectedResult, it.next());
- assertEquals(false, it.hasNext());
-
+ assertFalse(it.hasNext());
+
// schema with duplicates
script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (i:int, j:int); " +
"b = load '"+ Util.encodeEscape(secondInput) +"' as (i:int, l:chararray); " +
@@ -240,8 +239,8 @@ public class TestJoin extends TestCase {
assertEquals(1025, pe.getErrorCode());
exceptionThrown = true;
}
- assertEquals(true, exceptionThrown);
-
+ assertTrue(exceptionThrown);
+
// schema with duplicates with resolution
script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (i:int, j:int); " +
"b = load '"+ Util.encodeEscape(secondInput) +"' as (i:int, l:chararray); " +
@@ -249,14 +248,14 @@ public class TestJoin extends TestCase {
"d = foreach c generate a::i as ai1,j,b::i as bi1,l,a::i as ai2,a::j as aj2,b::i as bi3,b::l as bl3;";
Util.registerMultiLineQuery(pigServer, script);
it = pigServer.openIterator("d");
- assertEquals(true, it.hasNext());
+ assertTrue(it.hasNext());
assertEquals(expectedResult, it.next());
- assertEquals(false, it.hasNext());
+ assertFalse(it.hasNext());
deleteInputFile(execType, firstInput);
deleteInputFile(execType, secondInput);
}
}
-
+
@Test
public void testJoinSchema2() throws Exception {
// test join where one load does not have schema
@@ -271,20 +270,20 @@ public class TestJoin extends TestCase {
"1\thello",
"4\tbye",
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
Tuple expectedResultCharArray =
(Tuple)Util.getPigConstant("('1','2','1','hello','1','2','1','hello')");
-
+
Tuple expectedResult = TupleFactory.getInstance().newTuple();
for(Object field : expectedResultCharArray.getAll()){
expectedResult.append(new DataByteArray(field.toString()));
}
-
+
// with schema
String script = "a = load '"+ Util.encodeEscape(firstInput) +"' ; " +
- //re-using alias a for new operator below, doing this intentionally
+ //re-using alias a for new operator below, doing this intentionally
// because such use case has been seen
"a = foreach a generate $0 as i, $1 as j ;" +
"b = load '"+ Util.encodeEscape(secondInput) +"' as (k, l); " +
@@ -292,15 +291,15 @@ public class TestJoin extends TestCase {
"d = foreach c generate i,j,k,l,a::i as ai,a::j as aj,b::k as bk,b::l as bl;";
Util.registerMultiLineQuery(pigServer, script);
Iterator<Tuple> it = pigServer.openIterator("d");
- assertEquals(true, it.hasNext());
+ assertTrue(it.hasNext());
Tuple res = it.next();
assertEquals(expectedResult, res);
- assertEquals(false, it.hasNext());
+ assertFalse(it.hasNext());
deleteInputFile(execType, firstInput);
deleteInputFile(execType, secondInput);
-
+
}
-
+
@Test
public void testLeftOuterJoin() throws Exception {
for (ExecType execType : execTypes) {
@@ -314,18 +313,18 @@ public class TestJoin extends TestCase {
"hello\tworld",
"good\tmorning",
"\tevening"
-
+
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings(
- new String[] {
+ new String[] {
"('hello',1,'hello','world')",
"('bye',2,null,null)",
"(null,3,null,null)"
});
-
+
// with and without optional outer
for(int i = 0; i < 2; i++) {
//with schema
@@ -339,7 +338,7 @@ public class TestJoin extends TestCase {
script += "d = order c by $1;";
// ensure we parse correctly
Util.buildLp(pigServer, script);
-
+
// run query and test results only once
if(i == 0) {
Util.registerMultiLineQuery(pigServer, script);
@@ -349,7 +348,7 @@ public class TestJoin extends TestCase {
assertEquals(expectedResults.get(counter++), it.next());
}
assertEquals(expectedResults.size(), counter);
-
+
// without schema
script = "a = load '"+ Util.encodeEscape(firstInput) +"'; " +
"b = load '"+ Util.encodeEscape(secondInput) +"'; ";
@@ -384,9 +383,9 @@ public class TestJoin extends TestCase {
"hello\tworld",
"good\tmorning",
"\tevening"
-
+
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings(
@@ -408,7 +407,7 @@ public class TestJoin extends TestCase {
script += "d = order c by $3;";
// ensure we parse correctly
Util.buildLp(pigServer, script);
-
+
// run query and test results only once
if(i == 0) {
Util.registerMultiLineQuery(pigServer, script);
@@ -418,7 +417,7 @@ public class TestJoin extends TestCase {
assertEquals(expectedResults.get(counter++), it.next());
}
assertEquals(expectedResults.size(), counter);
-
+
// without schema
script = "a = load '"+ Util.encodeEscape(firstInput) +"'; " +
"b = load '"+ Util.encodeEscape(secondInput) +"'; " ;
@@ -439,7 +438,7 @@ public class TestJoin extends TestCase {
deleteInputFile(execType, secondInput);
}
}
-
+
@Test
public void testFullOuterJoin() throws Exception {
for (ExecType execType : execTypes) {
@@ -453,9 +452,9 @@ public class TestJoin extends TestCase {
"hello\tworld",
"good\tmorning",
"\tevening"
-
+
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings(
@@ -479,7 +478,7 @@ public class TestJoin extends TestCase {
script += "d = order c by $1, $3;";
// ensure we parse correctly
Util.buildLp(pigServer, script);
-
+
// run query and test results only once
if(i == 0) {
Util.registerMultiLineQuery(pigServer, script);
@@ -489,7 +488,7 @@ public class TestJoin extends TestCase {
assertEquals(expectedResults.get(counter++), it.next());
}
assertEquals(expectedResults.size(), counter);
-
+
// without schema
script = "a = load '"+ Util.encodeEscape(firstInput) +"'; " +
"b = load '"+ Util.encodeEscape(secondInput) +"'; " ;
@@ -510,10 +509,10 @@ public class TestJoin extends TestCase {
deleteInputFile(execType, secondInput);
}
}
-
+
@Test
public void testMultiOuterJoinFailure() throws ExecException {
- setUp(ExecType.LOCAL);
+ setUp(ExecType.LOCAL);
String[] types = new String[] { "left", "right", "full" };
String query = "a = load 'a.txt' as (n:chararray, a:int);\n" +
"b = load 'b.txt' as (n:chararray, m:chararray);\n"+
@@ -521,23 +520,23 @@ public class TestJoin extends TestCase {
for (int i = 0; i < types.length; i++) {
boolean errCaught = false;
try {
- String q = query +
- "d = join a by $0 " + types[i] + " outer, b by $0, c by $0;" +
- "store d into 'output';";
- Util.buildLp(pigServer, q);
+ String q = query +
+ "d = join a by $0 " + types[i] + " outer, b by $0, c by $0;" +
+ "store d into 'output';";
+ Util.buildLp(pigServer, q);
} catch(Exception e) {
errCaught = true;
assertTrue(e.getMessage().contains("mismatched input ',' expecting SEMI_COLON"));
}
- assertEquals(true, errCaught);
-
+ assertTrue(errCaught);
+
}
-
+
}
-
+
@Test
public void testNonRegularOuterJoinFailure() throws ExecException {
- setUp(ExecType.LOCAL);
+ setUp(ExecType.LOCAL);
String query = "a = load 'a.txt' as (n:chararray, a:int); "+
"b = load 'b.txt' as (n:chararray, m:chararray); ";
String[] types = new String[] { "left", "right", "full" };
@@ -546,21 +545,21 @@ public class TestJoin extends TestCase {
for(int j = 0; j < joinTypes.length; j++) {
boolean errCaught = false;
try {
- String q = query + "d = join a by $0 " +
+ String q = query + "d = join a by $0 " +
types[i] + " outer, b by $0 using '" + joinTypes[j] +"';" +
"store d into 'output';";
Util.buildLp(pigServer, q);
-
+
} catch(Exception e) {
errCaught = true;
// This after adding support of LeftOuter Join to replicated Join
- assertEquals(true, e.getMessage().contains("does not support (right|full) outer joins"));
+ assertTrue(e.getMessage().contains("does not support (right|full) outer joins"));
}
assertEquals( i == 0 ? false : true, errCaught);
}
}
}
-
+
@Test
public void testJoinTupleFieldKey() throws Exception{
for (ExecType execType : execTypes) {
@@ -573,24 +572,24 @@ public class TestJoin extends TestCase {
"(1,b)",
"(2,bb)"
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
-
+
String script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (a:tuple(a1:int, a2:chararray));" +
"b = load '"+ Util.encodeEscape(secondInput) +"' as (b:tuple(b1:int, b2:chararray));" +
"c = join a by a.a1, b by b.b1;";
Util.registerMultiLineQuery(pigServer, script);
Iterator<Tuple> it = pigServer.openIterator("c");
-
+
assertTrue(it.hasNext());
Tuple t = it.next();
- assertTrue(t.toString().equals("((1,a),(1,b))"));
-
+ assertEquals("((1,a),(1,b))", t.toString());
+
assertTrue(it.hasNext());
t = it.next();
- assertTrue(t.toString().equals("((2,aa),(2,bb))"));
-
+ assertEquals("((2,aa),(2,bb))", t.toString());
+
deleteInputFile(execType, firstInput);
deleteInputFile(execType, secondInput);
}
@@ -608,30 +607,30 @@ public class TestJoin extends TestCase {
"1\t",
"2\taa"
};
-
+
String firstInput = createInputFile(execType, "a.txt", input1);
String secondInput = createInputFile(execType, "b.txt", input2);
-
+
String script = "a = load '"+ Util.encodeEscape(firstInput) +"' as (a1:int, a2:chararray);" +
"b = load '"+ Util.encodeEscape(secondInput) +"' as (b1:int, b2:chararray);" +
"c = join a by (a1, a2), b by (b1, b2);";
Util.registerMultiLineQuery(pigServer, script);
Iterator<Tuple> it = pigServer.openIterator("c");
-
+
assertTrue(it.hasNext());
Tuple t = it.next();
- assertTrue(t.toString().equals("(2,aa,2,aa)"));
-
+ assertEquals("(2,aa,2,aa)", t.toString());
+
assertFalse(it.hasNext());
-
+
deleteInputFile(execType, firstInput);
deleteInputFile(execType, secondInput);
}
}
-
+
@Test
public void testLiteralsForJoinAlgoSpecification1() throws Exception {
- setUp(ExecType.LOCAL);
+ setUp(ExecType.LOCAL);
String query = "a = load 'A'; " +
"b = load 'B'; " +
"c = Join a by $0, b by $0 using 'merge';" +
@@ -641,10 +640,10 @@ public class TestJoin extends TestCase {
LOJoin join = (LOJoin)lp.getPredecessors( store ).get(0);
assertEquals(JOINTYPE.MERGE, join.getJoinType());
}
-
+
@Test
public void testLiteralsForJoinAlgoSpecification2() throws Exception {
- setUp(ExecType.LOCAL);
+ setUp(ExecType.LOCAL);
String query = "a = load 'A'; " +
"b = load 'B'; " +
"c = Join a by $0, b by $0 using 'hash'; "+
@@ -654,12 +653,12 @@ public class TestJoin extends TestCase {
LOJoin join = (LOJoin) lp.getPredecessors( store ).get(0);
assertEquals(JOINTYPE.HASH, join.getJoinType());
}
-
+
@Test
public void testLiteralsForJoinAlgoSpecification5() throws Exception {
- setUp(ExecType.LOCAL);
+ setUp(ExecType.LOCAL);
String query = "a = load 'A'; " +
- "b = load 'B'; " +
+ "b = load 'B'; " +
"c = Join a by $0, b by $0 using 'default'; "+
"store c into 'output';";
LogicalPlan lp = Util.buildLp(pigServer, query);
@@ -667,10 +666,10 @@ public class TestJoin extends TestCase {
LOJoin join = (LOJoin) lp.getPredecessors( store ).get(0);
assertEquals(JOINTYPE.HASH, join.getJoinType());
}
-
+
@Test
public void testLiteralsForJoinAlgoSpecification3() throws Exception {
- setUp(ExecType.LOCAL);
+ setUp(ExecType.LOCAL);
String query = "a = load 'A'; " +
"b = load 'B'; " +
"c = Join a by $0, b by $0 using 'repl'; "+
@@ -680,11 +679,11 @@ public class TestJoin extends TestCase {
LOJoin join = (LOJoin) lp.getPredecessors( store ).get(0);
assertEquals(JOINTYPE.REPLICATED, join.getJoinType());
}
-
+
@Test
public void testLiteralsForJoinAlgoSpecification4() throws Exception {
- setUp(ExecType.LOCAL);
- String query = "a = load 'A'; " +
+ setUp(ExecType.LOCAL);
+ String query = "a = load 'A'; " +
"b = load 'B'; " +
"c = Join a by $0, b by $0 using 'replicated'; "+
"store c into 'output';";
Modified: pig/trunk/test/org/apache/pig/test/TestKeyTypeDiscoveryVisitor.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestKeyTypeDiscoveryVisitor.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestKeyTypeDiscoveryVisitor.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestKeyTypeDiscoveryVisitor.java Wed Nov 7 05:58:04 2012
@@ -17,70 +17,65 @@
*/
package org.apache.pig.test;
-import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
import java.util.Iterator;
-import java.util.Random;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.data.BagFactory;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
-import org.apache.pig.impl.io.FileLocalizer;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import junit.framework.TestCase;
/**
* This testcases here test that the key type of the map key
- * is correctly determines for use when the key is null. In
+ * is correctly determines for use when the key is null. In
* particular it tests KeyTypeDiscoveryVisitor
*/
-@RunWith(JUnit4.class)
-public class TestKeyTypeDiscoveryVisitor extends TestCase {
+public class TestKeyTypeDiscoveryVisitor {
static MiniCluster cluster = MiniCluster.buildCluster();
private PigServer pigServer;
TupleFactory mTf = TupleFactory.getInstance();
BagFactory mBf = BagFactory.getInstance();
-
+
@Before
public void setUp() throws Exception{
- pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties()); //TODO this doesn't need to be M/R mode
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
+
@Test
public void testNullJoin() throws Exception {
String[] inputData = new String[] { "\t7\t8", "\t8\t9", "1\t20\t30", "1\t20\t40" };
Util.createInputFile(cluster, "a.txt", inputData);
-
+
inputData = new String[] { "7\t2", "1\t5", "1\t10" };
Util.createInputFile(cluster, "b.txt", inputData);
-
+
String script = "a = load 'a.txt' as (x:int, y:int, z:int);" +
- "b = load 'b.txt' as (x:int, y:int);" +
- "b_group = group b by x;" +
- "b_sum = foreach b_group generate flatten(group) as x, SUM(b.y) as clicks;" +
- // b_sum will have {(1, 15L)}
- "a_group = group a by (x, y);" +
- "a_aggs = foreach a_group generate flatten(group) as (x, y), SUM(a.z) as zs;" +
- // a_aggs will have {(<null>, 7, 8L), (<null>, 8, 9L), (1, 20, 70L)
- // The join in the next statement is on "x" which is the first column
- // The nulls in the first two records of a_aggs will test whether
- // KeyTypeDiscoveryVisitor had set a valid keyType (in this case INTEGER)
- // The null records will get discarded by the join and hence the join
- // output would be {(1, 15L, 1, 20, 70L)}
- "join_a_b = join b_sum by x, a_aggs by x;";
+ "b = load 'b.txt' as (x:int, y:int);" +
+ "b_group = group b by x;" +
+ "b_sum = foreach b_group generate flatten(group) as x, SUM(b.y) as clicks;" +
+ // b_sum will have {(1, 15L)}
+ "a_group = group a by (x, y);" +
+ "a_aggs = foreach a_group generate flatten(group) as (x, y), SUM(a.z) as zs;" +
+ // a_aggs will have {(<null>, 7, 8L), (<null>, 8, 9L), (1, 20, 70L)
+ // The join in the next statement is on "x" which is the first column
+ // The nulls in the first two records of a_aggs will test whether
+ // KeyTypeDiscoveryVisitor had set a valid keyType (in this case INTEGER)
+ // The null records will get discarded by the join and hence the join
+ // output would be {(1, 15L, 1, 20, 70L)}
+ "join_a_b = join b_sum by x, a_aggs by x;";
Util.registerMultiLineQuery(pigServer, script);
Iterator<Tuple> it = pigServer.openIterator("join_a_b");
Object[] results = new Object[] { 1, 15L, 1, 20, 70L};
@@ -90,7 +85,6 @@ public class TestKeyTypeDiscoveryVisitor
for (int i = 0; i < output.size(); i++) {
assertEquals(results[i], output.get(i));
}
-
- }
+ }
}
Modified: pig/trunk/test/org/apache/pig/test/TestLargeFile.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLargeFile.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestLargeFile.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestLargeFile.java Wed Nov 7 05:58:04 2012
@@ -18,170 +18,140 @@
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Iterator;
+import java.util.Random;
+
+import org.apache.hadoop.conf.Configuration;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
-
import org.apache.pig.data.DataType;
import org.apache.pig.data.Tuple;
-
import org.apache.pig.impl.io.FileLocalizer;
-
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;
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.FileOutputStream;
-import java.util.Iterator;
-import java.util.Random;
-import org.apache.pig.backend.executionengine.ExecException;
+/**
+ * This class tests pig behavior with large file spanning multiple blocks along with group and count functions
+ * Order and Distinct functions are also tested. This test takes long time because of the large test files.
+ */
+public class TestLargeFile {
-import org.apache.hadoop.conf.Configuration;
-//This class tests pig behavior with large file spanning multiple blocks along with group and count functions
-//Order and Distinct functions are also tested.
-//This test would take a long time because of the large test files.
-
-@RunWith(JUnit4.class)
-public class TestLargeFile extends TestCase {
-
File datFile;
-
+
private long defaultBlockSize = (new Configuration()).getLong("dfs.block.size", 0);
-
+
private long total = defaultBlockSize >> 1;
private int max_rand = 500;
-// private double sum = 0.0, sumIn = 0.0;
static MiniCluster cluster = MiniCluster.buildCluster();
-
- Integer [] COUNT = new Integer[max_rand];
-
+ Integer[] COUNT = new Integer[max_rand];
+
PigServer pig;
String fileName, tmpFile1;
-
- @Override
+
@Before
public void setUp() throws Exception{
System.out.println("Generating test data...");
System.out.println("Default block size = " + defaultBlockSize);
System.out.println("Total no. of iterations to run for the test data = " + total);
-
+
datFile = File.createTempFile("StoreTest", ".dat");
-
+
FileOutputStream dat = new FileOutputStream(datFile);
-
+
Random rand = new Random();
-
+
for(int i = 0; i < max_rand; i++) {
COUNT[i] = 0;
}
-
-
- for(long i = 0; i < total; i++) {
+ for(long i = 0; i < total; i++) {
Integer x = new Integer(rand.nextInt(max_rand));
- COUNT[x.intValue()] ++;
+ COUNT[x.intValue()]++;
dat.write((x.toString() + "\n").getBytes());
}
-
+
dat.close();
-
- try {
- pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
- }
- catch (ExecException e) {
- IOException ioe = new IOException("Failed to create Pig server");
- ioe.initCause(e);
- throw ioe;
- }
+
+ pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+
fileName = "'" + FileLocalizer.hadoopify(datFile.toString(), pig.getPigContext()) + "'";
tmpFile1 = "'" + FileLocalizer.getTemporaryPath(pig.getPigContext()).toString() + "'";
datFile.delete();
}
-
- @Override
+
@After
public void tearDown() throws Exception {
-
-
+ pig.shutdown();
}
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
+
@Test
public void testLargeFile () throws Exception {
System.out.println("Running testLargeFile...");
pig.registerQuery("A = load " + fileName + ";");
pig.registerQuery("A = group A by $0;");
pig.store("A", tmpFile1, "BinStorage()");
-// pig.store("A", tmpFile1);
pig.registerQuery("B = foreach A generate group, COUNT($1);");
-
- Iterator <Tuple> B = pig.openIterator("B");
-
- while(B.hasNext()) {
+
+ Iterator<Tuple> B = pig.openIterator("B");
+
+ while (B.hasNext()) {
Tuple temp = B.next();
int index = DataType.toInteger(temp.get(0));
int value = DataType.toInteger(temp.get(1));
System.out.println("COUNT [" + index + "] = " + COUNT[index] + " B[" + index + "] = " + value);
-
+
assertEquals(COUNT[index].intValue(), value);
-
}
-
}
-
+
@Test
- public void testOrder () throws Exception {
+ public void testOrder() throws Exception {
System.out.println("Running testOrder...");
int N = 0, Nplus1 = 0;
pig.registerQuery("A = load " + fileName + ";");
pig.registerQuery("B = order A by $0;");
-
- Iterator <Tuple> B = pig.openIterator("B");
-
- if(B.hasNext()) {
+
+ Iterator<Tuple> B = pig.openIterator("B");
+
+ if (B.hasNext()) {
N = DataType.toInteger(B.next().get(0));
}
-
- while(B.hasNext()) {
- int flag = 0;
+
+ while (B.hasNext()) {
Nplus1 = DataType.toInteger(B.next().get(0));
- if(Nplus1 >= N) {
- flag = 1;
- }
- assertEquals(flag, 1);
-
+
+ assertTrue("Expecting Nplus ["+Nplus1+"] to be greater than or equal to N ["+N+"]", Nplus1 >= N);
+
N = Nplus1;
-
}
-
-
}
-
+
@Test
- public void testDistinct () throws Exception {
+ public void testDistinct() throws Exception {
System.out.println("Running testDistinct...");
pig.registerQuery("A = load " + fileName + ";");
pig.registerQuery("B = distinct A;");
-
+
Iterator <Tuple> B = pig.openIterator("B");
-
- Integer [] COUNT_Test = new Integer [max_rand];
- Integer [] COUNT_Data = new Integer [max_rand];
-
+
+ Integer[] COUNT_Test = new Integer[max_rand];
+ Integer[] COUNT_Data = new Integer[max_rand];
+
for(int i = 0; i < max_rand; i++) {
COUNT_Test[i] = 0;
if (COUNT[i] > 0) {
@@ -190,16 +160,14 @@ public class TestLargeFile extends TestC
COUNT_Data[i] = 0;
}
}
-
+
while(B.hasNext()) {
int temp = DataType.toInteger(B.next().get(0));
COUNT_Test[temp] ++;
}
-
+
for(int i = 0; i < max_rand; i++) {
assertEquals(COUNT_Test[i].intValue(), COUNT_Data[i].intValue());
}
-
}
-
-}
+}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestLocal.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLocal.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestLocal.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestLocal.java Wed Nov 7 05:58:04 2012
@@ -17,6 +17,8 @@
*/
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
@@ -26,11 +28,10 @@ import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Iterator;
-import junit.framework.TestCase;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pig.EvalFunc;
+import org.apache.pig.ExecType;
import org.apache.pig.FuncSpec;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
@@ -46,25 +47,23 @@ import org.apache.pig.test.utils.TestHel
import org.junit.Before;
import org.junit.Test;
-public class TestLocal extends TestCase {
+public class TestLocal {
private Log log = LogFactory.getLog(getClass());
-
+
private PigServer pig;
-
+
@Before
- @Override
- protected void setUp() throws Exception {
- //pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
- pig = new PigServer("local");
+ public void setUp() throws Exception {
+ pig = new PigServer(ExecType.LOCAL);
}
@Test
public void testBigGroupAll() throws Throwable {
int LOOP_COUNT = 4*1024;
- File tmpFile = File.createTempFile( this.getName(), ".txt");
+ File tmpFile = File.createTempFile( this.getClass().getName(), ".txt");
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
for(int i = 0; i < LOOP_COUNT; i++) {
ps.println(i);
@@ -79,7 +78,7 @@ public class TestLocal extends TestCase
public void testBigGroupAllWithNull() throws Throwable {
int LOOP_COUNT = 4*1024;
- File tmpFile = File.createTempFile( this.getName(), ".txt");
+ File tmpFile = File.createTempFile( this.getClass().getName(), ".txt");
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
long nonNullCnt = 0;
for(int i = 0; i < LOOP_COUNT; i++) {
@@ -98,7 +97,6 @@ public class TestLocal extends TestCase
}
- @Test
public Double bigGroupAll( File tmpFile ) throws Throwable {
String query = "foreach (group (load '"
@@ -106,13 +104,13 @@ public class TestLocal extends TestCase
+ "') all) generate " + COUNT.class.getName() + "($1) ;";
System.out.println(query);
pig.registerQuery("asdf_id = " + query);
- Iterator it = pig.openIterator("asdf_id");
- Tuple t = (Tuple)it.next();
+ Iterator<Tuple> it = pig.openIterator("asdf_id");
+ Tuple t = it.next();
return DataType.toDouble(t.get(0));
}
-
+
static public class MyApply extends EvalFunc<DataBag> {
String field0 = "Got";
public MyApply() {}
@@ -121,23 +119,15 @@ public class TestLocal extends TestCase
}
@Override
public DataBag exec(Tuple input) throws IOException {
- try {
- DataBag output = BagFactory.getInstance().newDefaultBag();
- Iterator<Tuple> it = (DataType.toBag(input.get(0))).iterator();
- while(it.hasNext()) {
- Tuple t = it.next();
- Tuple newT = TupleFactory.getInstance().newTuple(2);
- newT.set(0, field0);
- newT.set(1, t.get(0).toString());
- output.add(newT);
- }
-
- return output;
- } catch (ExecException ee) {
- IOException ioe = new IOException(ee.getMessage());
- ioe.initCause(ee);
- throw ioe;
+ DataBag output = BagFactory.getInstance().newDefaultBag();
+ for (Tuple t : DataType.toBag(input.get(0))) {
+ Tuple newT = TupleFactory.getInstance().newTuple(2);
+ newT.set(0, field0);
+ newT.set(1, t.get(0).toString());
+ output.add(newT);
}
+
+ return output;
}
}
static public class MyGroup extends EvalFunc<Tuple> {
@@ -165,14 +155,14 @@ public class TestLocal extends TestCase
public void setNulls(boolean hasNulls ) { this.hasNulls=hasNulls; }
/**
- *
+ *
*/
public MyStorage() {
// initialize delimiter to be "-" for output
// since that is the delimiter in the tests below
super("-");
}
-
+
@Override
public Tuple getNext() throws IOException {
if (count < COUNT) {
@@ -242,7 +232,7 @@ public class TestLocal extends TestCase
String[][] data = genDataSetFile1( 10, true );
storeFunction( data);
}
-
+
public void storeFunction(String[][] data) throws Throwable {
File tmpFile=TestHelper.createTempFile(data) ;
@@ -302,11 +292,11 @@ public class TestLocal extends TestCase
pig.registerQuery("asdf_id = " + query);
//Verfiy query
- Iterator it = pig.openIterator("asdf_id");
+ Iterator<Tuple> it = pig.openIterator("asdf_id");
Tuple t;
int count = 0;
while(it.hasNext()) {
- t = (Tuple) it.next();
+ t = it.next();
assertEquals(t.get(0).toString(), "Got");
Integer.parseInt(t.get(1).toString());
count++;
@@ -315,7 +305,7 @@ public class TestLocal extends TestCase
assertEquals( MyStorage.COUNT, count );
tmpFile.delete();
}
-
+
@Test
public void testQualifiedFunctionsWithNulls() throws Throwable {
@@ -354,7 +344,7 @@ public class TestLocal extends TestCase
assertEquals( MyStorage.COUNT, count );
tmpFile.delete();
}
-
+
@Test
public void testDefinedFunctions() throws Throwable {
@@ -405,7 +395,6 @@ public class TestLocal extends TestCase
}
- @Test
public void definedFunctions(String[][] data) throws Throwable {
File tmpFile=TestHelper.createTempFile(data) ;
@@ -477,11 +466,11 @@ public class TestLocal extends TestCase
* 3 3
* 4 4
* 5 5
- * 6
+ * 6
* 7 7
- *
+ *
* 9 9
- *
+ *
*/
private String[][] genDataSetFile1( int dataLength, boolean hasNulls ) throws IOException {
@@ -498,7 +487,7 @@ public class TestLocal extends TestCase
data[i][1] = new Integer(i).toString();
} else if ( i == 6 ) {
-
+
data[i][0] = new Integer(i).toString();
data[i][1] = "";
@@ -526,6 +515,4 @@ public class TestLocal extends TestCase
return data;
}
-
-
-}
+}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestLocal2.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLocal2.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestLocal2.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestLocal2.java Wed Nov 7 05:58:04 2012
@@ -18,10 +18,21 @@
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.text.DecimalFormat;
+import java.util.Iterator;
+
import junit.framework.Assert;
-import junit.framework.TestCase;
import org.apache.pig.EvalFunc;
+import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.data.BagFactory;
import org.apache.pig.data.DataBag;
@@ -29,21 +40,12 @@ import org.apache.pig.data.Tuple;
import org.apache.pig.test.utils.TestHelper;
import org.junit.Test;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.text.DecimalFormat;
-import java.util.Iterator;
-
-public class TestLocal2 extends TestCase {
-
- private String initString = "local";
+public class TestLocal2 {
private PigServer pig ;
public TestLocal2() throws Throwable {
- pig = new PigServer(initString) ;
+ pig = new PigServer(ExecType.LOCAL) ;
}
@@ -58,7 +60,7 @@ public class TestLocal2 extends TestCase
+ Util.generateURI(Util.encodeEscape(tmpFile2.toString()), pig.getPigContext())
+ "'; ");
pig.registerQuery("c = union a, b; ") ;
-
+
verifyUnion( "c", 30 + 50 );
}
@@ -112,51 +114,51 @@ public class TestLocal2 extends TestCase
verifyUnion( "c", 30 + 50 );
}
-
+
@Test
public void testPig800Distinct() throws Exception {
// Regression test for Pig-800
File fp1 = File.createTempFile("test", "txt");
PrintStream ps = new PrintStream(new FileOutputStream(fp1));
-
+
ps.println("1\t1}");
ps.close();
-
+
pig.registerQuery("A = load '"
+ Util.generateURI(Util.encodeEscape(fp1.toString()), pig.getPigContext())
+ "'; ");
pig.registerQuery("B = foreach A generate flatten("
+ Pig800Udf.class.getName() + "($0));");
pig.registerQuery("C = distinct B;");
-
+
Iterator<Tuple> iter = pig.openIterator("C");
// Before PIG-800 was fixed this went into an infinite loop, so just
// managing to open the iterator is sufficient.
fp1.delete();
-
+
}
-
+
@Test
public void testPig800Sort() throws Exception {
// Regression test for Pig-800
File fp1 = File.createTempFile("test", "txt");
PrintStream ps = new PrintStream(new FileOutputStream(fp1));
-
+
ps.println("1\t1}");
ps.close();
-
+
pig.registerQuery("A = load '"
+ Util.generateURI(Util.encodeEscape(fp1.toString()), pig.getPigContext())
+ "'; ");
pig.registerQuery("B = foreach A generate flatten("
+ Pig800Udf.class.getName() + "($0));");
pig.registerQuery("C = order B by $0;");
-
+
Iterator<Tuple> iter = pig.openIterator("C");
// Before PIG-800 was fixed this went into an infinite loop, so just
// managing to open the iterator is sufficient.
fp1.delete();
-
+
}
@Test
@@ -164,10 +166,10 @@ public class TestLocal2 extends TestCase
// Regression test for PIG-1546
File fp1 = File.createTempFile("opTest", "txt");
PrintStream ps = new PrintStream(new FileOutputStream(fp1));
-
+
ps.println("1\t2");
ps.close();
-
+
pig.registerQuery("A = load '"
+ Util.generateURI(Util.encodeEscape(fp1.toString()), pig.getPigContext())
+ "' AS (c1:int, c2:int); ");
@@ -175,35 +177,35 @@ public class TestLocal2 extends TestCase
pig.registerQuery("C = filter B by c1 < 2;");
pig.registerQuery("D = filter C by c1 >= 0;");
pig.registerQuery("E = filter D by c1 <= 2;");
-
+
Iterator<Tuple> iter = pig.openIterator("E");
assertTrue(iter.hasNext());
Tuple t = iter.next();
- assertTrue(t.get(0).equals(new Integer(1)));
- assertTrue(t.get(1).equals(new Integer(2)));
+ assertEquals(Integer.valueOf(1), t.get(0));
+ assertEquals(Integer.valueOf(2), t.get(1));
assertFalse(iter.hasNext());
fp1.delete();
}
-
+
@Test
public void testJoin1() throws Exception {
// Regression test for Pig-925
File fp1 = File.createTempFile("test1", "txt");
PrintStream ps = new PrintStream(new FileOutputStream(fp1));
-
+
ps.println("1\t1");
ps.println("2\t2");
ps.close();
-
+
File fp2 = File.createTempFile("test2", "txt");
ps = new PrintStream(new FileOutputStream(fp2));
-
+
ps.println("1\t1");
ps.println("2\t2");
ps.close();
-
-
+
+
pig.registerQuery("A = load '"
+ Util.generateURI(Util.encodeEscape(fp1.toString()), pig.getPigContext())
+ "'AS (a0:int, a1:int); ");
@@ -211,29 +213,28 @@ public class TestLocal2 extends TestCase
+ Util.generateURI(Util.encodeEscape(fp2.toString()), pig.getPigContext())
+ "'AS (b0:int, b1:int); ");
pig.registerQuery("C = join A by a0, B by b0;");
-
+
Iterator<Tuple> iter = pig.openIterator("C");
assertTrue(iter.hasNext());
Tuple t = iter.next();
- assertTrue(t.get(0).equals(new Integer(1)));
- assertTrue(t.get(1).equals(new Integer(1)));
- assertTrue(t.get(2).equals(new Integer(1)));
- assertTrue(t.get(3).equals(new Integer(1)));
-
+ assertEquals(Integer.valueOf(1), t.get(0));
+ assertEquals(Integer.valueOf(1), t.get(1));
+ assertEquals(Integer.valueOf(1), t.get(2));
+ assertEquals(Integer.valueOf(1), t.get(3));
+
assertTrue(iter.hasNext());
t = iter.next();
- assertTrue(t.get(0).equals(new Integer(2)));
- assertTrue(t.get(1).equals(new Integer(2)));
- assertTrue(t.get(2).equals(new Integer(2)));
- assertTrue(t.get(3).equals(new Integer(2)));
-
- assertTrue(!iter.hasNext());
+ assertEquals(Integer.valueOf(2), t.get(0));
+ assertEquals(Integer.valueOf(2), t.get(1));
+ assertEquals(Integer.valueOf(2), t.get(2));
+ assertEquals(Integer.valueOf(2), t.get(3));
+
+ assertFalse(iter.hasNext());
fp1.delete();
}
-
-
+
static public class Pig800Udf extends EvalFunc<DataBag> {
-
+
@Override
public DataBag exec(Tuple input) throws IOException {
DataBag output = BagFactory.getInstance().newDefaultBag();
@@ -305,5 +306,4 @@ public class TestLocal2 extends TestCase
tmpFile.deleteOnExit();
return tmpFile;
}
-
}
Modified: pig/trunk/test/org/apache/pig/test/TestMapReduce2.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestMapReduce2.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestMapReduce2.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestMapReduce2.java Wed Nov 7 05:58:04 2012
@@ -18,8 +18,12 @@
package org.apache.pig.test;
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.Iterator;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
@@ -27,15 +31,8 @@ import org.apache.pig.data.Tuple;
import org.apache.pig.test.utils.TestHelper;
import org.junit.AfterClass;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import java.io.File;
-import java.io.IOException;
-import java.text.DecimalFormat;
-import java.util.Iterator;
-@RunWith(JUnit4.class)
-public class TestMapReduce2 extends TestCase {
+public class TestMapReduce2 {
static MiniCluster cluster = MiniCluster.buildCluster();
@@ -61,7 +58,7 @@ public class TestMapReduce2 extends Test
+ Util.generateURI(tmpFile2.toString(), pig.getPigContext())
+ "'; ");
pig.registerQuery("c = union a, b; ") ;
-
+
verifyUnion( "c", 30 + 50 );
}
@@ -129,7 +126,7 @@ public class TestMapReduce2 extends Test
count++ ;
}
- Assert.assertEquals(count, actualCount);
+ assertEquals(count, actualCount);
}
@@ -181,6 +178,4 @@ public class TestMapReduce2 extends Test
tmpFile.deleteOnExit();
return tmpFile;
}
-
-
-}
+}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestNewPlanColumnPrune.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestNewPlanColumnPrune.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestNewPlanColumnPrune.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestNewPlanColumnPrune.java Wed Nov 7 05:58:04 2012
@@ -18,6 +18,11 @@
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -25,8 +30,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import junit.framework.TestCase;
-
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.impl.PigContext;
@@ -41,264 +44,266 @@ import org.apache.pig.newplan.logical.ru
import org.apache.pig.newplan.logical.rules.MapKeysPruneHelper;
import org.apache.pig.newplan.optimizer.PlanOptimizer;
import org.apache.pig.newplan.optimizer.Rule;
+import org.junit.Test;
-public class TestNewPlanColumnPrune extends TestCase {
-
+public class TestNewPlanColumnPrune {
LogicalPlan plan = null;
PigContext pc = new PigContext(ExecType.LOCAL, new Properties());
-
+
private LogicalPlan buildPlan(String query) throws Exception{
PigServer pigServer = new PigServer( pc );
return Util.buildLp(pigServer, query);
}
-
-
+
+ @Test
public void testNoPrune() throws Exception {
// no foreach
String query = "a = load 'd.txt' as (id, v1, v2);" +
- "b = filter a by v1==NULL;" +
- "store b into 'empty';";
+ "b = filter a by v1==NULL;" +
+ "store b into 'empty';";
LogicalPlan newLogicalPlan = buildPlan(query);
-
+
PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a = load 'd.txt' as (id, v1, v2);" +
- "b = filter a by v1==NULL;" +
- "store b into 'empty';";
+ "b = filter a by v1==NULL;" +
+ "store b into 'empty';";
LogicalPlan expected = buildPlan(query);
-
+
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// no schema
query = "a = load 'd.txt';" +
"b = foreach a generate $0, $1;" +
- "store b into 'empty';";
+ "store b into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a = load 'd.txt';"+
"b = foreach a generate $0, $1;"+
- "store b into 'empty';";
+ "store b into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
}
-
+
+ @Test
public void testPrune() throws Exception {
// only foreach
String query = "a = load 'd.txt' as (id, v1, v2);" +
- "b = foreach a generate id;"+
- "store b into 'empty';";
+ "b = foreach a generate id;"+
+ "store b into 'empty';";
LogicalPlan newLogicalPlan = buildPlan(query);
-
+
PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a = load 'd.txt' as (id);" +
- "b = foreach a generate id;"+
- "store b into 'empty';";
+ "b = foreach a generate id;"+
+ "store b into 'empty';";
LogicalPlan expected = buildPlan(query);
-
+
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with filter
query = "a = load 'd.txt' as (id, v1, v5, v3, v4, v2);"+
"b = filter a by v1 != NULL AND (v2+v3)<100;"+
"c = foreach b generate id;"+
- "store c into 'empty';";
+ "store c into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a = load 'd.txt' as (id, v1, v3, v2);" +
"b = filter a by v1 != NULL AND (v2+v3)<100;" +
"c = foreach b generate id;" +
- "store c into 'empty';";
+ "store c into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with 2 foreach
query = "a = load 'd.txt' as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate v2, v5, v4;" +
"c = foreach b generate v5, v4;" +
- "store c into 'empty';";
+ "store c into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a = load 'd.txt' as (v5, v4);" +
"b = foreach a generate v5, v4;" +
"c = foreach b generate v5, v4;" +
- "store c into 'empty';";
+ "store c into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with 2 foreach
query = "a = load 'd.txt' as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate id, v1, v5, v3, v4;" +
"c = foreach b generate v5, v4;" +
- "store c into 'empty';";
+ "store c into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a = load 'd.txt' as (v5, v4);" +
"b = foreach a generate v5, v4;" +
"c = foreach b generate v5, v4;" +
- "store c into 'empty';";
+ "store c into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with 2 foreach and filter in between
query = "a =load 'd.txt' as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate v2, v5, v4;" +
"c = filter b by v2 != NULL;" +
"d = foreach c generate v5, v4;" +
- "store d into 'empty';";
+ "store d into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' as (v5, v4, v2);" +
"b = foreach a generate v2, v5, v4;" +
"c = filter b by v2 != NULL;" +
"d = foreach c generate v5, v4;" +
- "store d into 'empty';";
+ "store d into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with 2 foreach after join
query = "a =load 'd.txt' as (id, v1, v2, v3);" +
"b = load 'c.txt' as (id, v4, v5, v6);" +
- "c = join a by id, b by id;" +
+ "c = join a by id, b by id;" +
"d = foreach c generate a::id, v5, v3, v4;" +
- "store d into 'empty';";
+ "store d into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' as (id, v3);" +
"b = load 'c.txt' as (id, v4, v5);" +
- "c = join a by id, b by id;" +
+ "c = join a by id, b by id;" +
"d = foreach c generate a::id, v5, v3, v4;" +
- "store d into 'empty';";
+ "store d into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with BinStorage, insert foreach after load
- query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
+ query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
"c = filter a by v2 != NULL;" +
"d = foreach c generate v5, v4;" +
- "store d into 'empty';";
+ "store d into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate v5, v4, v2;" +
"c = filter b by v2 != NULL;" +
"d = foreach c generate v5, v4;" +
- "store d into 'empty';";
+ "store d into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with BinStorage, not to insert foreach after load if there is already one
- query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
+ query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate v5, v4, v2;" +
"c = filter b by v2 != NULL;" +
"d = foreach c generate v5;" +
- "store d into 'empty';";
+ "store d into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate v5, v2;" +
"c = filter b by v2 != NULL;" +
"d = foreach c generate v5;" +
- "store d into 'empty';";
+ "store d into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// with BinStorage, not to insert foreach after load if there is already one
- query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
+ query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate v5, v4, v2, 10;" +
"c = filter b by v2 != NULL;" +
"d = foreach c generate v5;" +
- "store d into 'empty';";
+ "store d into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);" +
"b = foreach a generate v5, v2, 10;" +
"c = filter b by v2 != NULL;" +
"d = foreach c generate v5;" +
- "store d into 'empty';";
+ "store d into 'empty';";
expected = buildPlan(query);
assertTrue(expected.isEqual(newLogicalPlan));
}
-
+
+ @Test
@SuppressWarnings("unchecked")
public void testPruneWithMapKey() throws Exception {
// only foreach
String query = "a =load 'd.txt' as (id, v1, m:map[]);" +
- "b = foreach a generate id, m#'path';" +
- "store b into 'empty';";
+ "b = foreach a generate id, m#'path';" +
+ "store b into 'empty';";
LogicalPlan newLogicalPlan = buildPlan(query);
-
+
PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' as (id, m:map[]);" +
- "b = foreach a generate id, m#'path';" +
- "store b into 'empty';";
+ "b = foreach a generate id, m#'path';" +
+ "store b into 'empty';";
LogicalPlan expected = buildPlan(query);
-
+
assertTrue(expected.isEqual(newLogicalPlan));
-
+
LOLoad op = (LOLoad)newLogicalPlan.getSources().get(0);
- Map<Integer,Set<String>> annotation =
+ Map<Integer,Set<String>> annotation =
(Map<Integer, Set<String>>) op.getAnnotation(MapKeysPruneHelper.REQUIRED_MAPKEYS);
- assertEquals(annotation.size(), 1);
+ assertEquals(1, annotation.size());
Set<String> s = new HashSet<String>();
s.add("path");
assertEquals(annotation.get(2), s);
-
+
// foreach with join
query = "a =load 'd.txt' as (id, v1, m:map[]);" +
"b = load 'd.txt' as (id, v1, m:map[]);" +
"c = join a by id, b by id;" +
"d = filter c by a::m#'path' != NULL;" +
- "e = foreach d generate a::id, b::id, b::m#'path', a::m;" +
- "store e into 'empty';";
+ "e = foreach d generate a::id, b::id, b::m#'path', a::m;" +
+ "store e into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' as (id, m:map[]);" +
"b = load 'd.txt' as (id, m:map[]);" +
"c = join a by id, b by id;" +
"d = filter c by a::m#'path' != NULL;" +
- "e = foreach d generate a::id, b::id, b::m#'path', a::m;" +
- "store e into 'empty';";
+ "e = foreach d generate a::id, b::id, b::m#'path', a::m;" +
+ "store e into 'empty';";
expected = buildPlan(query);
-
+
assertTrue(expected.isEqual(newLogicalPlan));
-
+
List<Operator> ll = newLogicalPlan.getSources();
- assertEquals(ll.size(), 2);
+ assertEquals(2, ll.size());
LOLoad loada = null;
LOLoad loadb = null;
for(Operator opp: ll) {
@@ -306,91 +311,94 @@ public class TestNewPlanColumnPrune exte
loada = (LOLoad)opp;
continue;
}
-
+
if (((LogicalRelationalOperator)opp).getAlias().equals("b")) {
loadb = (LOLoad)opp;
continue;
}
}
-
- annotation =
+
+ annotation =
(Map<Integer, Set<String>>) loada.getAnnotation(MapKeysPruneHelper.REQUIRED_MAPKEYS);
assertNull(annotation);
-
- annotation =
+
+ annotation =
(Map<Integer, Set<String>>) loadb.getAnnotation(MapKeysPruneHelper.REQUIRED_MAPKEYS);
assertEquals(annotation.size(), 1);
-
+
s = new HashSet<String>();
s.add("path");
assertEquals(annotation.get(2), s);
}
-
+
+ @Test
public void testPruneWithBag() throws Exception {
// filter above foreach
String query = "a =load 'd.txt' as (id, v:bag{t:(s1,s2,s3)});" +
"b = filter a by id>10;" +
- "c = foreach b generate id, FLATTEN(v);" +
- "d = foreach c generate id, v::s2;" +
- "store d into 'empty';";
+ "c = foreach b generate id, FLATTEN(v);" +
+ "d = foreach c generate id, v::s2;" +
+ "store d into 'empty';";
LogicalPlan newLogicalPlan = buildPlan(query);
-
+
PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' as (id, v:bag{t:(s1,s2,s3)});" +
"b = filter a by id>10;" +
- "c = foreach b generate id, FLATTEN(v);" +
- "d = foreach c generate id, v::s2;" +
+ "c = foreach b generate id, FLATTEN(v);" +
+ "d = foreach c generate id, v::s2;" +
"store d into 'empty';";
LogicalPlan expected = buildPlan(query);
-
+
assertTrue(expected.isEqual(newLogicalPlan));
}
-
+
+ @Test
public void testAddForeach() throws Exception {
// filter above foreach
- String query = "a =load 'd.txt' as (id, v1, v2);" +
+ String query = "a =load 'd.txt' as (id, v1, v2);" +
"b = filter a by v1>10;" +
- "c = foreach b generate id;" +
- "store c into 'empty';";
+ "c = foreach b generate id;" +
+ "store c into 'empty';";
LogicalPlan newLogicalPlan = buildPlan(query);
-
+
PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' as (id, v1);" +
- "b = filter a by v1>10;" +
- "c = foreach b generate id;" +
- "store c into 'empty';";
+ "b = filter a by v1>10;" +
+ "c = foreach b generate id;" +
+ "store c into 'empty';";
LogicalPlan expected = buildPlan(query);
-
+
assertTrue(expected.isEqual(newLogicalPlan));
-
+
// join with foreach
query = "a =load 'd.txt' as (id, v1, v2);" +
"b = load 'd.txt' as (id, v1, v2);" +
"c = join a by id, b by id;" +
"d = filter c by a::v1>b::v1;" +
- "e = foreach d generate a::id;" +
- "store e into 'empty';";
+ "e = foreach d generate a::id;" +
+ "store e into 'empty';";
newLogicalPlan = buildPlan(query);
-
+
optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
optimizer.optimize();
-
+
query = "a =load 'd.txt' as (id, v1);" +
"b = load 'd.txt' as (id, v1);" +
"c = join a by id, b by id;" +
- "d = foreach c generate a::id, a::v1, b::v1;" +
- "e = filter d by a::v1>b::v1;" +
- "f = foreach e generate a::id;" +
- "store f into 'empty';";
+ "d = foreach c generate a::id, a::v1, b::v1;" +
+ "e = filter d by a::v1>b::v1;" +
+ "f = foreach e generate a::id;" +
+ "store f into 'empty';";
expected = buildPlan(query);
-
+
assertTrue(expected.isEqual(newLogicalPlan));
}
+ @Test
public void testPruneSubTreeForEach() throws Exception {
String query = "a =load 'd.txt' as (id, v1);" +
"b = group a by id;" +
@@ -413,23 +421,23 @@ public class TestNewPlanColumnPrune exte
public class MyPlanOptimizer extends LogicalPlanOptimizer {
protected MyPlanOptimizer(OperatorPlan p, int iterations) {
- super(p, iterations, null);
+ super(p, iterations, null);
}
-
- protected List<Set<Rule>> buildRuleSets() {
+
+ protected List<Set<Rule>> buildRuleSets() {
List<Set<Rule>> ls = new ArrayList<Set<Rule>>();
-
+
Rule r = new ColumnMapKeyPrune("ColumnMapKeyPrune");
Set<Rule> s = new HashSet<Rule>();
- s.add(r);
+ s.add(r);
ls.add(s);
-
+
r = new AddForEach("AddForEach");
s = new HashSet<Rule>();
- s.add(r);
+ s.add(r);
ls.add(s);
-
+
return ls;
}
- }
+ }
}
Modified: pig/trunk/test/org/apache/pig/test/TestNewPlanListener.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestNewPlanListener.java?rev=1406469&r1=1406468&r2=1406469&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestNewPlanListener.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestNewPlanListener.java Wed Nov 7 05:58:04 2012
@@ -18,6 +18,10 @@
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.List;
import org.apache.pig.data.DataType;
@@ -38,23 +42,21 @@ import org.apache.pig.newplan.logical.op
import org.apache.pig.newplan.logical.optimizer.SchemaPatcher;
import org.apache.pig.newplan.logical.relational.LOFilter;
import org.apache.pig.newplan.logical.relational.LOJoin;
+import org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE;
import org.apache.pig.newplan.logical.relational.LOLoad;
import org.apache.pig.newplan.logical.relational.LogicalPlan;
import org.apache.pig.newplan.logical.relational.LogicalRelationalOperator;
import org.apache.pig.newplan.logical.relational.LogicalSchema;
-import org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE;
import org.apache.pig.newplan.logical.relational.LogicalSchema.LogicalFieldSchema;
import org.junit.Before;
import org.junit.Test;
-import junit.framework.TestCase;
-
/**
* Tests for PlanTransformListerns
*
*/
-public class TestNewPlanListener extends TestCase {
-
+public class TestNewPlanListener {
+
private LogicalPlan lp;
private LogicalPlan changedPlan;
@@ -62,9 +64,7 @@ public class TestNewPlanListener extends
* @see junit.framework.TestCase#setUp()
*/
@Before
- protected void setUp() throws Exception {
- super.setUp();
-
+ public void setUp() throws Exception {
// Build a plan that looks like it has just been transformed
// It is roughly the logical plan for
// A = load 'bla' as (x);
@@ -82,7 +82,7 @@ public class TestNewPlanListener extends
LOLoad A = new LOLoad(null, lp);
A.neverUseForRealSetSchema(aschema);
lp.add(A);
-
+
// B = load
LogicalSchema bschema = new LogicalSchema();
bschema.addField(new LogicalSchema.LogicalFieldSchema(
@@ -91,7 +91,7 @@ public class TestNewPlanListener extends
LOLoad B = new LOLoad(null, lp);
B.neverUseForRealSetSchema(bschema);
lp.add(B);
-
+
// C = join
LogicalSchema cschema = new LogicalSchema();
cschema.addField(new LogicalSchema.LogicalFieldSchema(
@@ -101,10 +101,10 @@ public class TestNewPlanListener extends
cschema.getField(0).uid = 1;
cschema.getField(1).uid = 2;
- MultiMap<Integer, LogicalExpressionPlan> mm =
+ MultiMap<Integer, LogicalExpressionPlan> mm =
new MultiMap<Integer, LogicalExpressionPlan>();
LOJoin C = new LOJoin(lp, mm, JOINTYPE.HASH, new boolean[] {true, true});
-
+
LogicalExpressionPlan aprojplan = new LogicalExpressionPlan();
ProjectExpression x = new ProjectExpression(aprojplan, 0, 0, C);
x.neverUseForRealSetFieldSchema(new LogicalFieldSchema(null, null,
@@ -115,10 +115,10 @@ public class TestNewPlanListener extends
DataType.INTEGER, 2));
mm.put(0, aprojplan);
mm.put(1, bprojplan);
-
+
C.neverUseForRealSetSchema(cschema);
// Don't add it to the plan quite yet
-
+
// D = filter
LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
LOFilter D = new LOFilter(lp, filterPlan);
@@ -127,43 +127,43 @@ public class TestNewPlanListener extends
DataType.INTEGER, 2));
ConstantExpression fc = new ConstantExpression(filterPlan, new Integer(0));
new EqualExpression(filterPlan, fy, fc);
-
+
D.neverUseForRealSetSchema(cschema);
// Connect D to B, since the transform has happened.
lp.add(D);
lp.connect(B, D);
-
+
// Now add in C, connected to A and D.
lp.add(C);
lp.connect(A, C);
lp.connect(D, C);
-
+
changedPlan = new LogicalPlan();
changedPlan.add(D);
changedPlan.add(C);
changedPlan.connect(D, C);
}
-
+
private static class SillySameVisitor extends AllSameRalationalNodesVisitor {
StringBuffer buf = new StringBuffer();
SillySameVisitor(OperatorPlan plan) throws FrontendException {
super(plan, new DepthFirstWalker(plan));
}
-
+
@Override
protected void execute(LogicalRelationalOperator op) throws FrontendException {
buf.append(op.getName());
buf.append(" ");
}
-
+
@Override
public String toString() {
return buf.toString();
}
-
+
}
-
+
// Test that the AllSameVisitor calls execute on every node
// in the plan.
@Test
@@ -172,9 +172,9 @@ public class TestNewPlanListener extends
v.visit();
assertTrue("LOLoad LOJoin(HASH) LOLoad LOFilter ".equals(v.toString()) ||
"LOLoad LOFilter LOJoin(HASH) LOLoad ".equals(v.toString()));
-
+
}
-
+
private static class SillyExpressionVisitor extends LogicalExpressionVisitor {
StringBuffer buf;
@@ -182,47 +182,47 @@ public class TestNewPlanListener extends
super(p, new DepthFirstWalker(p));
buf = b;
}
-
+
@Override
public void visit(AndExpression andExpr) throws FrontendException {
buf.append("and ");
}
-
+
@Override
public void visit(EqualExpression equal) throws FrontendException {
buf.append("equal ");
}
-
+
@Override
public void visit(ProjectExpression p) throws FrontendException {
buf.append("proj ");
}
-
+
@Override
public void visit(ConstantExpression c) throws FrontendException {
buf.append("const ");
}
}
-
+
private static class SillyAllExpressionVisitor extends AllExpressionVisitor {
StringBuffer buf = new StringBuffer();
public SillyAllExpressionVisitor(OperatorPlan plan) throws FrontendException {
super(plan, new DepthFirstWalker(plan));
}
-
+
@Override
protected LogicalExpressionVisitor getVisitor(LogicalExpressionPlan expr) throws FrontendException {
return new SillyExpressionVisitor(expr, buf);
- }
-
+ }
+
@Override
public String toString() {
return buf.toString();
}
}
-
+
// Test that the AllExpressionVisitor executes on every
// expression in the plan
@Test
@@ -232,13 +232,13 @@ public class TestNewPlanListener extends
assertTrue("proj proj equal proj const ".equals(v.toString()) ||
"equal proj const proj proj ".equals(v.toString()));
}
-
+
// Test that schemas are patched up after a transform
@Test
public void testSchemaPatcher() throws FrontendException {
SchemaPatcher patcher = new SchemaPatcher();
patcher.transformed(lp, changedPlan);
-
+
// Check that the filter now has the proper schema.
List<Operator> roots = changedPlan.getSources();
assertEquals(1, roots.size());
@@ -250,13 +250,13 @@ public class TestNewPlanListener extends
assertEquals("y", y.alias);
assertEquals(2, y.uid);
}
-
+
// Test that projections are patched up after a transform
@Test
public void testProjectionPatcher() throws FrontendException {
ProjectionPatcher patcher = new ProjectionPatcher();
patcher.transformed(lp, changedPlan);
-
+
// Check that the projections in filter are now set properly
List<Operator> roots = changedPlan.getSources();
assertEquals(1, roots.size());
@@ -277,5 +277,4 @@ public class TestNewPlanListener extends
assertEquals(0, proj.getColNum());
}
-}
-
+}
\ No newline at end of file