Friday, April 29, 2016

Apache Pig Installation on Linux

Apache Pig Installation with Hadoop on Linux


Step 1: Install JAVA and Hadoop

Apache Hive required java 6 or later version. We also need to install hadoop first before installing apache hive on our system. Use below links to install them.

Check Java installation on your machine

# java -version 

java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

If you don’t have Java installed on your system, use below link to install the java.
https://www.java.com/en/download/help/linux_x64_install.xml

Step 2: Download Pig 

After configuring hadoop successfully on your linux system. lets start hive setup. First download latest hive source code and extract archive using following commands.
$ wget http://apache.claz.org/pig/pig-0.15.0/pig-0.15.0.tar.gz 
$ tar -xvf pig-0.15.0.tar.gz
$ mv pig-0.15.0 pig

Step 3: Setup Environment Variables

After extracting hive archive file, switch to hadoop user and setup following environment variables.
$ export PIG_HOME=/scratch/vchennar/hadoop/pig

$  export PATH=$PATH:$PIG_HOME/bin

Step 4: Start Pig

Try the following command, to get a list of Pig commands:

$ pig -help 
Try the following command, to start the Grunt shell:
$ pig  

Run Modes

Pig has two run modes or exectypes:
  • Local Mode - To run Pig in local mode, you need access to a single machine.
  • Mapreduce Mode - To run Pig in mapreduce mode, you need access to a Hadoop cluster and HDFS installation. Pig will automatically allocate and deallocate a 15-node cluster.
You can run the Grunt shell, Pig scripts, or embedded programs using either mode.

Grunt Shell

Use Pig's interactive shell, Grunt, to enter pig commands manually. See the Sample Code for instructions about the passwd file used in the example.
You can also run or execute script files from the Grunt shell. See the run and exec commands.
Local Mode
$ pig -x local
Mapreduce Mode
$ pig
or
$ pig -x mapreduce

For either mode, the Grunt shell is invoked and you can enter commands at the prompt. The results are displayed to your terminal screen (if DUMP is used) or to a file (if STORE is used).

grunt> A = load 'passwd' using PigStorage(':'); 
grunt> B = foreach A generate $0 as id; 
grunt> dump B; 
grunt> store B; 

Refer Apache Pig Documentation for further details : https://pig.apache.org/docs/r0.7.0/setup.html


No comments:

Post a Comment