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

What is TRIM()?

  • The TRIM() function accepts a string and returns its copy after removing the unwanted spaces before and after it.
 Apache Pig Trim

Learn Apache Pig - Apache Pig tutorial - Apache Pig Trim - Apache Pig examples - Apache Pig programs


  • Here is the syntax of the TRIM() function .
grunt> TRIM(expression)


  • Assume we have some unwanted spaces before and after the names of the employees in the records of the wikitechy_emp_data relation.
grunt> Dump emp_data; 
(001, Aadav ,32,Tokyo)
(003, Charu ,23, London)
(005, Hansa ,22,Bhuwaneshwar) 
(006, Hena ,21,Chennai)
(007,Robert,24, Bhuwaneshwar)
(009, Leena ,22, Chennai)
(010, Mahi ,22, newyork)
(011, Priya ,23, Tokyo)
(012,Rahul,20, newyork)
  • Using the TRIM() function, we can remove these heading and tailing spaces from the names, as shown below.
grunt> trim_data = FOREACH wikitechy_emp_data GENERATE (id,name), TRIM(name);
  • The above statement returns the copy of the names by removing the heading and tailing spaces from the names of the employees.
  • The result is stored in the relation named trim_data .
  • Verify the result of the relation trim_data using the Dump operator as shown below.
grunt> Dump trim_data;

Related Searches to Apache Pig TRIM()

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.