如何使用ApachePig在hadoop集群上加载文件?

如何使用ApachePig在hadoop集群上加载文件?,hadoop,apache-pig,Hadoop,Apache Pig,我有一个pig脚本,需要从本地hadoop集群加载文件。我可以使用hadoop命令列出文件:hadoop fs–ls/repo/mydata,` 但当我尝试用pig脚本加载文件时,失败了。load语句如下所示: in = LOAD '/repo/mydata/2012/02' USING PigStorage() AS (event:chararray, user:chararray) 错误消息是: Message: org.apache.pig.backend.executionengine

我有一个pig脚本,需要从本地hadoop集群加载文件。我可以使用hadoop命令列出文件:hadoop fs–ls/repo/mydata,` 但当我尝试用pig脚本加载文件时,失败了。load语句如下所示:

in = LOAD '/repo/mydata/2012/02' USING PigStorage() AS (event:chararray, user:chararray)
错误消息是:

Message: org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: file:/repo/mydata/2012/02
有什么想法吗?谢谢

我的建议:

  • 在hdfs中创建文件夹:
    hadoop fs-mkdir/pigdata

  • 将文件加载到创建的hdfs文件夹:
    hadoop fs-put/opt/pig/tutorial/data/exite-small.log/pigdata

  • (也可以从grunt shell中执行此操作,如
    grunt>copyFromLocal/opt/pig/tutorial/data/excite-small.log/pigdata

  • 执行pig拉丁语脚本:

       grunt> set debug on
    
       grunt> set job.name 'first-p2-job'
    
       grunt> log = LOAD 'hdfs://hostname:54310/pigdata/excite-small.log' AS 
                  (user:chararray, time:long, query:chararray); 
       grunt> grpd = GROUP log BY user; 
       grunt> cntd = FOREACH grpd GENERATE group, COUNT(log); 
       grunt> STORE cntd INTO 'output';
    
  • 输出文件将存储在
    hdfs://hostname:54310/pigdata/output


  • 我也面临同样的问题。。以下是我的建议:

  • 要开始使用清管器,请键入: [root@localhost培训]#pig-x本地

  • 现在键入load语句,就像我在下面的示例中所做的那样: grunt>a=LOAD'/home/training/pig/TempFile.txt',使用PigStorage(',')作为(c1:chararray,c2:chararray,c3:chararray)


  • 去掉“=”两边的空格
    in=LOAD'/repo/mydata/2012/02'使用PigStorage()作为(事件:chararray,用户:chararray)

    得到它,应该是这样的:in=LOAD“hdfs:/repo/mydata/2012/02”使用PigStorage()作为。。。