Running Pig Scripts in Zeppelin

This section contains a sample of an Apache Pig script that you can run in your Apache Zeppelin notebook.

About this task

This example reads the contents of your password file and outputs the first field in the file: the user name.

Procedure

  1. Using the shell interpreter, copy the password file to the MapR File System:

    To use POSIX shell commands like cp, you must have a MapR File System mount point in your container. The example below assumes your mount point is /mapr and your cluster name is my.cluster.com:

    %sh
    cp /etc/passwd /mapr/my.cluster.com/user/mapruser1
    %sh
    hadoop fs -put /etc/passwd /user/mapruser1/
  2. Load the password file in Pig and output the first field in each line in the file:
    %pig
    A = load 'passwd' using PigStorage(':');  
    B = foreach A generate $0 as id;  
    dump B;

What to do next

There are other examples of using Pig in the Zeppelin tutorial, including running Pig queries.