【pig】Error Handling

We saw an example of this when the
Pow function detected overflow:
for (int i = 0; i < exponent; i++) {
long preresult = result;
result *= base;
if (preresult > result) {
// We overflowed. Give a warning, but do not throw an
// exception.
warn("Overflow!", PigWarning.TOO_LARGE_FOR_INT);
// Returning null will indicate to Pig that we failed but
// we want to continue execution.
return null;
}
}


warn, a method of EvalFunc, takes a message that you provide as well as a warning code.
The warning codes are in org.apache.pig.PigWarning, including several user-defined
codes that you can use if none of the provided codes matches your situation. These
warnings are aggregated by Pig and reported to the user at the end of the job.
Warning and returning null is convenient because it allows your job to continue. When
you are processing billions of records, you do not want your job to fail because one
record out of all those billions had a chararray where you expected an int. Given enough
data, the odds are overwhelming that a few records will be bad, and most calculations
will be fine if a few data points are missing.
For errors that are not tolerable, your UDF can throw an exception. If Pig catches an
exception, it will assume that you are asking to stop everything, and it will cause the
task to fail. Hadoop will then restart your task. If any particular task fails three times,
Hadoop will not restart it again. Instead, it will kill all the other tasks and declare the
job a failure.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值