- Apache Pig Tutorial
- Apache Pig - Home
- Apache Pig Introduction
- Apache Pig - Overview
- Apache Pig - Architecture
- Apache Pig Environment
- Apache Pig - Installation
- Apache Pig - Execution
- Apache Pig - Grunt Shell
- Pig Latin
- Pig Latin - Basics
- Load & Store Operators
- Apache Pig - Reading Data
- Apache Pig - Storing Data
- Diagnostic Operators
- Apache Pig - Diagnostic Operator
- Apache Pig - Describe Operator
- Apache Pig - Explain Operator
- Apache Pig - Illustrate Operator
- Grouping & Joining
- Apache Pig - Group Operator
- Apache Pig - Cogroup Operator
- Apache Pig - Join Operator
- Apache Pig - Cross Operator
- Combining & Splitting
- Apache Pig - Union Operator
- Apache Pig - Split Operator
- Pig Latin Built-In Functions
- Apache Pig - Eval Functions
- Load & Store Functions
- Apache Pig - Bag & Tuple Functions
- Apache Pig - String Functions
- Apache Pig - date-time Functions
- Apache Pig - Math Functions
- Other Modes Of Execution
- Apache Pig - User-Defined Functions
- Apache Pig - Running Scripts
- Apache Pig Useful Resources
- Apache Pig - Quick Guide
- Apache Pig - Useful Resources
- Apache Pig - Discussion
Apache Pig - LTRIM()
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