0

我正在尝试使用 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_ideight_score展平seven数组/包的元素

4

1 回答 1

-1

尝试使用

c = FOREACH b GENERATE FLATTEN(three);
d = FOREACH c GENERATE three::four#five AS five;
于 2016-03-15T19:46:29.073 回答