【问题标题】:configuring LOAD function in PIG在 PIG 中配置 LOAD 函数
【发布时间】:2016-05-14 21:27:45
【问题描述】:

HDFS 中的输入文件 => /user/xyz/abc/part-m-00000

文件内容:-

100002030,Tom,peter,eng,block 3, lane 5,california,10021

100003031,Tom,john,doc,block 2, lane 2,california,10021

100004032,Tom,jim,eng,block 1, lane 1,california,10021

100005033,Tom,trek,doc,block 2, lane 2,california,10021

100006034,Tom,peter,eng,block 6, Lane 6,california,10021

架构文件 -

rollno,firstname,lastname,qualification,address1,address2,city,Zipcode

是否可以进行如下加载:-

输入 = 使用 PigStorage(',') 加载 '/user/xyz/abc/part-m-00000';

SF=load 'user/xyz/abc/sf.txt';

X= 使用 PigStorage(',') 作为 (SF) 加载“输入”;

它不起作用 请注意,我不想硬编码字段名称

感谢快速帮助,谢谢!

【问题讨论】:

    标签: hadoop apache-pig bigdata


    【解决方案1】:

    PigStorage 有第二个构造函数,它接受多个选项,其中之一是 -schema。 根据文档,创建一个隐藏文件 .pig_schema ,其中包含您的架构,它会在加载数据时从中加载您的架构。 更多细节在这里 https://pig.apache.org/docs/r0.10.0/api/org/apache/pig/builtin/PigStorage.html

    以下是步骤: 您需要做的第一件事是手动创建架构

    // Load data by specifying schema
    A = LOAD 'data' USING PigStorage(',') AS (name:chararray, amount:float);
    // Now store data in with -schema option to create schema
    STORE A INTO 'output' USING PigStorage(',', '-schema');
    // above statement will create .pig_schema file in "output" directory. copy this file to your source directory 'data'
    Now load data without specifying Schema
    
    A_WITHOUT_SCHEMA = LOAD 'data' USING PigStorage(',');
    
    // view the schema of relation by issuing describe statement.
    DESCRIBE A_WITHOUT_SCHEMA;
    
    // The output should be something like 
    {name: chararray, amount: float}
    

    我希望澄清解决方案。

    【讨论】:

    • 你能举例说明一下吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多