--错误1066:无法打开alias的迭代器

aelbi1ox  于 2021-06-25  发布在  Pig
关注(0)|答案(1)|浏览(451)

我是新来的Pig我的输入数据是
(message,nil,2015-07-01,22:58:53.66,e,machine.com.name,12,0xd6,string,string,0,0.0,key=value&key=123456789&key=value&key=us&key=company&key=message&key=123456789&key=string&key=string&key=string)
我编写了如下javaudf来解析最后一个输入数据字符串

package com.pig.udf;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;

public class PigUDF extends EvalFunc<Map> {

    @Override
    public Map<String, String> exec(Tuple input) throws IOException {
        // If tuple is null, has fewer than 3 values, or has an even number of
        // values
        if (input == null || input.size() < 3 || (input.size() % 2 == 0)) {
            throw new IOException("Incorrect number of values.");
        }

        String source = (String) input.get(0);
        System.out.println("input Source"+source);
        String delim = (input.size() > 1) ? (String) input.get(1) : "&";
        int length = (input.size() > 2) ? (Integer) input.get(2) : 0;
        if (source == null || delim == null) {
            return null;
        }

        String[] splits = source.split(delim, length);
        System.out.println("Splits"+ splits);
        ArrayList<String> arrayList = new ArrayList<String>(
                Arrays.asList(splits));
        Map<String, String> map = new HashMap<String, String>();
        for (String keyValue : arrayList) {
            int end = keyValue.indexOf('=');
            if (end != -1) {
                map.put(keyValue.substring(0, end), keyValue.substring(end + 1));
            }

        }
        System.out.println("map"+map);

        return map;

    }

}

当我用上面的javaudf运行mypig脚本时,我得到了下面的错误

Pig Stack Trace
---------------
ERROR 1066: Unable to open iterator for alias C

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias C
    at org.apache.pig.PigServer.openIterator(PigServer.java:892)
    at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:774)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:372)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:198)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:173)
    at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
    at org.apache.pig.Main.run(Main.java:607)
    at org.apache.pig.Main.main(Main.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.io.IOException: Job terminated with anomalous status FAILED
    at org.apache.pig.PigServer.openIterator(PigServer.java:884)
    ... 13 more

    Application Log
    -------------------------------------------------------------------
    Application application_1436453941326_0020 failed 2 times due to AM Container for appattempt_1436453941326_0020_000002 exited with exitCode: 1
For more detailed output, check application tracking page:http://quickstart.cloudera:8088/proxy/application_1436453941326_0020/Then, click on links to logs of each attempt.
Diagnostics: Exception from container-launch.
Container id: container_1436453941326_0020_02_000001
Exit code: 1
Stack trace: ExitCodeException exitCode=1:
at org.apache.hadoop.util.Shell.runCommand(Shell.java:538)
at org.apache.hadoop.util.Shell.run(Shell.java:455)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:715)
at org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor.launchContainer(DefaultContainerExecutor.java:211)
at org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:302)
at org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:82)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Container exited with a non-zero exit code 1
Failing this attempt. Failing the application.

我的脚本运行良好,没有javaudf函数,也给了我outfile。当我在pig脚本中包含javaudf时,问题就出现了。在我的javaudf和运行pig的机器之间没有java版本不匹配,任何指针都将受到赞赏
Pig脚本:

Register '/home/cloudera/Pig/PigUDF_1.7.jar';
Register '/home/cloudera/Pig/pig.jar';
 A= Load 'Logs_message.txt' using PigStorage(',') as (component:chararray,Nil:chararray,date:chararray,time:chararray,E:chararray,machine_address:chararray,number1:chararray,hex_number:chararray,cal_type:chararray,cal_name:chararray,number2:chararray,number3:chararray,data:chararray) 
 B = filter A by cal_name matches 'CHANGEDMESSAGE';
 C = foreach B generate cal_name ,com.pig.udf.PigUDF(data) as dataMap;
 dump C ;
q0qdq0h2

q0qdq0h21#

我发现你的代码有3个问题:
你第一行少了一个分号。不知道它是怎么运行的,假设这是复制到stackoverflow的错误
将变量命名为“e”:这是一个保留变量。不知道这会有什么影响,但我不会为了安全而这么做。有关保留的pig关键字的列表,请参见此处
(这可能是导致错误的原因)。你的验证毫无意义。看起来您创建了一个split函数,用于接受3个或更少的参数(要拆分的字符串、分隔符和最大拆分大小)。但是您正在验证输入是否有3个以上的参数。您还验证了它是否有偶数个参数。这看起来像是在拆分字符串之后而不是之前对其进行的验证。
应该是这样的:

if (input == null || input.size() == 0 || input.size() > 3) {
  throw new IOException("Incorrect number of values.");
}
//...
if(splits.length % 2 != 0)
  throw new IOException("Invalid key value pairs");

我建议不要在hadoop上的云中运行程序,除非你已经调试了它们,首先让它们在本地工作。如果使用pigserver类,则可以通过eclipse或其他ide在开发机器上调试udf。

相关问题