[Solved-2 Solutions] Flatten tuple like a bag in pig ?
- flatten can also be applied to a tuple. In this case, it does not produce a cross product; instead, it elevates each field in the tuple to a top-level field. Again, empty tuples will remove the entire record. If the fields in a bag or tuple that is being flattened have names, Pig will carry those names along.
- Dataset looks like the following:
- We would like to "flatten" the tuples in Pig, basically repeating each record for each value found in the inner-tuple, such that the expected output is:
We know this is possible when the tuples (1,2) and (2,9) are bags instead.
Initially, we used STRSPLIT that generates a tuple resulting in the similar input as above but was unsuccessful.
- We can also use tokenize and that’s produces the desired result
- The TOBAG() function of Pig Latin converts one or more expressions to individual tuples. And these tuples are placed in a bag.
- Given below is the syntax of the TOBAG() function.
Here is the solution that use the TOBAG operator ?