【问题标题】:Hive :Current token (VALUE_STRING) not numeric, can not use numeric value accessors, while trying to QUERY an external table in hive on nested jsonHive:当前令牌(VALUE_STRING)不是数字,不能使用数值访问器,同时尝试在嵌套 json 上查询 hive 中的外部表
【发布时间】: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 hive


    【解决方案1】:

    问题是您在表定义中将 pharmacy_location 声明为 int,但您的示例数据是一个字符串:“pharmacy_location”:“93”。如果您在表定义中更改它,它应该可以工作。

    【讨论】:

    • 这是问题所在,但计数查询select count(*) from MGPH_APPLICATION2 遇到了同样的错误
    • 如果您能够读取一些记录但在计数期间出错(*)。可能您的 json 数据之间存在不一致。堆栈跟踪是否显示记录?
    • 问题仅出在表定义上,使用正确的数据类型再次创建了表并且它工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    相关资源
    最近更新 更多