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

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

问题描述

我正在尝试找到

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天全站免登陆