assertTrue(schema.isEqual(aschema));
}
public void testForeachSchema() throws Exception {
// test flatten
LogicalPlanTester lpt = new LogicalPlanTester(pc);
lpt.buildPlan("a = load '/test/d.txt' as (id, d:tuple(v, s));");
LogicalPlan plan = lpt.buildPlan("b = foreach a generate id, FLATTEN(d);");
org.apache.pig.newplan.logical.relational.LogicalPlan newPlan = migratePlan(plan);
LogicalRelationalOperator op = (LogicalRelationalOperator)newPlan.getSinks().get(0);
LogicalSchema s2 = new LogicalSchema();
s2.addField(new LogicalSchema.LogicalFieldSchema("id", null, DataType.BYTEARRAY));
s2.addField(new LogicalSchema.LogicalFieldSchema("v", null, DataType.BYTEARRAY));
s2.addField(new LogicalSchema.LogicalFieldSchema("s", null, DataType.BYTEARRAY));
assertTrue(s2.isEqual(op.getSchema()));
// test no flatten
lpt = new LogicalPlanTester(pc);
lpt.buildPlan("a = load '/test/d.txt' as (id, d:bag{t:(v, s)});");
plan = lpt.buildPlan("b = foreach a generate id, d;");
newPlan = migratePlan(plan);
op = (LogicalRelationalOperator)newPlan.getSinks().get(0);
LogicalSchema aschema = new LogicalSchema();
aschema.addField(new LogicalSchema.LogicalFieldSchema("id", null, DataType.BYTEARRAY));
LogicalSchema aschema2 = new LogicalSchema();
LogicalSchema aschema3 = new LogicalSchema();
aschema3.addField(new LogicalSchema.LogicalFieldSchema("v", null, DataType.BYTEARRAY));
aschema3.addField(new LogicalSchema.LogicalFieldSchema("s", null, DataType.BYTEARRAY));
aschema2.addField(new LogicalSchema.LogicalFieldSchema("t", aschema3, DataType.TUPLE));
aschema.addField(new LogicalSchema.LogicalFieldSchema("d", aschema2, DataType.BAG));
assertTrue(aschema.isEqual(op.getSchema()));
// check with defined data type
lpt = new LogicalPlanTester(pc);
lpt.buildPlan("a = load '/test/d.txt' as (id, d:bag{t:(v:int, s)});");
lpt.buildPlan("b = foreach a generate id, FLATTEN(d);");
plan = lpt.buildPlan("store b into '/test/empty';");
newPlan = migratePlan(plan);
op = (LogicalRelationalOperator)newPlan.getSinks().get(0);
op = (LogicalRelationalOperator)newPlan.getPredecessors(op).get(0);
LogicalSchema schema = op.getSchema();
aschema = new LogicalSchema();
aschema.addField(new LogicalSchema.LogicalFieldSchema("id", null, DataType.BYTEARRAY));
aschema.addField(new LogicalSchema.LogicalFieldSchema("v", null, DataType.INTEGER));
aschema.addField(new LogicalSchema.LogicalFieldSchema("s", null, DataType.BYTEARRAY));
assertTrue(schema.isEqual(aschema));
// test with add
lpt = new LogicalPlanTester(pc);
lpt.buildPlan("a = load '/test/d.txt' as (id, v:int, s:int);");
lpt.buildPlan("b = foreach a generate id, v+s;");
plan = lpt.buildPlan("store b into '/test/empty';");
newPlan = migratePlan(plan);
op = (LogicalRelationalOperator)newPlan.getSinks().get(0);
op = (LogicalRelationalOperator)newPlan.getPredecessors(op).get(0);
schema = op.getSchema();