Apache pig 用拉丁语读取Json数据

Apache pig 用拉丁语读取Json数据,apache-pig,Apache Pig,我想用拉丁语读取Json中的嵌套数据 {"info":{"Id":53556,"State":"Ohio"},"time":139140} {"info":{"Id":3554,"State":"Calif"},"time":1391407471477} 我是用电脑做的 read = load '$json_file' USING JsonLoader('Id : chararray, state : chararray, time : chararray'); 以及使用PigStora

我想用拉丁语读取Json中的嵌套数据

{"info":{"Id":53556,"State":"Ohio"},"time":139140}  
{"info":{"Id":3554,"State":"Calif"},"time":1391407471477}
我是用电脑做的

read = load '$json_file' USING JsonLoader('Id : chararray, state : chararray, time : chararray');
以及使用PigStorage(“,”,“-noschema”)将读取的数据存储到
/tmp/data.csv中


但是我在data.csv中得到了垃圾值。你知道我读错了还是存储错了吗?

你的LOAD语句中的模式不正确info是一个名称,{“Id”:53556,“State”:“Ohio”}是它的值。该值是一个对象,也是一组无序的名称/值对,即“Id”:53556和“State”:“Ohio”

试试这个

read = 
        LOAD 'test.dat' 
        USING JsonLoader('
                info:(
                        id       : CHARARRAY
                        , state  : CHARARRAY )
                , time : CHARARRAY
        ');

proj = 
        FOREACH read 
        GENERATE 
            FLATTEN(info) AS (
                    id
                    , state )
            , time
        ;

proj2 = 
        FOREACH proj 
        GENERATE 
                state
                , time
        ;

dump proj2;
输出

(Ohio,139140)
(Calif,1391407471477)

有人能对此发表评论吗?我使用JsonLoader时有问题吗?