如何从别名计算所有行中字段的总和 [英] How to compute sum of a field in all the rows from an alias

查看:34
本文介绍了如何从别名计算所有行中字段的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是对别名中所有行中的字段值求和.这一定很简单,但不知何故我找不到答案.这可能是因为我想要的是标量值,而 PIG 处理数据集?我想我可以创建一个包含总和字段的行?请指教!

What I want to do is to sum values of a field in all rows in an alias. This must be simple but somehow I can't find the answer. This is probably because what I want is a scalar value while PIG handles datasets? I guess I can create a row with a field which is the sum? Please advise!

推荐答案

这可以通过使用 GROUP ALL 将所有内容合并为一个组,然后使用 SUM 函数将所有字段加在一起来实现:

This can be achieved using a GROUP ALL to bring everything into a single group, and then the SUM function to add together all the fields:

DESCRIBE a
a: (name, age, height)

b = GROUP a ALL;
c = FOREACH b GENERATE SUM(a.age);

这篇关于如何从别名计算所有行中字段的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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