【发布时间】:2017-01-08 22:48:03
【问题描述】:
我正在尝试编写 Hadoop Pig 脚本,该脚本将采用 2 个文件并根据字符串进行过滤,即
words.txt
google
facebook
twitter
linkedin
tweets.json
{"created_time": "18:47:31 ", "text": "RT @Joey7Barton: ..give a facebook about whether the americans wins a Ryder cup. I mean surely he has slightly more important matters. #fami ...", "user_id": 450990391, "id": 252479809098223616, "created_date": "Sun Sep 30 2012"}
脚本
twitter = LOAD 'Twitter.json' USING JsonLoader('created_time:chararray, text:chararray, user_id:chararray, id:chararray, created_date:chararray');
filtered = FILTER twitter BY (text MATCHES '.*facebook.*');
extracted = FOREACH filtered GENERATE 'facebook' AS pattern,id, user_id, created_time, created_date, text;
final = GROUP extracted BY pattern;
dump final;
输出
(facebook,{(facebook,252545104890449921,291041644,23:06:59 ,Sun Sep 30 2012,RT @Joey7Barton: ..give a facebook about whether the americans wins a Ryder cup. I mean surely he has slightly more important matters. #fami ...)})
我得到的输出是,不加载 words.txt 文件,即直接过滤推文。
我需要得到输出
(facebook)(complete tweet of that facebook word contained)
即它应该读取 words.txt 并且根据它读取的单词应该从 tweets.json 文件中获取所有推文
任何帮助
莫汉.V
【问题讨论】:
-
可能是我遗漏了一些东西,但是您在脚本中的什么地方使用了 words.txt 文件?
-
不,我没有在提到的脚本中使用。但我想。
-
我怎样才能使用words.txt并得到上面提到的输出
标签: json hadoop twitter apache-pig tweets