// See: https://issues.apache.org/jira/browse/PIG-3093
@Test
public void testIndirectSelfJoinRealias() throws Exception {
setUp(ExecType.LOCAL);
Data data = resetData(pigServer);
Set<Tuple> tuples = Sets.newHashSet(tuple("a"), tuple("b"), tuple("c"));
data.set("foo", Utils.getSchemaFromString("field1:chararray"), tuples);
pigServer.registerQuery("A = load 'foo' using mock.Storage();");
pigServer.registerQuery("B = foreach A generate *;");
pigServer.registerQuery("C = join A by field1, B by field1;");
assertEquals(Utils.getSchemaFromString("A::field1:chararray, B::field1:chararray"), pigServer.dumpSchema("C"));
pigServer.registerQuery("D = foreach C generate B::field1, A::field1 as field2;");
assertEquals(Utils.getSchemaFromString("B::field1:chararray, field2:chararray"), pigServer.dumpSchema("D"));
pigServer.registerQuery("E = foreach D generate field1, field2;");
assertEquals(Utils.getSchemaFromString("B::field1:chararray, field2:chararray"), pigServer.dumpSchema("E"));
pigServer.registerQuery("F = foreach E generate field2;");
pigServer.registerQuery("store F into 'foo_out' using mock.Storage();");
List<Tuple> out = data.get("foo_out");
assertEquals("Expected size was "+tuples.size()+" but was "+out.size(), tuples.size(), out.size());
for (Tuple t : out) {
assertTrue("Should have found tuple "+t+" in expected: "+tuples, tuples.remove(t));
}
assertTrue("All expected tuples should have been found, remaining: "+tuples, tuples.isEmpty());