蜂巢:列类型的Decimal(12,9)与JSONSerDe引发NullPointerException

时间:2018-07-11 11:03:59

标签: hadoop hive hiveql hadoop2

我有一个指向json数据的外部表。我正在使用Serde org.apache.hive.hcatalog.data.JsonSerDe
我已经使用DDL在此外部表的顶部创建了一个视图:

CREATE VIEW `my_table` AS SELECT
a.col1,
a.col2,
...
...
a.longitude,
a.latitude
FROM
(SELECT
mytable.body.col1,
mytable.body.col2,
....
..
mytable.body.longitude,
mytable.body.latidute,
ROW_NUMBER() OVER( PARTITION BY mytable.body.col1, mytable.body.col1 ORDER BY mytable.body.col3 DESC )
AS rownum FROM mydb.myExtTable) AS a where a.rownum=1

当我做SELECT * FROM mytable时,它给了我NullPointerException

Vertex failed, vertexName=Reducer 2, vertexId=vertex_1529530522022_75616_22_01, diagnostics=[Task failed, taskId=task_1529530522022_75616_22_01_000000, diagnostics=[TaskAttempt 0 failed, info=[Error: Failure while running task:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row (tag=0) [Error getting row data with exception java.lang.NullPointerException
        at org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryHiveDecimal.init(LazyBinaryHiveDecimal.java:47)
        at org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryStruct.uncheckedGetField(LazyBinaryStruct.java:267)
        at org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryStruct.getField(LazyBinaryStruct.java:204)
        at org.apache.hadoop.hive.serde2.lazybinary.objectinspector.LazyBinaryStructObjectInspector.getStructFieldData(LazyBinaryStructObjectInspector.java:64)
        at org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:354)
        at org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:354)
        at org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:354)
        at org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:198)
        at org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:184)
        at org.apache.hadoop.hive.ql.exec.tez.ReduceRecordSource$GroupIterator.next(ReduceRecordSource.java:347)
        at org.apache.hadoop.hive.ql.exec.tez.ReduceRecordSource.pushRecord(ReduceRecordSource.java:274)
        at org.apache.hadoop.hive.ql.exec.tez.ReduceRecordProcessor.run(ReduceRecordProcessor.java:266)
        at org.apache.hadoop.hive.ql.exec.tez.TezProcessor.initializeAndRunProcessor(TezProcessor.java:150)
        at org.apache.hadoop.hive.ql.exec.tez.TezProcessor.run(TezProcessor.java:139)
        at org.apache.tez.runtime.LogicalIOProcessorRuntimeTask.run(LogicalIOProcessorRuntimeTask.java:347)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable$1.run(TezTaskRunner.java:194)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable$1.run(TezTaskRunner.java:185)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:422)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1866)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable.callInternal(TezTaskRunner.java:185)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable.callInternal(TezTaskRunner.java:181)
        at org.apache.tez.common.CallableWithNdc.call(CallableWithNdc.java:36)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
 ]
        at org.apache.hadoop.hive.ql.exec.tez.TezProcessor.initializeAndRunProcessor(TezProcessor.java:173)
        at org.apache.hadoop.hive.ql.exec.tez.TezProcessor.run(TezProcessor.java:139)
        at org.apache.tez.runtime.LogicalIOProcessorRuntimeTask.run(LogicalIOProcessorRuntimeTask.java:347)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable$1.run(TezTaskRunner.java:194)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable$1.run(TezTaskRunner.java:185)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:422)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1866)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable.callInternal(TezTaskRunner.java:185)
        at org.apache.tez.runtime.task.TezTaskRunner$TaskRunnerCallable.callInternal(TezTaskRunner.java:181)
        at org.apache.tez.common.CallableWithNdc.call(CallableWithNdc.java:36)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

我只有2条记录为JSON。
这两个JSON就像:

{"header": {"header1":"value1", "header2": "value2"}, "body": {"col1": "col1 value", "col2": "col2 value",.... "latitude": 39.921302, "longitude": -74.879928}}
{"header": {"header1":"value1", "header2": "value2"}, "body": {"col1": "col1 value", "col2": "col2 value",.... "latitude": 43658734.438, "longitude": 3453.3453}} 

奇怪的是,当我仅使用1条记录在VIEW上运行SELECT时,它可以正确地获取我的信息,但是同时为两条记录运行它时,将给我带来异常。

当我从第二条记录的JSON数据中删除"latitude": 43658734.438, "longitude": 3453.3453值时,一切又恢复正常了。
longitudelatitude的类型为decimal(12,9)
我怀疑列值有问题吗?
但是,如果同时运行两个记录时这些值构成问题,为什么它们分别运行良好(请注意:分别运行第二条记录时,该记录的这两个列值将被NULL取代)。
可能是什么问题 ?

请帮助。

1 个答案:

答案 0 :(得分:1)

检查定义https://www.cloudera.com/documentation/enterprise/5-8-x/topics/impala_decimal.html

decimal(12,9)表示12位数字,小数点后为9位,因此前3位为小数。看来您至少需要decimal(14,6)在这里