}
@Test
public void testQuery90() throws Exception {
LogicalPlan lp;
LOForEach foreach;
String query = "a = load 'myfile' as (name:Chararray, age:Int, gpa:Float);" +
"b = group a by (name, age);";
//the first and second elements in group, i.e., name and age are renamed as myname and myage
lp = buildPlan(query +
"c = foreach b generate flatten(group) as (myname, myage), COUNT(a) as mycount;" +
"store c into 'output';");
Operator store = lp.getSinks().get(0);
foreach = (LOForEach)lp.getPredecessors(store).get(0);
Assert.assertTrue(foreach.getSchema().isEqual(Utils.parseSchema("myname: chararray, age: int, mycount: long")));
//the schema of group is unchanged
lp = buildPlan( query +
"c = foreach b generate flatten(group), COUNT(a) as mycount;" +
"store c into 'output';" );
store = lp.getSinks().get(0);
foreach = (LOForEach)lp.getPredecessors(store).get(0);
Assert.assertTrue(foreach.getSchema().toString( false ).equals("group::name:chararray,group::age:int,mycount:long"));
//group is renamed as mygroup
lp = buildPlan(query +
"c = foreach b generate group as mygroup, COUNT(a) as mycount;" +
"store c into 'output';");
store = lp.getSinks().get(0);
foreach = (LOForEach)lp.getPredecessors(store).get(0);
Assert.assertTrue(foreach.getSchema().toString( false ).equals("mygroup:tuple(name:chararray,age:int),mycount:long"));
//group is renamed as mygroup and the elements are renamed as myname and myage
lp = buildPlan(query +
"c = foreach b generate group as mygroup:(myname, myage), COUNT(a) as mycount;" +
"store c into 'output';");
store = lp.getSinks().get(0);
foreach = (LOForEach)lp.getPredecessors(store).get(0);
Assert.assertTrue(foreach.getSchema().toString( false ).equals("mygroup:tuple(myname:chararray,myage:int),mycount:long"));
/*
//setting the schema of flattened bag that has no schema with the user defined schema
String q = "a = load 'myfile' as (name:Chararray, age:Int, gpa:Float);" +
"c = load 'another_file';" +
"d = cogroup a by $0, c by $0;";