[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.
- Given below is the syntax of the COUNT() function
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.
- 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.
- We can use this below code to count function in pig
Alternative way to solve: