这是我的(看似微不足道的)PIG 脚本,后面是它生成的异常:
raw_logs = LOAD './Apache-WebLog-Samples.d/access_log.txt' USING TextLoader() AS (line:chararray);
logs = FOREACH raw_logs GENERATE FLATTEN (
REGEX_EXTRACT_ALL(line, '^(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+\\[([\\w:/]+\\s[+\\-]\\d{4})\\]\\s+"(..*)"\\s+(\\S+)\\s+(\\S+)'))
AS (remoteAddr: chararray,
remoteLogname: chararray,
user: chararray,
date_time: chararray,
request: chararray,
httpStatus: int, <- Here's the problem. But goes away when I set to chararray.
numBytes: int);
httpGET200 = FILTER logs BY (request MATCHES '^GET\\s.*') AND (httpStatus == 200);
mylimit = LIMIT httpGET200 40;
DUMP mylimit;
猪脚本
java.lang.Exception: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:404)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
[ ... non meaningful error output removed ... ]
2013-03-13 14:04:10,882 [main] INFO org.apache.pig.tools.pigstats.SimplePigStats - Script Statistics:
HadoopVersion PigVersion UserId StartedAt FinishedAt Features
2.0.0-cdh4.2.0 0.10.0-cdh4.2.0 nmvega 2013-03-13 14:04:05 2013-03-13 14:04:10 FILTER,LIMIT
Failed!
Failed Jobs:
JobId Alias Feature Message Outputs
job_local1982169921_0001 httpGET200,logs,mylimit,raw_logs Message: Job failed!
Input(s):
Failed to read data from "file:///home/user/Dropbox/CodeDEV.d/BIG-DATA-SNIPPETS.d/PIG.d/Apache-WebLog-Samples.d/access_log.txt"
Output(s):
异常信息
除了“httpGET200”关系之外,一切都有效。由于对我来说不明显的原因,“httpStatus == 200”子句导致上述异常。当我删除该条款时,问题就消失了。或者,或者,当我更改架构并将“httpStatus”声明为“chararray”类型而不是“int”类型时(如上所述并且适用于 HTTP 状态代码),问题也消失了......(当然,当我这样做时,我必须编辑关系以插入引号,如下所示:httpStatus == '200')。
我检查了输入数据文件并验证,对于每一行,与“httpStatus”相对应的字段确实总是一个整数(......嗯,一个表示整数的子字符串)。
顺便说一下,这里是 grunt 报告的模式(即预期的):
grunt> describe httpGET200;
httpGET200: {remoteAddr: chararray,remoteLogname: chararray,user: chararray,date_time: chararray,request: chararray,httpStatus: int,numBytes: int}
我想了解这里发生了什么(我的误解或 PIG 限制)。任何人都可以阐明吗?
谢谢!