Apache Pig - RTRIM()


Advertisements

The function RTRIM() is same as the function TRIM(). It removes the unwanted spaces from the right side of a given string (tailing spaces).

Syntax

The syntax of the RTRIM() function is as follows −

grunt> RTRIM(expression)

Example

Assume we have some unwanted spaces before and after the names of the employees in the records of the emp_data relation as shown below.

grunt> Dump emp_data;
  
(1, Robin ,22,newyork)
(2, BOB,23,Kolkata)
(3, Maya ,23,Tokyo)
(4, Sara,25,London)
(5, David ,23,Bhuwaneshwar)
(6, maggy,22,Chennai)
(7, Robert,22,newyork)
(8, Syam ,23,Kolkata)
(9, Mary,25,Tokyo)
(10, Saran ,25,London)
(11, Stacy,25,Bhuwaneshwar)
(12, Kelly ,22,Chennai)

Using the RTRIM() function, we can remove the heading spaces from the names as shown below

grunt> rtrim_data = FOREACH emp_data GENERATE (id,name), RTRIM(name);

The above statement returns the copy of the names by removing the tailing spaces from the names of the employees. The result is stored in the relation named rtrim_data. Verify the result of the relation rtrim_data using the Dump operator as shown below.

grunt> Dump rtrim_data;
  
((1, Robin ), Robin)
((2,BOB),BOB)
((3, Maya ), Maya)
((4,Sara),Sara)
((5, David ), David)
((6,maggy),maggy)
((7,Robert),Robert)
((8, Syam ), Syam)
((9,Mary),Mary)
((10, Saran ), Saran)
((11, Stacy), Stacy)
((12, Kelly ), Kelly)
apache_pig_string_functions.htm
Advertisements