4

我对 Hive 和 ElasticMapreduce 相当陌生,目前我遇到了一个特定问题。在具有数十亿行 JSON 对象的表上运行 Hive 语句时,只要其中一行是无效/格式错误的 JSON,MapReduce 作业就会崩溃。

例外:

java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing writable {"ip":"39488130","cdate":"2012-08-09","cdate_ts":"2012-08-09 17:06:41","country":"SA","city":"Riyadh","mid":"6666276582211270592","osversion":"5.1.
1
at org.apache.hadoop.hive.ql.exec.ExecMapper.map(ExecMapper.java:161)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:50)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:441)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:377)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1132)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing writable {"ip":"39488130","cdate":"2012-08-09","cdate_ts":"2012-08-09 17:06:41","country":"SA","city":"Riyadh","mid":"6666276582211270592","osversion":"5.1.1
at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:524)
at org.apache.hadoop.hive.ql.exec.ExecMapper.map(ExecMapper.java:143)
... 8 more
Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string near
at com.google.gson.Streams.parse(Streams.java:51)
at com.google.gson.JsonParser.parse(JsonParser.java:83)
at com.google.gson.JsonParser.parse(JsonParser.java:58)
at com.google.gson.JsonParser.parse(JsonParser.java:44)
at com.amazon.elasticmapreduce.JsonSerde.deserialize(Unknown Source)
at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:510)
... 9 more
Caused by: com.google.gson.stream.MalformedJsonException: Unterminated string near
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1110)
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:967)
at com.google.gson.stream.JsonReader.nextValue(JsonReader.java:802)
at com.google.gson.stream.JsonReader.objectValue(JsonReader.java:782)
at com.google.gson.stream.JsonReader.quickPeek(JsonReader.java:377)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:340)
at com.google.gson.Streams.parseRecursive(Streams.java:60)
at com.google.gson.Streams.parseRecursive(Streams.java:83)
at com.google.gson.Streams.parse(Streams.java:40)
... 14 more

我像这样创建我的表:

CREATE EXTERNAL TABLE IF NOT EXISTS table1 (
column1 string,
column2 string
)
PARTITIONED BY (year string, month string)
ROW FORMAT SERDE 'com.amazon.elasticmapreduce.JsonSerde'
WITH SERDEPROPERTIES ('paths'='c1, c2')
LOCATION 's3://mybucket/table1';

我能做些什么来防止崩溃?忽略格式错误的 JSON 对象/字符串会很好,因为它的十亿分之一是格式错误的。

提前感谢您的帮助。最好的,萨沙

4

3 回答 3

4

通过更改行格式中使用的类并添加“格式错误”属性,您可以使您的表创建工作在格式错误的 JSON 上:

ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ("ignore.malformed.json" = "true")
LOCATION ...

使用“hive-site.xml”中的“hive.aux.jars.path”属性或“ADD JAR”Hive 指令包含 JAR。您可以在此处找到 JAR ,或从此源代码编译它。

于 2015-09-26T19:24:50.233 回答
0

来自 Apache 的 JsonSerDe 似乎忽略了格式错误的 JSON 字符串... http://code.google.com/p/hive-json-serde/

于 2013-01-03T14:28:09.227 回答
-2

基本上,发生上述错误是因为 JSON 无效字符串。尝试解决此问题。

否则,为避免您的应用程序崩溃,请在 try catch 块中捕获该异常并进一步处理。这样您的应用程序就不会崩溃。

于 2013-01-03T13:02:17.770 回答