错误 1066:无法在某些字段中打开别名的迭代器,但适用于其他字段 [英] ERROR 1066: Unable to open iterator for alias in certain fields, but works for others

查看:21
本文介绍了错误 1066:无法在某些字段中打开别名的迭代器,但适用于其他字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在某些领域使用我的 udf,但我可以在其他领域使用.如果我使用我的第一个字段 ipAddress,则 udf 将按预期工作.但是,如果我将其更改为 date,则会出现 1066 错误.这是我的脚本.

I am unable to use my udf on some fields, yet I can do it on others. If I use my first field, ipAddress, the udf works as intended. However, if I change it to be date I got the 1066 error. Here is my script.

REGISTER myudfs.jar;
DEFINE HOUR myudfs.HOUR;

A = 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, port:int);
B = FOREACH A GENERATE HOUR(ip);
dump B;

Pig 脚本不起作用,并调用 udf

REGISTER myudfs.jar;
DEFINE HOUR myudfs.HOUR;

A = 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, port:int);
B = FOREACH A GENERATE HOUR(date);
dump B;

可以运行但不调用 udf 的 Pig 脚本

REGISTER myudfs.jar;
DEFINE HOUR myudfs.HOUR;

A = 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, port:int);
B = FOREACH A GENERATE date;
dump B;

示例数据

199.72.81.55 - - [01/Jul/1995:00:00:01 -0400] "GET /history/apollo/ HTTP/1.0" 200 6245

Java UDF

 package myudfs;
 import java.io.IOException;
 import org.apache.pig.EvalFunc;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.impl.util.WrappedIOException;

 public class HOUR extends EvalFunc<String>
 {
        @SuppressWarnings("deprecation")
        public String exec(Tuple input) throws IOException {
            if (input == null || input.size() == 0)
                return " ";
         try{
             String str = (String)input.get(0);
                return str.substring(0, 1);
            }catch(Exception e){
                throw WrappedIOException.wrap("Caught exception processing input row ", e);
            }
        }
 }

错误

ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1066: Unable to open iterator for alias B

如果还有什么,请告诉我.我在本地运行时遇到此错误,并减少了地图.

If there is anything else, let me know. I get this error running locally, and over map reduce.

推荐答案

date 有时会为空吗?在您的 UDF 中,对元组进行了空检查,但没有对 input.get(0)

Could date be null some of the time? In your UDF there is a null check for the tuple but no check for input.get(0)

如果发生这种情况,它将击中您的 catch 块并且您的 UDF 将出错.可能导致此错误...

If this happens, it will hit your catch block and your UDF will error out. Could possibly be causing this error...

这篇关于错误 1066:无法在某些字段中打开别名的迭代器,但适用于其他字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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