pig:将一个关系输出连接到另一个关系

eni9jsuy  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(321)

对不起,问题的措辞有误。我对stackoverflow是个新手,对pig也是个新手,我也尝试着自己做实验。
我有一个处理words.t文件和data.txt文件的场景。
文字.txt

word1
word2
word3
word4

数据.txt

{"created_at":"18:47:31,Sun Sep 30 2012","text":"RT @Joey7Barton: ..give a word1 about whether the americans wins a Ryder cup. I mean surely he has slightly more important matters. #fami ...","user_id":450990391,"id":252479809098223616}

我需要得到输出作为
(word1\u epochtime){文本属性中匹配的完整数据}

(word1_1234567890){"created_at":"18:47:31,Sun Sep 30 2012","text":"RT @Joey7Barton: ..give a word1 about whether the americans wins a Ryder cup. I mean surely he has slightly more important matters. #fami ...","user_id":450990391,"id":252479809098223616}

我的输出是
(word1){“created_at”:“18:47:31,sun sep 30 2012”,“text”:“rt@joey 7barton:……请用词1说明美国人是否赢得莱德杯。我是说他肯定还有更重要的事#fami…,“用户id”:450990391,“id”:25247980989823616}
通过使用此脚本。

load words.txt
load data.txt
c = cross words,data;
d = FILTER c BY (data::text MATCHES CONCAT(CONCAT('.*',words::word),'.*'));
e =  foreach (group d BY word) {data);

我得到了一个年代,上面写着

time = FOREACH words GENERATE CONCAT(CONCAT(word,'_'),(chararray)ToUnixTime(CurrentTime(created_at));

但我无法用时间来表达这些话。
我怎样才能得到输出

(word1_time){data}

请随时向我推荐以上内容。谢谢您。

yhxst69z

yhxst69z1#

根据这个引用,concat接受两个“字段”作为输入。我想你的问题是 (chararray)ToUnixTime(CurrentTime()) ,不是字段名。您可以生成表示当前时间戳值的字段,然后在concat函数中使用它。

iezvtpos

iezvtpos2#

我想我得到了结果。这是我写的剧本。

d = FILTER c BY (data::text MATCHES CONCAT(CONCAT('.*',word::word),'.*'));
e = FOREACH d GENERATE CONCAT(CONCAT(word,'_'),(chararray)ToUnixTime(CurrentTime(created_at))) as epochtime;
f = foreach (group e BY epochtime) {data}
dump f;

相关问题