此文章是vip文章,如何查看?  

1,点击链接获取密钥 http://nicethemes.cn/product/view29882.html

2,在下方输入文章查看密钥即可立即查看当前vip文章


Pig 0.12.1安装和使用

  • 时间:
  • 浏览:
  • 来源:互联网

1 :安装

解压,配置环境变量,验证 pig安装是否成功

<pre name="code" class="plain">[jifeng@jifeng02 ~]$ tar zxf pig-0.12.0.tar.gz 
[jifeng@jifeng02 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export JAVA_HOME=$HOME/jdk1.7.0_45
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=$HOME/hadoop/hadoop-1.2.1
export ANT_HOME=$HOME/apache-ant-1.9.4

export HIVE_HOME=$HOME/hadoop/hive-0.12.0-bin
export HBASE_HOME=$HOME/hbase-0.94.21
export PIG_HOME=$HOME/pig-0.12.1

export PATH=$PATH:$ANT_HOME/bin:$HIVE_HOME/bin::$HBASE_HOME/bin:$PIG_HOME/bin
~
~
~
".bash_profile" 23L, 591C 已写入                                                                                  
[jifeng@jifeng02 ~]$ source .bash_profile

[jifeng@jifeng02 ~]$ pig -helpwhich: no hadoop in (/home/jifeng/jdk1.7.0_45/bin:/home/jifeng/jdk1.7.0_45/bin:/home/jifeng/jdk1.7.0_45/bin:/usr/lib/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jifeng/bin:/home/jifeng/apache-ant-1.9.4/bin:/home/jifeng/hadoop/hive-0.12.0-bin/bin::/home/jifeng/hbase-0.94.21/bin:/home/jifeng/bin:/home/jifeng/apache-ant-1.9.4/bin:/home/jifeng/hadoop/hive-0.12.0-bin/bin::/home/jifeng/hbase-0.94.21/bin:/home/jifeng/pig-0.12.1/bin:/home/jifeng/bin:/home/jifeng/apache-ant-1.9.4/bin:/home/jifeng/hadoop/hive-0.12.0-bin/bin::/home/jifeng/hbase-0.94.21/bin:/home/jifeng/pig-0.12.0/bin)Warning: $HADOOP_HOME is deprecated.Apache Pig version 0.12.0 (r1529718) compiled Oct 07 2013, 12:20:14


2.Pig执行模式
Pig有两种执行模式,分别为:
1)本地模式(Local)
本地模式下,Pig运行在单一的JVM中,可访问本地文件。该模式适用于处理小规模数据或学习之用。
运行以下命名设置为本地模式:
[jifeng@jifeng02 ~]$ pig -x local
which: no hadoop in (/home/jifeng/jdk1.7.0_45/bin:/home/jifeng/jdk1.7.0_45/bin:/home/jifeng/jdk1.7.0_45/bin:/usr/lib/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jifeng/bin:/home/jifeng/apache-ant-1.9.4/bin:/home/jifeng/hadoop/hive-0.12.0-bin/bin::/home/jifeng/hbase-0.94.21/bin:/home/jifeng/bin:/home/jifeng/apache-ant-1.9.4/bin:/home/jifeng/hadoop/hive-0.12.0-bin/bin::/home/jifeng/hbase-0.94.21/bin:/home/jifeng/pig-0.12.1/bin:/home/jifeng/bin:/home/jifeng/apache-ant-1.9.4/bin:/home/jifeng/hadoop/hive-0.12.0-bin/bin::/home/jifeng/hbase-0.94.21/bin:/home/jifeng/pig-0.12.0/bin)
Warning: $HADOOP_HOME is deprecated.

2015-08-16 22:57:09,716 [main] INFO  org.apache.pig.Main - Apache Pig version 0.12.0 (r1529718) compiled Oct 07 2013, 12:20:14
2015-08-16 22:57:09,717 [main] INFO  org.apache.pig.Main - Logging error messages to: /home/jifeng/pig_1439737029715.log
2015-08-16 22:57:09,735 [main] INFO  org.apache.pig.impl.util.Utils - Default bootup file /home/jifeng/.pigbootup not found
2015-08-16 22:57:09,828 [main] INFO  org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: file:///
grunt> 

2)MapReduce模式
在MapReduce模式下,Pig将查询转换为MapReduce作业提交给Hadoop(可以说群集 ,也可以说伪分布式)。
应该检查当前Pig版本是否支持你当前所用的Hadoop版本。某一版本的Pig仅支持特定版本的Hadoop,你可以通过访问Pig官网获取版本支持信息。
Pig会用到HADOOP_HOME环境变量。如果该变量没有设置,Pig也可以利用自带的Hadoop库,但是这样就无法保证其自带肯定库和你实际使用的HADOOP版本是否兼容,所以建议显式设置HADOOP_HOME变量。且还需要设置PIG_CLASSPATH变量:

[jifeng@jifeng02 ~]$ vi .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export JAVA_HOME=$HOME/jdk1.7.0_45
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=$HOME/hadoop/hadoop-1.2.1
export ANT_HOME=$HOME/apache-ant-1.9.4

export HIVE_HOME=$HOME/hadoop/hive-0.12.0-bin
export HBASE_HOME=$HOME/hbase-0.94.21
export PIG_HOME=$HOME/pig-0.12.0
export PIG_CLASSPATH=$HOME/hadoop/hadoop-1.2.1/conf/

export PATH=$PATH:$ANT_HOME/bin:$HIVE_HOME/bin::$HBASE_HOME/bin:$PIG_HOME/bin:$HADOOP_HOME/bin
~
~
~
".bash_profile" 24L, 661C 已写入                                                                                  
[jifeng@jifeng02 ~]$ source .bash_profile
[jifeng@jifeng02 ~]$ pig
Warning: $HADOOP_HOME is deprecated.

2015-08-16 23:06:24,122 [main] INFO  org.apache.pig.Main - Apache Pig version 0.12.0 (r1529718) compiled Oct 07 2013, 12:20:14
2015-08-16 23:06:24,123 [main] INFO  org.apache.pig.Main - Logging error messages to: /home/jifeng/pig_1439737584121.log
2015-08-16 23:06:24,142 [main] INFO  org.apache.pig.impl.util.Utils - Default bootup file /home/jifeng/.pigbootup not found
2015-08-16 23:06:24,281 [main] INFO  org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: hdfs://jifeng01:9000
2015-08-16 23:06:24,463 [main] INFO  org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to map-reduce job tracker at: jifeng01:9001
grunt> 

3.运行Pig程序
Pig程序执行方式有三种:
1)脚本方式
直接运行包含Pig脚本的文件,比如以下命令将运行本地scripts.pig文件中的所有命令:
pig scripts.pig
2)Grunt方式
Grunt提供了交互式运行环境,可以在命令行编辑执行命令。
Grund同时支持命令的历史记录,通过上下方向键访问。
Grund支持命令的自动补全功能。比如当你输入a = foreach b g时,按下Tab键,则命令行自动变成a = foreach b generate。你甚至可以自定义命令自动补全功能的详细方式。具体请参阅相关文档。
3)嵌入式方式
可以在java中运行Pig程序,类似于使用JDBC运行SQL程序。
Pig Latin编辑器
PigPen是一个Ecliipse插件,它提供了在Eclipse中开发运行Pig程序的常用功能,比如脚本编辑、运行等。下载地址:http://wiki.apache.org/pig/PigPen
其他一些编辑器也提供了编辑Pig脚本的功能,比如vi等。


本文链接http://element-ui.cn/news/show-576988.aspx