gpt4 book ai didi

hadoop - 如何从 Pig 中的关系生成自定义模式?

转载 作者:可可西里 更新时间:2023-11-01 15:42:09 27 4
gpt4 key购买 nike

我有一个描述各种文章中单词的 tf-idf 值的模式。它的描述如下:

tfidf_relation: {word: chararray,id: bytearray,tfidf: double}

这是此类数据的示例:

(cat,article_one,0.13515503603605478)
(cat,article_two,0.4054651081081644)
(dog,article_one,0.3662040962227032)
(apple,article_three,0.3662040962227032)
(orange,article_three,0.3662040962227032)
(parrot,article_one,0.13515503603605478)
(parrot,article_three,0.13515503603605478)

我想以一种形式获得输出:猫article_one 0.13515503603605478,article_two 0.4054651081081644等等。问题是,我如何从这个包含单词字段和 id 和 tfidf 字段的元组的关系中建立关系?像这样:

X = FOREACH tfidf_relation GENERATE word, (id, tfidf);

没用。正确的语法是什么?

最佳答案

试试这个:

    t = LOAD 'input/file' USING PigStorage(',') as (word: chararray,id: bytearray,tfidf: double);
u = group t by word;
dump u;

输出将是

    (cat,{(cat,article_two,0.4054651081081644),(cat,article_one,0.13515503603605478)})
(dog,{(dog,article_one,0.3662040962227032)})
(apple,{(apple,article_three,0.3662040962227032)})
(orange,{(orange,article_three,0.366204096222703)})
(parrot,{(parrot,article_three,0.13515503603605478),
(parrot,article_one,0.13515503603605478)})

希望这就是您要找的。

关于hadoop - 如何从 Pig 中的关系生成自定义模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5681744/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com