// B = load 'morebla' as (y);
// C = join A on x, B on y;
// D = filter C by y > 0;
// A = load
LogicalPlan lp = new LogicalPlan();
{
LogicalSchema aschema = new LogicalSchema();
aschema.addField(new LogicalSchema.LogicalFieldSchema(
"x", null, DataType.INTEGER));
LOLoad A = new LOLoad(new FileSpec("/abc",
new FuncSpec("/fooload", new String[] {"x", "y"})), aschema, lp);
lp.add(A);
// B = load
LogicalSchema bschema = new LogicalSchema();
bschema.addField(new LogicalSchema.LogicalFieldSchema(
"y", null, DataType.INTEGER));
LOLoad B = new LOLoad(new FileSpec("/def",
new FuncSpec("PigStorage", "\t")), bschema, lp);
lp.add(B);
// C = join
LogicalSchema cschema = new LogicalSchema();
cschema.addField(new LogicalSchema.LogicalFieldSchema(
"x", null, DataType.INTEGER));
cschema.addField(new LogicalSchema.LogicalFieldSchema(
"y", null, DataType.INTEGER));
LogicalExpressionPlan aprojplan = new LogicalExpressionPlan();
new ProjectExpression(aprojplan, DataType.INTEGER, 0, 0);
LogicalExpressionPlan bprojplan = new LogicalExpressionPlan();
new ProjectExpression(bprojplan, DataType.INTEGER, 1, 0);
MultiMap<Integer, LogicalExpressionPlan> mm =
new MultiMap<Integer, LogicalExpressionPlan>();
mm.put(0, aprojplan);
mm.put(1, bprojplan);
LOJoin C = new LOJoin(lp, mm, JOINTYPE.HASH, new boolean[] {true, true});
C.neverUseForRealSetSchema(cschema);
lp.add(C);
lp.connect(A, C);
lp.connect(B, C);
// D = filter
LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
ProjectExpression fy = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 1);
ConstantExpression fc = new ConstantExpression(filterPlan, DataType.INTEGER, new Integer(0));
new EqualExpression(filterPlan, fy, fc);
LOFilter D = new LOFilter(lp, filterPlan);
D.neverUseForRealSetSchema(cschema);
lp.add(D);
lp.connect(C, D);
}
// Build a second similar plan to test equality
// A = load
LogicalPlan lp1 = new LogicalPlan();
{
LogicalSchema aschema = new LogicalSchema();
aschema.addField(new LogicalSchema.LogicalFieldSchema(
"x", null, DataType.INTEGER));
LOLoad A = new LOLoad(new FileSpec("/abc",
new FuncSpec("/fooload", new String[] {"x", "y"})), aschema, lp1);
lp1.add(A);
// B = load
LogicalSchema bschema = new LogicalSchema();
bschema.addField(new LogicalSchema.LogicalFieldSchema(
"y", null, DataType.INTEGER));
LOLoad B = new LOLoad(new FileSpec("/def",
new FuncSpec("PigStorage", "\t")), bschema, lp1);
lp1.add(B);
// C = join
LogicalSchema cschema = new LogicalSchema();
cschema.addField(new LogicalSchema.LogicalFieldSchema(
"x", null, DataType.INTEGER));
cschema.addField(new LogicalSchema.LogicalFieldSchema(
"y", null, DataType.INTEGER));
LogicalExpressionPlan aprojplan = new LogicalExpressionPlan();
new ProjectExpression(aprojplan, DataType.INTEGER, 0, 0);
LogicalExpressionPlan bprojplan = new LogicalExpressionPlan();
new ProjectExpression(bprojplan, DataType.INTEGER, 1, 0);
MultiMap<Integer, LogicalExpressionPlan> mm =
new MultiMap<Integer, LogicalExpressionPlan>();
mm.put(0, aprojplan);
mm.put(1, bprojplan);
LOJoin C = new LOJoin(lp1, mm, JOINTYPE.HASH, new boolean[] {true, true});
C.neverUseForRealSetSchema(cschema);
lp1.add(C);
lp1.connect(A, C);
lp1.connect(B, C);
// D = filter
LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
ProjectExpression fy = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 1);
ConstantExpression fc = new ConstantExpression(filterPlan, DataType.INTEGER, new Integer(0));
new EqualExpression(filterPlan, fy, fc);
LOFilter D = new LOFilter(lp1, filterPlan);
D.neverUseForRealSetSchema(cschema);
lp1.add(D);
lp1.connect(C, D);
}
assertTrue( lp.isEqual(lp1));
}