Search code examples
apache-pig

How to create multiple tuples from single tuple in pig?


I have column like '5060-5070' in pig and I want to write a udf to return tuples as below:

col1 and col2 will be same in all the tuples.

col1,col2,5060,....

col1,col2,5061,..

col1,col2,5062,..

or if there is any alternative (instead of using udf) to create multiple tuples from single tuple .


Solution

  • Your should create a UDF that returns Databag. Databag can contain any number of tuples. Then use flatten to expand this databag. Use BagFactory to create DataBag, use TupleFactory to create a tuple and add it inside it.