}
@Test
public void testPigScriptrForBagToStringUDF() throws Exception {
PigServer pigServer = new PigServer(ExecType.LOCAL);
Data data = resetData(pigServer);
data.set("foo", "myBag:bag{t:(l:chararray)}",
tuple(bag(tuple("a"), tuple("b"), tuple("c"))));
pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage();");
pigServer.registerQuery("B = FOREACH A GENERATE BagToString(myBag) as myBag;");
pigServer.registerQuery("STORE B INTO 'bar' USING mock.Storage();");
pigServer.registerQuery("C = FOREACH A GENERATE BagToString(myBag, '==') as myBag;");
pigServer.registerQuery("STORE C INTO 'baz' USING mock.Storage();");
List<Tuple> out = data.get("bar");
assertEquals(schema("myBag:chararray"), data.getSchema("bar"));
assertEquals(tuple("a_b_c"), out.get(0));
out = data.get("baz");
assertEquals(tuple("a==b==c"), out.get(0));
}