[Solved-2 Solutions] How to calculate the length of a string in Apache Pig ?



Problem :

How to calculate the length of a string in Apache Pig ?

Solution 1:

  • Length of the string in apache can be calculated by using the SIZE operator.

Size ()

  • The SIZE() function of Pig Latin is used to compute the number of elements based on any Pig data type.

Syntax

  • The syntax of the SIZE() function.
grunt> SIZE(expression)
  • The return values vary according to the data types in Apache Pig.
Data type Value
int, long, float, double For all these types, the size function returns 1.
Char array For a char array, the size() function returns the number of characters in the array.
Byte array For a bytearray, the size() function returns the number of bytes in the array.
Tuple For a tuple, the size() function returns number of fields in the tuple.
Bag For a bag, the size() function returns number of tuples in the bag.
Map For a map, the size() function returns the number of key/value pairs in the map.

Solution 2:

SUBSTRING(division,4,(int)SIZE(division))

Note that int cast.


Related Searches to How to calculate the length of a string in Apache Pig?