【问题标题】:apache pig, permutations of values grouped by idapache pig,按 id 分组的值的排列
【发布时间】:2017-03-31 22:19:38
【问题描述】:

使用 Apache Pig,我需要一个字段的所有排列,按 id 字段(在本例中为“标题”)分组。输入数据如下所示:

架构是 {chararray, chararray}

(title1, name1)
(title1, name2)
(title1, name3)
(title2, name4)
(title2, name5)
(title2, name6)

我需要 title1 名称关系和 title2 名称关系在一个列表中的所有排列。期望的输出是:

(name1, name2)
(name1, name3)
(name2, name3)
(name4, name5)
(name4, name6)
(name5, name6)

我找到了这个相关的答案How To Find All Possible Permutations From A Bag under apache pig,但我在扩展解决方案以限制每个标题字段的排列时遇到了困难。

【问题讨论】:

    标签: apache-pig permutation


    【解决方案1】:

    在做了更多搜索之后,使用这两个帖子: How To Find All Possible Permutations From A Bag under apache pig , PIG: Get all tuples out of a grouped bag 引导我找到这个解决方案:

    输入模式是 {chararray, chararray}

    inpt = foreach input generate $0 as (id:chararray), $1 as (val);
    grp = group inpt by (id);
    id_grp = foreach grp generate group as id, inpt.val as value_bag;
    result = foreach id_grp generate FLATTEN(value_bag) as v1,FLATTEN(value_bag) as v2; 
    result = filter result by v1 <= v2;
    result = filter result by v1 != v2;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      相关资源
      最近更新 更多