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



What is UPPER() in pig?

  • This function is used to convert all the characters in a string to uppercase.
  • · The.upper() and.lower() string methods are self-explanatory. Performing the .upper() method on a string converts all of the characters to uppercase..

Syntax:

  • The syntax of the UPPER() function is as follows −
  grunt> UPPER(expression)

Example:

  • Assume that there is a file named wikitechy_emp.txt in the HDFS directory /pig_data/. This file contains the employee details such as id, name, age, and city.

wikitechy_emp.txt

001,Aadav,32,Tokyo
002,Aadhi,33,Kolkata
003,Charu,23, London
004,Daya,35,London 
005, Hansa,22,Bhuwaneshwar 
006, Hena,21,Chennai
007 ,Robert,24, Bhuwaneshwar
008,Kali,20,Kolkata
009,Leena,22, Chennai
010,Mahi,22, newyork
011,Priya,23, Tokyo
012,Rahul,20, newyork
012,Rahul,20, newyork
  • And, we have loaded this file into Pig with a relation named wikitechy_emp_data as shown below.
grunt> wikitechy_emp_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_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 wikitechy_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,Aadav),AADAV)
  • ((2,Aadhi),AADHI)
  • ((3,Charu),CHARU)
  • ((4,Daya),DAYA)
  • ((5,Hansa),HANSA)
  • ((6,Hena),HENA)
  • ((7,Robert),ROBERT)
  • ((8,Kali),KALI)
  • ((9,Leena),LEENA)
  • ((10,Mahi),MAHI)
  • ((11,Priya),PRIYA)
  • ((12,Rahul),RAHUL)

Related Searches to Apache Pig UPPER()