Apache Pig Writing/Storing Data

Let’s study about the Apache Pig Writing/Storing Data.

In the article will study how to store the loaded data into the pig using Store operator.

Example

Let’s assume that employee.txt data is loaded into the HDFS with the following content.

100,Roshan,23,HR

101,Roy,27,CS

102,Shruthi,31,IT

103,Disha,28,EC

104,Gowri,30,HR

1. Start the Pig Grunt Shell

In this stage start the Pig terminal using below command.

$ Pig

grunt>

2. Storing data

In this stage we are storing the loaded data to the HDFS directory using store operator.

/* loading data*/

grunt> empdata = LOAD ‘hdfs://localhost:9000/emp_pigdata/employee.txt’  USING   PigStorage(‘,’);

/* storing data*/

grunt> STORE empdata INTO ‘ hdfs://localhost:9000/pig_Output/ ‘ USING PigStorage (‘,’);

3. Verification

In this stage we are verifying the stored result data in HDFS using cat command.

$hdfs dfs -ls ‘hdfs://localhost:9000/pig_Output/’

$ hdfs dfs -cat ‘hdfs://localhost:9000/pig_Output/part-m-00000’