使用elephantbird-PIG读取JSON时出错

时间:2012-02-24 22:24:45

标签: json hadoop apache-pig

我无法使用ElephantBird和Pig读取JSON文件。我想知道我在哪里犯了错误。

数据:

{ "nrcpts": "1",
  "src": "info@example.com",
  "sendmailid": "p6D0r0u1006229",
  "relay": "app03.example.com",
  "classnumber": "0",
  "msgid": "WARQZCXAEMSSVWPPOOYZXR
LQIKMFUY.155763@example.com",
  "pid": "6229",
  "month": "Jul",
  "time": "20:53:00",
  "day": "12",
  "mailserver": "mail5",
  "size": "57395"
}

代码:

json1 = load '/user/hdetl/funnel/uetsample.dat' using com.twitter.elephantbird.pig.load.JsonLoader();

dat   = FOREACH json1 GENERATE $0#'mailserver' AS mailserver;
dump dat;

错误:

Input(s):
Failed to read data from "/user/hdetl/funnel/uetsample.dat"

detailed error :
Pig Stack Trace
---------------
ERROR 2997: Unable to recreate exception from backed error: Error: in

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias dat. Backend error : Unable to recreate exception from back
ed error: Error: in
        at org.apache.pig.PigServer.openIterator(PigServer.java:891)
        at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:655)
        at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:303)
        at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:188)
        at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:164)
        at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:69)
        at org.apache.pig.Main.run(Main.java:495)
        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:186)
Caused by: org.apache.pig.backend.executionengine.ExecException: ERROR 2997: Unable to recreate exception from backed error: Error: in
        at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.Launcher.getErrorMessages(Launcher.java:221)
        at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.Launcher.getStats(Launcher.java:151)
        at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher.launchPig(MapReduceLauncher.java:344)
        at org.apache.pig.PigServer.launchPlan(PigServer.java:1314)
        at org.apache.pig.PigServer.executeCompiledLogicalPlan(PigServer.java:1299)
        at org.apache.pig.PigServer.storeEx(PigServer.java:996)
        at org.apache.pig.PigServer.store(PigServer.java:963)
        at org.apache.pig.PigServer.openIterator(PigServer.java:876)

2 个答案:

答案 0 :(得分:0)

我没有使用JSON加载器,但我想你应该可以在你的foreach中丢弃$ 0。我只是相信装载机只是将{和}之间的所有内容转换成单个记录(元组)。

dat   = FOREACH json1 GENERATE mailserver;

答案 1 :(得分:0)

相当老的帖子,但有人可能有类似的问题。

我根据问题中提供的数据创建了输入文件 由于行中不必要的Enter,我无法加载该文件:

"msgid": "WARQZCXAEMSSVWPPOOYZXR
LQIKMFUY.155763@example.com",

但是修复并没有得到预期的结果。 我已经从文件中删除了所有输入,所以最后我只有一行。

文件已加载:

dump json1
([time#20:53:00,msgid#WARQZCXAEMSSVWPPOOYZXRLQIKMFUY.155763@example.com,relay#app03.example.com,mailserver#mail5,month#Jul,pid#6229,classnumber#0,day#12,src#info@example.com,sendmailid#p6D0r0u1006229,nrcpts#1,size#57395])

并且您foreach有效:

dat   = FOREACH json1 GENERATE $0#'mailserver' AS mailserver;
dump dat

(mail5)