gpt4 book ai didi

apache-pig - 如何在列子集上使用 Pig Latin 执行 DISTINCT?

转载 作者:行者123 更新时间:2023-12-03 23:23:16 26 4
gpt4 key购买 nike

我想对列的子集执行 DISTINCT 操作。 documentation说这可以通过嵌套的 foreach 实现:

You cannot use DISTINCT on a subset of fields; to do this, use FOREACH and a nested block to first select the fields and then apply DISTINCT (see Example: Nested Block).



对所有列执行 DISTINCT 操作很简单:
A = LOAD 'data' AS (a1,a2,a3,a4);
A_unique = DISTINCT A;

假设我有兴趣在 a1、a2 和 a3 之间执行不同的操作。谁能提供一个示例,说明如何按照文档中的建议使用嵌套的 foreach 执行此操作?

这是输入和预期输出的示例:
A = LOAD 'data' AS(a1,a2,a3,a4);
DUMP A;

(1 2 3 4)
(1 2 3 4)
(1 2 3 5)
(1 2 4 4)

-- insert DISTINCT operation on a1,a2,a3 here:
-- ...

DUMP A_unique;

(1 2 3 4)
(1 2 4 4)

最佳答案

对所有其他列进行分组,仅将感兴趣的列投影到一个包中,然后使用 FLATTEN再次扩展它们:

A_unique =
FOREACH (GROUP A BY a4) {
b = A.(a1,a2,a3);
s = DISTINCT b;
GENERATE FLATTEN(s), group AS a4;
};

关于apache-pig - 如何在列子集上使用 Pig Latin 执行 DISTINCT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19016374/

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