【问题标题】:Defining schema in JsonLoader in PIG在 PIG 中的 JsonLoader 中定义模式
【发布时间】:2016-04-01 15:17:47
【问题描述】:

我在使用 JsonLoader 从 JSON 文件中使用 Pig 时尝试输入数据集的架构。

数据格式如下:

{
  'cat_a':'some_text',
  'cat_b':{(attribute_name):(attribute_value)}
}

我试图将架构描述为:

LOAD 'filename' USING JsonLoader('cat_a:chararray, cat_b:(attribute_name:chararray,attribute_value:int)');

我觉得我对 cat_b 的架构描述不正确。

有人可以帮忙吗? 提前致谢。

【问题讨论】:

    标签: json hadoop schema apache-pig


    【解决方案1】:

    如果你的 json 是格式

    {"recipe":"Tacos","ingredients":[{"name":"Beef"},{"name":"Lettuce"},{"name":"Cheese"}]}
    

    将上面的json存入test.json

    运行以下命令

    a = LOAD '/home/abhijit/Desktop/test.json' USING JsonLoader('recipe:chararray,ingredients: {(name:chararray)}');
    
    dump a;
    

    你会得到输出为

    (Tacos,{(Beef),(Lettuce),(Cheese)},)
    

    如果你的 json 像下面的格式

    {"recipe":"Tacos","ingredients":[{"name":"Beef"},{"name":"Lettuce"},{"name":"Cheese"}],"inventor":{"name":"Alex","age":25}}
    
    a = LOAD '/home/abhijit/Desktop/test.json' USING JsonLoader('recipe:chararray,ingredients: {(name:chararray)},inventor: (name:chararray, age:int)');
    
    
    dump a;
    

    输出将是

    (Tacos,{(Beef),(Lettuce),(Cheese)},(Alex,25))
    

    【讨论】:

    • 这是否回答了您的问题...?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多