ネストされたJSONに外部ハイブテーブルを照会することができません原因ハイブ:数値ではない現在のトークン(VALUE_STRING)、
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にハイブに外部表を照会しようとしているときに、数値アクセサを使用することはできません
JSON SAの
create external table MGPH_APPLICATION2
(
magic String,
type String,
headers String,
messageSchemaId String,
messageSchema String,
message struct<data:struct<APPLICATION_ID:double,APPLICATION_TYPE_ID:Int,NAME:String,DES CR:String,ACTIVE_STAT:double,PROGRAM_ID:double,HEARTBEATS_ENABLED:Int,pharmacy_location:Int>,beforeData:struct<APPLICATION_ID:double,APPLICATION_TYPE_ID:Int,NAME:String,DESCR:String,ACTIVE_STAT:double,PROGRAM_ID:double,HEARTBEATS_ENABLED:Int,pharmacy_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';
used- CREATE TABLEコマンドを
{"magic": "atMSG", "type": "DT", "headers": null, "messageSchemaId": null, "messageSchema": null, "message": {"data": {"APPLICATION_ID": 1212088666, "APPLICATION_TYPE_ID": 2, "NAME": "Safire Database Job", "DESCR": "Safire Database Job", "ACTIVE_STAT": 1212150529, "PROGRAM_ID": null, "HEARTBEATS_ENABLED": 1, "pharmacy_location": "93"}, "beforeData": {"APPLICATION_ID": 1212088666, "APPLICATION_TYPE_ID": 2, "NAME": "Safire Database Job", "DESCR": "Safire Database Job", "ACTIVE_STAT": 1, "PROGRAM_ID": null, "HEARTBEATS_ENABLED": 1, "pharmacy_location": "93"}, "headers": {"operation": "UPDATE", "changeSequence": "20171012223133000000000000039296745", "timestamp": "2017-10-12T22:31:33.000", "streamPosition": "000006BF4A465F25010000010000B4D20000AA8000100001000006BF4A465682", "transactionId": "000000000000000000000000001A0009"}}}
like-に見えます私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')
しかし、上記で作成したテーブルを照会するために私はそのようなJSON serdeを使用してテーブルを作成したい
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,'pharmacy_location') s as pharmacy_location
where pharmacy_location is null;
のような方法をjsontuple使用してい私のチームは通常のハイブテーブルのように直接クエリを実行できますが、今すぐクエリを実行すると失敗します。
は、私がどの/ nのJSONファイルに存在する場合、私がチェックしたが何もありませんでした、だけでなく単一のレコードで試してみました
何をtry-んでした。
ネストされたjsonのテーブル作成定義(https://community.hortonworks.com/questions/29814/how-to-load-nested-json-file-in-hive-table-using-h.html)を確認しましたが、必要な複雑なデータ型を使用しているので正しいと思われます。 「pharmacy_location」:「93」 -
これは問題でしたが、カウントクエリーで同じエラーが表示されていました。[count(*)from MGPH_APPLICATION2'] – Jim
カウント(*)中にいくつかのレコードを読み取ることができます。おそらく、あなたのjsonデータの間に矛盾があります。スタックトレースはレコードを表示しますか? – hlagos
問題はテーブル定義のみで、正しいデータ型のテーブルを再度作成して機能しました。 – Jim