gpt4 book ai didi

user-defined-functions - 错误 1066 : Unable to open iterator for alias in pig

转载 作者:行者123 更新时间:2023-12-04 08:42:41 29 4
gpt4 key购买 nike

我正在运行一个 pig 脚本,如下所示

REGISTER '/home/vishal/FirstUdf.jar';
DEFINE UPPER com.first.UPPER();
A = LOAD '/home/vishal/exampleforPIG1' AS (exchange: chararray, symbol: chararray, date: int,value:float);
B= FOREACH A GENERATE com.first.UPPER(exchange);
DUMP B;

Following is my UDF in java

package com.first;

import java.io.IOException;

import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;

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

现在当我尝试运行它时,它给了我以下错误

Pig Stack Trace

ERROR 1066: Unable to open iterator for alias B

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias B
at org.apache.pig.PigServer.openIterator(PigServer.java:866)
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:683)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:303)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:190)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:166)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
at org.apache.pig.Main.run(Main.java:430)
at org.apache.pig.Main.main(Main.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.RunJar.main(RunJar.java:156) Caused by: java.io.IOException: Job terminated with anomalous status FAILED
at org.apache.pig.PigServer.openIterator(PigServer.java:858)
... 12 more

为什么在 pig 脚本中它不能为 B 打开一个迭代器,即(它不能为下一行分配一个迭代器)

B = FOREACH A GENERATE com.first.UPPER(exchange);

'exampleforPIG1' 文件有以下数据

NYSE    CPO 2009-12-30  0.14
NYSE CPO 2009-09-28 0.14
NYSE CPO 2009-06-26 0.14
NYSE CPO 2009-03-27 0.14
NYSE CPO 2009-01-06 0.14
NYSE CCS 2009-10-28 0.414
NYSE CCS 2009-07-29 0.414
..
..
etc

最佳答案

有两件事,

  1. 如果您只想转换为大写/小写,为什么不使用内置函数 UPPER/LOWER。您可以在引用手册中找到用法。

  2. 如果您想继续使用相同的方法,应该是
    B = FOREACH A GENERATE UPPER(交换);
    您已经将其定义为 DEFINE UPPER com.first.UPPER();

关于user-defined-functions - 错误 1066 : Unable to open iterator for alias in pig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15546402/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com