Apache Pig - LTRIM()


Advertisements

The function LTRIM() is same as the function TRIM(). It removes the unwanted spaces from the left side of the given string (heading spaces).

Syntax

Here is the syntax of the LTRIM() function.

grunt> LTRIM(expression)

Example

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

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 LTRIM() function, we can remove the heading spaces from the names as shown below.

grunt> ltrim_data = FOREACH emp_data GENERATE (id,name), LTRIM(name);

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

grunt> Dump ltrim_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