Apache Pig - UCFIRST()
This function accepts a string, converts the first letter of it into uppercase, and returns the result.
Syntax
Here is the syntax of the function UCFIRST() function.
grunt> UCFIRST(expression)
Example
Assume that there is a file named emp.txt in the HDFS directory /pig_data/ as shown below. 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);
Following is an example of the UCFIRST() function. In this example, we are trying to convert the first letters of the names of the cities, to which the employees belong to, to uppercase.
grunt> ucfirst_data = FOREACH emp_data GENERATE (id,city), UCFIRST(city);
The result of the statement will be stored in the relation named ucfirst_data. Verify the content of the relation ucfirst_data, using the Dump operator as shown below.
In our example, the first letter of the name of the city “newyork” is in lowercase. After applying UCFIRST() function, it turns into “NEWYORK”
grunt>Dump ucfirst_data; ((1,newyork),Newyork) ((2,Kolkata),Kolkata) ((3,Tokyo),Tokyo) ((4,London),London) ((5,Bhuwaneshwar),Bhuwaneshwar) ((6,Chennai),Chennai) ((7,newyork),Newyork) ((8,Kolkata),Kolkata) ((9,Tokyo),Tokyo) ((10,London),London) ((11,Bhuwaneshwar),Bhuwaneshwar) ((12,Chennai),Chennai)