【问题标题】:how to load files on hadoop cluster using apache pig?如何使用 apache pig 在 hadoop 集群上加载文件?
【发布时间】:2012-02-29 00:20:36
【问题描述】:

我有一个 pig 脚本,需要从本地 hadoop 集群加载文件。我可以使用 hadoop 命令列出文件:hadoop fs –ls /repo/mydata,` 但是当我尝试在 pig 脚本中加载文件时,它失败了。加载语句是这样的:

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

有什么想法吗?谢谢

【问题讨论】:

  • 知道了,应该是这样的:in = LOAD "hdfs:/repo/mydata/2012/02" USING PigStorage() AS ...

标签: hadoop apache-pig


【解决方案1】:

我的建议:

  1. 在 hdfs 中创建一个文件夹:hadoop fs -mkdir /pigdata

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

(或者你可以在 grunt shell 中使用 grunt> copyFromLocal /opt/pig/tutorial/data/excite-small.log /pigdata

  1. 执行猪拉丁脚本:

       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';
    
  2. 输出文件将存储在hdfs://hostname:54310/pigdata/output

【讨论】:

    【解决方案2】:

    我遇到了同样的问题..请在下面找到我的建议:

    1. 要开始使用 PIG,请输入: [root@localhost 培训]# pig -x local

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

    【讨论】:

      【解决方案3】:

      去掉“=”两边的空格 in=LOAD '/repo/mydata/2012/02' USING PigStorage() AS (event:chararray, user:chararray)

      【讨论】:

        猜你喜欢
        • 2023-03-23
        • 2016-07-23
        • 2023-04-05
        • 1970-01-01
        • 2014-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多