【问题标题】:PIG: CONCAT A relation OUTPUT to another RELATIONPIG:CONCAT 关系输出到另一个关系
【发布时间】:2016-09-07 18:50:46
【问题描述】:

抱歉,问题的措辞有误。 我是 stackoverflow 的新手,也是 PIG 的新手,我正在尝试自己进行实验。

我有一个处理 words.t 文件和 data.txt 文件的场景。

words.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_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 @Joey7Barton: ..give a word1 关于美国人是否赢得莱德杯。我的意思是肯定他 有稍微重要的事情。 #家庭 ...","user_id":450990391,"id":252479809098223616}

通过使用此脚本。

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}

请随时向我提出上述建议。 谢谢。

【问题讨论】:

    标签: hadoop apache-pig epoch


    【解决方案1】:

    我想我得到了输出。 这是我写的脚本。

    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;
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 感谢您的重播阿米特。实际上,我没有正确提及它是我的错误。我正在根据 created_at 属性获取纪元时间。我已经编辑了问题。请您重新检查一次。请建议我。
      猜你喜欢
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2018-01-08
      • 2022-01-15
      • 1970-01-01
      相关资源
      最近更新 更多