Case Conversion in Apache Pig

Apache Pig provides few functions that SQL developers are familiar with. The behavior in much of the functions is the same. Such functions help to interpret, translate, quantify and format data.

The aim of this post is to let you know the functions that help view data in various character cases, such as Uppercase and Lowercase.

Syntax:
UPPER(expression)
It returns a string converted to upper case.

LOWER(expression)
It returns a string converted to lower case.

Examples:
grunt> emp = LOAD ‘Desktop/Docs/emp.csv’ USING PigStorage(‘,’) as (empno:int,ename:chararray,job:chararray,mgr:int,hiredate:chararray,sal:double,comm:double,deptno:int);

grunt> empcaps = FOREACH emp GENERATE empno, UPPER (ename);
grunt> emplowcase = FOREACH emp GENERATE empno, LOWER (ename);

grunt> dump empcaps;
grunt> dump emplowcase;

Lower_in_Apache_Pig_1Lower_in_Apache_Pig_2Upper_in_Apache_Pig_1Upper_in_Apache_Pig_2

Hope you find this article helpful.

Please subscribe for more interesting updates.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s