// D = filter
LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
LOFilter D = new LOFilter(lp, filterPlan);
ProjectExpression fx = new ProjectExpression(filterPlan, 0, 0, D);
ConstantExpression fc0 = new ConstantExpression(filterPlan, new Integer(0));
EqualExpression eq1 = new EqualExpression(filterPlan, fx, fc0);
ProjectExpression fanotherx = new ProjectExpression(filterPlan, 0, 0, D);
ProjectExpression fa = new ProjectExpression(filterPlan, 0, 2, D);
EqualExpression eq2 = new EqualExpression(filterPlan, fanotherx, fa);
AndExpression and1 = new AndExpression(filterPlan, eq1, eq2);
ProjectExpression fb = new ProjectExpression(filterPlan, 0, 3, D);
ConstantExpression fc1 = new ConstantExpression(filterPlan, new Integer(1));
EqualExpression eq3 = new EqualExpression(filterPlan, fb, fc1);
AndExpression and2 = new AndExpression(filterPlan, and1, eq3);
ProjectExpression fanotherb = new ProjectExpression(filterPlan, 0, 3, D);
ProjectExpression fy = new ProjectExpression(filterPlan, 0, 1, D);
EqualExpression eq4 = new EqualExpression(filterPlan, fy, fanotherb);
new AndExpression(filterPlan, and2, eq4);
D.setAlias("D");
// Connect D to B, since the transform has happened.
lp.add(D);
lp.connect(C, D);
}
System.out.println(lp);
LogicalPlanOptimizer optimizer = new LogicalPlanOptimizer(lp, 500, null);
optimizer.optimize();
LogicalPlan expected = new LogicalPlan();
{
// A = load
LogicalSchema aschema = new LogicalSchema();
aschema.addField(new LogicalSchema.LogicalFieldSchema(
"x", null, DataType.BYTEARRAY));
aschema.addField(new LogicalSchema.LogicalFieldSchema(
"y", null, DataType.BYTEARRAY));
LOLoad A = newLOLoad(new FileSpec("bla", new FuncSpec("PigStorage", "\t")), aschema, expected, conf);
expected.add(A);
// DA = filter
LogicalExpressionPlan DAfilterPlan = new LogicalExpressionPlan();
LOFilter DA = new LOFilter(expected, DAfilterPlan);
ProjectExpression fx = new ProjectExpression(DAfilterPlan, 0, 0, DA);
fx.neverUseForRealSetFieldSchema(new LogicalFieldSchema(null, null, DataType.BYTEARRAY));
ConstantExpression fc0 = new ConstantExpression(DAfilterPlan, new Integer(0));
new EqualExpression(DAfilterPlan, fx, fc0);
DA.neverUseForRealSetSchema(aschema);
expected.add(DA);
expected.connect(A, DA);
// A = foreach
LOForEach foreachA = org.apache.pig.newplan.logical.Util.addForEachAfter(expected, DA, 0, new HashSet<Integer>());
foreachA.setAlias("A");
foreachA.neverUseForRealSetSchema(aschema);
// B = load
LogicalSchema bschema = new LogicalSchema();
bschema.addField(new LogicalSchema.LogicalFieldSchema(
"a", null, DataType.BYTEARRAY));
bschema.addField(new LogicalSchema.LogicalFieldSchema(
"b", null, DataType.BYTEARRAY));
LOLoad B = newLOLoad(new FileSpec("morebla", new FuncSpec("PigStorage", "\t")), bschema, expected, conf);
expected.add(B);
// DB = filter
LogicalExpressionPlan DBfilterPlan = new LogicalExpressionPlan();
LOFilter DB = new LOFilter(expected, DBfilterPlan);
ProjectExpression fb = new ProjectExpression(DBfilterPlan, 0, 1, DB);
fb.neverUseForRealSetFieldSchema(new LogicalFieldSchema(null, null, DataType.BYTEARRAY));
ConstantExpression fc1 = new ConstantExpression(DBfilterPlan, new Integer(1));
new EqualExpression(DBfilterPlan, fb, fc1);
DB.neverUseForRealSetSchema(bschema);
expected.add(DB);
expected.connect(B, DB);