0

我正在本地桌面上试用 apache pig。

我希望 apache 页面上的教程是准确的或调用步骤。我安装了 pig 并试图粘贴示例代码:从这里http://pig.apache.org/docs/r0.7.0/setup.html#Sample+Code

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; 

不清楚我是否必须输入 pig -x local 来尝试 grunt 命令 [可能是 pig 必须以两种模式之一运行,但不明显开箱即用的操作]

我输入后

pig -x local 

我得到 grunt 提示,但命令失败说:

 Message: org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: file:/home/<usr>/passwd

在搜索谷歌时,我被路由到这样的邮件档案:http://mail-archives.apache.org/mod_mbox/pig-user/201109.mbox/%3C4E73658D.3000705@figarocms.fr%3E 这些很难阅读并关注对话。

这是我正在寻找的两件事:1]在您开始使用有线之前,是否有更好的指南来编写猪脚本和UDF,可以让您掌握一段时间[至少让您通过编写1-2个UDF来分析示例日志]错误。任何博客文章等如果说我有 4 个小时来编写几个简单的猪脚本,那么一个好的起点是什么 2] 对于我得到的错误,我可能需要将 passwd 文件添加到 HDFS 吗?不幸的是,“hadoop fs -mkdir -p /home/”表示该目录存在。那么我现在如何将文件放在那里。由于我在本地模式下运行它,有没有办法让 HDFS 在我在 FS 上提到的路径上查找文件,而不是每次都将文件放到 HDFS 上?

谢谢!

4

1 回答 1

1

在本地启动 pig 时,它将连接到您的本地文件系统:

user@machine~/pig-distrib$ pig -x local
12/08/23 10:10:24 INFO pig.Main: Apache Pig version 0.10.0 (r1328203) compiled Apr 19 2012, 22:54:12
12/08/23 10:10:24 INFO pig.Main: Logging error messages to: /home/user/pig-distrib/logs/pig.log
12/08/23 10:10:24 INFO executionengine.HExecutionEngine: Connecting to hadoop file system at: file:///
grunt> 
...


要找到 passwd,您有以下选项:
1.
复制/etc/passwd到执行 pig shell 的目录,然后您可以发出:

grunt> A = load 'passwd' using PigStorage(':');

2.
导航到 shell 中的目录:

grunt> cd /etc
grunt> A = load 'passwd' using PigStorage(':');

3.
或者使用文件的完整路径:

grunt> A = load '/etc/passwd' using PigStorage(':');

您也可以查看这些资源:
http ://www.cloudera.com/wp-content/uploads/2010/01/IntroToPig.pdf
Programming Pig 在线笔记
http://parand.com/say/index.php/2008 /06/19/pig-hadoop-commands-and-sample-results/

于 2012-08-23T08:26:23.043 回答