[Solved-3 Solutions] Could not infer COUNT function in pig ?
What is Count() ?
- The COUNT() function of Pig Latin is used to get the number of elements in a bag. While counting the number of tuples in a bag, the COUNT() function ignores (will not count) the tuples having a NULL value in the FIRST FIELD
- We trying to write a pig latin script to pull the count of a dataset that we have filtered.
Syntax
- Given below is the syntax of the COUNT() function
Problem :
We are trying to write a pig latin script to pull the count of a dataset that we have filtered.
Here is the Script:
- For some reason, we get the error:
Could not infer the matching function for org.apache.pig.builtin.COUNT as multiple or none of them fit. Please use an explicit cast.
Solution 1:
- Group by all to bring everything into one bag, then count the item
- COUNT requires a preceding GROUP ALL statement for global counts and a GROUP BY statement for group counts.
Solution 2:
- We can use this below code to count function in pig
Solution 3:
Alternative way to solve: