planTester.buildPlan("a = load 'file1' using PigStorage(':') as (name:chararray, marks:int);");
planTester.buildPlan("b = load 'file2' using PigStorage(':') as (name:chararray, rank:chararray);");
planTester.buildPlan("c = cogroup a by name, b by name;");
planTester.buildPlan("d = foreach c generate group, FLATTEN(a.marks) as newmarks;");
planTester.buildPlan("e = cogroup a by marks, d by newmarks;");
LogicalPlan plan = planTester.buildPlan("f = foreach e generate group, flatten(a), flatten(d);");
// Set the logical plan values correctly in all the operators
PlanSetter ps = new PlanSetter(plan);
ps.visit();
// run through validator
CompilationMessageCollector collector = new CompilationMessageCollector() ;
TypeCheckingValidator typeValidator = new TypeCheckingValidator() ;
typeValidator.validate(plan, collector) ;
printMessageCollector(collector) ;
printTypeGraph(plan) ;
if (collector.hasError()) {
throw new Exception("Error during type checking") ;
}
// this will run ImplicitSplitInserter
TestLogicalOptimizer.optimizePlan(plan);
// get Schema of leaf and compare:
Schema expectedSchema = Util.getSchemaFromString("grp: int,A::username: chararray,A::marks: int,AB::group: chararray,AB::newmarks: int");
assertTrue(Schema.equals(expectedSchema, plan.getLeaves().get(0).getSchema(),false, true));
}