包中的最大值

时间:2016-03-21 14:32:50

标签: apache-pig

跟进问题Pig equivalent of SQL GREATEST / LEAST?

我做了

x = LOAD 'file:///a/b/c.csv' USING PigStorage() AS (a: int, b: int, c: int); y = FOREACH x GENERATE a AS a: int, b AS b: int, c AS c: int, MAX(TOBAG(a, b, c)) AS g: int;

如上所述,它获得了最大值(真棒btw!)。你怎么知道这个值最初在哪个列(a,b或c)?

1 个答案:

答案 0 :(得分:0)

简单的方法可以是:

z = FOREACH y GENERATE
      a,
      b,
      c,
      g,
      CASE WHEN
         g==a THEN 'a'
         g==b THEN 'b'
         g==c THEN 'c'
      END as 'which_column';