pigServer.registerQuery("C = cogroup A by ($1), B by ($1);");
pigServer.registerQuery("D = foreach C {B = order B by $0;generate FLATTEN(A), B.($1);};");
Iterator<Tuple> iter = pigServer.openIterator("D");
assertTrue(iter.hasNext());
Tuple t = iter.next();
assertTrue(t.size()==4);
assertTrue(t.get(0).toString().equals("1"));
assertTrue(t.get(1).toString().equals("2"));
assertTrue(t.get(2).toString().equals("3"));
assertTrue(t.get(3).toString().equals("{(2)}"));
assertTrue(iter.hasNext());
t = iter.next();
assertTrue(t.size()==4);
assertTrue(t.get(0).toString().equals("2"));
assertTrue(t.get(1).toString().equals("5"));
assertTrue(t.get(2).toString().equals("2"));
assertTrue(t.get(3).toString().equals("{}"));
assertFalse(iter.hasNext());
assertTrue(emptyLogFileMessage());
}