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




What is TOTUPLE() function in Apache Pig ?

  • The TOTUPLE() function is used convert one or more expressions to the data type tuple.

Syntax

grunt> TOTUPLE(expression [, expression ...])

Example

Ensure that we have a file named wikitechy_emp_details.txt in the HDFS directory /pig_data/, with the following content.

Wikitechy_emp_details.txt

111,Anu,22,newyork 
112,Bastin,23,Kolkata 
113,Cimen,23,Tokyo 
114,Darathy,25,London 
115,Enba,23,Bhuwaneshwar 
116,Favin,22,Chennai 

You have loaded this file into Pig with the relation name emp_data as given below.

grunt> emp_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_emp_details.txt' USING PigStorage(',')
   as (id:int, name:chararray, age:int, city:chararray);

Now convert the id, name and age of each student (record) into a tuple.

grunt> totuple = FOREACH emp_data GENERATE TOTUPLE (id,name,age);

Verification

Now you can verify the contents of the totuple schema using the Dump operator as given below.

grunt> DUMP totuple;
((111,Anu,22))
((112,Bastin,23)) 
((113,Cimen,23)) 
((114,Darathy,25)) 
((115,Enba,23)) 
((116,Favin,22)) 

Related Searches to Apache Pig - TOTUPLE()

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×