猪相当于 SQL GREATEST/LEAST? [英] Pig equivalent of SQL GREATEST / LEAST?

查看:27
本文介绍了猪相当于 SQL GREATEST/LEAST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到与 SQL 函数 GREATESTLEAST.这些函数分别是聚合 SQL 函数 MAXMIN 的标量等价物.

I'm trying to find the Pig equivalent of the SQL functions GREATEST and LEAST. These functions are the scalar equivalent of the aggregate SQL functions MAX and MIN, respectively.

本质上,我希望能够这样说:

Essentially, I want to be able to say something like this:

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, GREATEST(a, b, c) AS g: int;

我知道我可以使用 bag 和 MAX 来完成这项工作,但我正在从另一种语言翻译成 Pig,并且该实现将难以集成.

I know I could use bags and MAX to get this done, but I'm translating from another language into Pig and that implementation would be difficult to integrate.

我可以在这里使用内联"方法吗?我忽略了一些内置函数,或者可能是 Piggybank 或 DataFu 中的 UDF,例如,将是理想的!如果有一个使用包的完全内联"版本而我只是没有想到它,那也很好!

Is there an "inline" approach I could use here? Some builtin function I'm overlooking, or maybe a UDF in Piggybank or DataFu, for example, would be ideal! If there's a completely "inline" version that uses bags and I'm just not thinking of it, that's fine too!

谢谢!

推荐答案

事实证明,存在有效的内联"基于袋子的方法:

It turns out that there are "inline" bag-based approaches that work:

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;

这篇关于猪相当于 SQL GREATEST/LEAST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆