pig tutorial - apache pig tutorial - How to Store pig result to local file ? - pig latin - apache pig - pig hadoop



How to Store Data

  • We can store the loaded data in the file system using the store operator. This explains how to store data in Apache Pig using the Store operator.

Syntax

  • The syntax of the Store statement.
STORE Relation_name INTO ' required_directory_path ' 

Example

  • Consider that we have a file student_data.txt in HDFS with the following content.
001,Rajiv,Reddy,9848022337,Hyderabad
002,siddarth,Battacharya,9848022338,Kolkata
003,Rajesh,Khanna,9848022339,Delhi
004,Preethi,Agarwal,9848022330,Pune
005,Trupthi,Mohanthy,9848022336,Bhuwaneshwar
006,Archana,Mishra,9848022335,Chennai.

  • And we have read it into a relation student using the LOAD operator as shown below.
grunt> student = LOAD 'hdfs://localhost:9000/pig_data/student_data.txt' 
   USING PigStorage(',')
   as ( id:int, firstname:chararray, lastname:chararray, phone:chararray, 
   city:chararray );

  • We can merging everything to a single file then we can use the copyToLocal command in grunt
grunt> copyToLocal <src> <dest>

Related Searches to How to Store pig result to local file