- 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 - 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 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