pig tutorial - apache pig tutorial - Apache Pig RTRIM() - pig latin - apache pig - pig hadoop



What is RTRIM()?

  • 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 wikitechy_emp_data relation as shown below.
grunt> Dump wikitechy_emp_data;
  
(001, Aadav ,32,Tokyo)
(002,Aadhi,33,Kolkata)
(003, Charu ,23, London)
(004,Daya,35,London)
(005, Hansa ,22,Bhuwaneshwar) 
(006, Hena ,21,Chennai)
(007,Robert,24, Bhuwaneshwar)
(008,Kali,20,Kolkata)
(009, Leena ,22, Chennai)
(010, Mahi ,22, newyork)
(011, Priya ,23, Tokyo)
(012,Rahul,20, newyork)
  • Using the RTRIM() function, we can remove the heading spaces from the names as shown below
grunt> rtrim_data = FOREACH wikitechy_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, Aadav ), Aadav) 
((2,Aadhi),Aadhi)
((3, Charu ), Charu) 
((4,Daya),Daya)
((5, Hansa ), Hansa) 
((6, Hena ), Hena) 
((7,Robert),Robert)
((8,Kali),Kali)
((9, Leena ), Leena) 
((10, Mahi ), Mahi) 
((11, Priya ), Priya) 
((12,Rahul),Rahul)

Related Searches to Apache Pig RTRIM()