带有 int 的猪拉丁语 sum 函数中的错误 1045 [英] Error 1045 on sum function in pig latin with an int

查看:31
本文介绍了带有 int 的猪拉丁语 sum 函数中的错误 1045的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下猪拉丁文字:

data = load 'access_log_Jul95' using PigStorage(' ') as (ip:chararray, dash1:chararray, dash2:chararray, date:chararray, date1:chararray, getRequset:chararray, location:chararray, http:chararray, code:int, size:int);

splitDate = foreach data generate  size as size:int , ip as ip,  FLATTEN(STRSPLIT(date, ':')) as h;

groupedIp = group splitDate by h.$1;

a = foreach groupedIp{
    added = foreach splitDate generate SUM(size); --
    generate added;
};


describe a;

给我错误:

<代码>错误 1045:<文件3.pig,第10行,第39列>无法将 org.apache.pig.builtin.SUM 的匹配函数推断为多个匹配或不匹配.请使用显式转换.

这个错误让我觉得我需要将 size 转换为 int,但如果我描述我的 groupedIp 字段,我会得到以下架构.

This error makes me think I need to cast size as an int, but if i describe my groupedIp field, I get the following schema.

groupedIp: {group: bytearray,splitDate: {(size: int,ip: chararray,h: bytearray)}} 表示size是一个int,应该可以使用通过 sum 函数.

groupedIp: {group: bytearray,splitDate: {(size: int,ip: chararray,h: bytearray)}} which indicates that size is an int, and should be able to be used by the sum function.

我是否错误地调用了 sum 函数?如果您想查看其他内容,例如输入文件,请告诉我.

Am I calling the sum function incorrectly? Let me know if you would like to see any thing else, such as the input file.

推荐答案

SUMbag 进行操作作为输入,但您将字段size"传递给它.
尝试消除嵌套的 foreach 并使用:

SUM operates on a bag as input, but you pass it the field 'size'.
Try to eliminate the nested foreach and use:

a = foreach groupedIp generate SUM(splitDate.size);

这篇关于带有 int 的猪拉丁语 sum 函数中的错误 1045的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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