Installing Pig

To install Pig On RHEL-compatible systems:

$ sudo yum install pig

To install Pig on SLES systems:

$ sudo zypper install pig

To install Pig on Ubuntu and other Debian systems:

$ sudo apt-get install pig

To start Pig in interactive mode (YARN)

To start Pig, use the following command.

$ pig

To start Pig in interactive mode (MRv1)

Use the following command:

$ pig 
You should see output similar to the following:
2012-02-08 23:39:41,819 [main] INFO  org.apache.pig.Main - Logging error messages to: /home/user/pig-0.11.0-cdh5b1/bin/pig_1328773181817.log
2012-02-08 23:39:41,994 [main] INFO  org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: hdfs://hostname:8020


If you don't already have sample data, create a file and load it to HDFS. For example:
  1. Create the file hostlist and enter the following data:,123221991,120222101,119220077,218880024,234320024
  2. Load hostlist to a user directory in HDFS, in this case the user cloudera.
    $ hadoop fs -copyFromLocal hostlist /user/cloudera
At the Grunt shell, list the HDFS directory:
grunt> ls hdfs://hostname:8020/user/cloudera

To run a grep example job using Pig for grep inputs:
grunt> A = LOAD 'hostlist' AS (host:chararray, capacity:int);


grunt> B = FILTER A BY $0 MATCHES '.*best.*';
grunt> DUMP B;