[Solved-2 Solutions] In pig, Check if an element is present in a bag ?
Problem:
How to check in piglatin, if a bag contains an element ?
Solution 1:
Use foreach
- The FOREACH operator is used to generate specified data transformations based on the column data.
Syntax
- The syntax of FOREACH operator.
- In Apache Pig we can use statements nested in FOREACH . Here is example: A is a bag in B.
- Instead of COUNT we can also use IsEmpty and ?: operator
Solution 2:
This is one of the way to do it without any custom udf code is :
- Assume A has schema my_bag:{(f1, f2, f3)};