【发布时间】:2016-03-15 16:18:06
【问题描述】:
我正在尝试使用 Pig 中的 Elephant Bird 解析嵌套的 JSON 对象,该对象的级别可以包含包和/或元组。在第四层引用列会导致一些奇怪的行为。
Pig 在引用第四个或以下的列时出现问题。似乎是因为数据在包、元组和映射之间做了一些交替。需要明确的是,看起来 JsonLoader 将一些转换为地图,但其他则没有。比如下面对“五”的引用。
HDP 版本:2.1.2,猪版本:0.12.1,象鸟版本:4.13
这是结构的示例数据,其中键和值替换为占位符。
{
"one" : {
"output_info" : {
"sample_key": "sample value"
},
"two" : {
"three" : [{
"three_id" : "three_id_value",
"four" : {
"five" : [{
"level_five_info" : {
"five_info_key" : "five_info_value"
},
"six" : {
"seven" : [{
"eight_id" : "123545",
"eight_score" : "77"
}, {
"eight_id" : "98765",
"eight_score" : "88"
}
]
}
}
]
}
}]
}
}
}
猪声明:
a = LOAD 'nest_test.dat' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS (json:map[]);
b = foreach a generate json#'one'#'two'#'three' as (three: {(three_id: chararray,four: map[])});
运行 dump b; 会导致:
({([three_id#three_id_value,four#{five={([six#{seven={([eight_score#77,eight_id#123545]),([eight_score#88,eight_id#98765])}},level_five_info#{five_info_key=five_info_value}])}}])})
这一切看起来都符合预期,但是:
c = foreach b generate three.four as ({(four:map[])});
但是现在,运行 dump c; 不会返回任何上述数据。
({()})
省略架构描述也是如此
c = foreach b generate three.four
引用更深的级别会出错:
d = foreach b generate three.four#'five';
2016-03-15 11:56:01,655 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1052: Cannot cast bag with schema :bag{:tuple(four:map)} to map with schema :map
我应该如何参考第五级和第六级?我的最终目标是能够引用eight_id 和eight_score 并展平seven 数组/包的元素
【问题讨论】:
标签: json hadoop nested apache-pig elephantbird