【发布时间】:2017-12-08 15:12:45
【问题描述】:
由于
,无法查询嵌套 json 上的外部配置单元表 Error: java.io.IOException: org.apache.hadoop.hive.serde2.SerDeException: org.codehaus.jackson.JsonParseException: Current token (VALUE_STRING) not numeric, can not use numeric value accessors
Json 看起来像-
使用的创建表命令-
create external table s
(
magic String,
type String,
headers String,
messageSchemaId String,
messageSchema String,
message struct<data:struct<s_ID:double,s_TYPE_ID:Int,NAME:String,DES CR:String,ACTIVE_s:double,s_ID:double,s_ENABLED:Int,pharmacy_location:Int>,seData:struct<APPLICATION_ID:double,s_TYPE_ID:Int,NAME:String,DESCR:String,s_STAT:double,PROGRAM_ID:double,s_ENABLED:Int,s_location:Int>,headers:struct<operation:String, changeSequence:String, timestamp: String, streamPosition: String, transactionId: String>>
)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
Stored as textfile
LOCATION '/user/eh2524/pt_rpt/MGPH.APPLICATION';
对于相同的 json,我可以使用 -
创建外部表CREATE EXTERNAL TABLE `MGPH_ZT`(
`jsonstr` string)
PARTITIONED BY (
`dt` string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'/user/eh2524/pt_rpt/MGPH.APPLICATION/'
TBLPROPERTIES (
'transient_lastDdlTime'='1510776187')
但是要查询上面创建的表,我使用 jsontuple 方法,例如
select count(*) from pt_rpt_stg.hvf_modules j
lateral view json_tuple(j.jsonstr, 'message') m as message
lateral view json_tuple(m.message, 'data') d as datacntr
lateral view json_tuple(d.datacntr,'l_location') s as pharmacy_location
where pharmacy_location is null;
我想使用 Json serde 创建表,以便我的团队可以像对普通 hive 表一样直接查询它,现在查询时它会失败。
我做了什么-
我检查了json文件中是否有/n,但没有,也尝试了单条记录。
检查了 (https://community.hortonworks.com/questions/29814/how-to-load-nested-json-file-in-hive-table-using-h.html) 上的表创建定义是否有嵌套的 json,但这似乎是正确的,因为我使用了所需的复杂数据类型。
-
【问题讨论】: