Apache Pig - UPPER()
This function is used to convert all the characters in a string to uppercase.
Syntax
The syntax of the UPPER() function is as follows −
grunt> UPPER(expression)
Example
Assume that there is a file named emp.txt in the HDFS directory /pig_data/. This file contains the employee details such as id, name, age, and city.
emp.txt
001,Robin,22,newyork 002,BOB,23,Kolkata 003,Maya,23,Tokyo 004,Sara,25,London 005,David,23,Bhuwaneshwar 006,Maggy,22,Chennai 007,Robert,22,newyork 008,Syam,23,Kolkata 009,Mary,25,Tokyo 010,Saran,25,London 011,Stacy,25,Bhuwaneshwar 012,Kelly,22,Chennai
And, we have loaded this file into Pig with a relation named emp_data as shown below.
grunt> emp_data = LOAD 'hdfs://localhost:9000/pig_data/emp.txt' USING PigStorage(',') as (id:int, name:chararray, age:int, city:chararray);
Given below is an example of the UPPER() function. In this example, we have converted the names of all the employees to upper case.
grunt> upper_data = FOREACH emp_data GENERATE (id,name), UPPER(name);
The above statement converts the names of all the employees to uppercase and returns the result.
The result of the statement will be stored in a relation named upper_data. Verify the content of the relation upper_data, using the Dump operator as shown below.
grunt> Dump upper_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)