我对 HADOOP 和 pig 还很陌生。
所以 。我有一行 json 文件,都具有相同的架构:
{"name":"someName","pkg":[{"F1":"abc","F2":"44","F3":"xyz","F4":1024,"info":
[{"timestamp":1372631550000,"value":"122","id":"nnn","name":"ppp"},
{"timestamp":1372649240000,"value":"222","id":"ggg","name":"qqq"}]} ,
{"F1":"abc","f2":"44","F3":"xyz","F4":1024,"new":[{"type":"event1", "time":1372537000000,"more":"
{\"bbad\":\"HELLO\",\"is_done\":0,\"ssss\":-128}"}]}]}
我使用大象鸟加载所有的 json 文件:
data = LOAD 'browsers/gzip' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') as (json:map[]);
到目前为止,唯一对我有用的是查询返回字节数组的“名称”字段。
b = foreach data generate json#'name' as name
然后我尝试将其转换为地图:
c = FOREACH data GENERATE json#'name' as (m:map[]);
DESCRIBE c;
并得到
c: {tuple_0: (m:map[])}
数据看起来像:
({([F1#"abc",F2#44...])})
所以现在我需要过滤所有 pkg.F1 = "abc" 或所有 pkg.info.value = 122 等的。
我该怎么做?
一个代码示例将非常有帮助,因为我已经用谷歌搜索了很多。
谢谢