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

查看:242
本文介绍了错误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



Pig Script that does not work, and calls 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 script that does work, but does not call 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 date;
dump B;



样本数据



Sample data

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



Java UDF



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

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.

推荐答案

日期有时可能为空吗?在您的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天全站免登陆