0

首先,我对 Pig 几乎是新手,我正在使用它,因为我的组织支持它。现在,我正在通过以下方式从目录中读取 json 文件(不使用 elephntBird,因为它的局限性,因为 Jackson 解析器可以做很多事情):

json = LOAD  '/user/json_data' USING TextLoader AS (line: chararray);

当我说dump json时,它会显示 /user/json_data 目录下所有可用 json 文件的内容。现在我正在使用我的 UDF 来解析这些 json 文件并将数据插入 Cassandra。猪声明是:

result = FOREACH json GENERATE com.myorg.pig.UDF(line);

但是当我转储结果时,它会显示以下异常:

 Pig Stack Trace
---------------
ERROR 2997: Unable to recreate exception from backed error: Error:    com.google.common.util.concurrent.Futures.withFallback(Lcom/google/common/util/concurrent/ListenableFuture;Lcom/google/common/util/concurrent/FutureFallback;Ljava/util/concurrent/Executor;)Lcom/google/common/util/concurrent/ListenableFuture;

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias result. Backend error : Unable to recreate exception from backed error: Error: com.google.common.util.concurrent.Futures.withFallback(Lcom/google/common/util/concurrent/ListenableFuture;Lcom/google/common/util/concurrent/FutureFallback;Ljava/util/concurrent/Executor;)Lcom/google/common/util/concurrent/ListenableFuture;
at org.apache.pig.PigServer.openIterator(PigServer.java:828)
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:696)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:320)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:194)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:170)
at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:69)
at org.apache.pig.Main.run(Main.java:538)
at org.apache.pig.Main.main(Main.java:157)
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:208)
Caused by: org.apache.pig.backend.executionengine.ExecException: ERROR 2997: Unable to recreate exception from backed error: Error: com.google.common.util.concurrent.Futures.withFallback(Lcom/google/common/util/concurrent/ListenableFuture;Lcom/google/common/util/concurrent/FutureFallback;Ljava/util/concurrent/Executor;)Lcom/google/common/util/concurrent/ListenableFuture;
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.Launcher.getErrorMessages(Launcher.java:217)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.Launcher.getStats(Launcher.java:149)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher.launchPig(MapReduceLauncher.java:400)
at org.apache.pig.PigServer.launchPlan(PigServer.java:1266)
at org.apache.pig.PigServer.executeCompiledLogicalPlan(PigServer.java:1251)
at org.apache.pig.PigServer.storeEx(PigServer.java:933)
at org.apache.pig.PigServer.store(PigServer.java:900)
at org.apache.pig.PigServer.openIterator(PigServer.java:813)
... 12 more

我的UDF是:

public class UDF extends EvalFunc<String> {


@Override
public String exec(Tuple tuple) throws IOException {
    if (null == tuple || tuple.size() != 1)
        return "bad input";
    try {
    String file = (String) tuple.get(0);
    DynamicJsonFlattener obl=new DynamicJsonFlattener(null);
    obl.processJsonToCassandra(file);

       return "processed successfully";
    } catch (Exception e) {
        return "error";
    }
  }
}

我在这里看到了几个答案,但没有发现任何改进。如果我以错误的方式进行操作,请提供任何意见并提出替代方案。

4

1 回答 1

0

很可能您的 UDF 失败了,这就是您没有结果关系的原因。您正在使用的代码是否有效/经过测试?

于 2016-04-08T23:01:54.730 回答