rcongiu / Hive-JSON-Serde

Read - Write JSON SerDe for Apache Hive.
Other
732 stars 391 forks source link

Accessing the elements of hive map data type #175

Closed kirankvgit closed 4 years ago

kirankvgit commented 7 years ago

Hi,

This is my input json file contents and I have defined hive tables as shown in below,

{ "confidence": 0.86, "donedate": "2016-12-09 15:58:05.369960", "app_data": {"agent_channel": 0,"agent_clarity": "0.905","agent_emotion": "Positive","client_emotion": "Negative","overall_emotion": "Negative","client_gender": "male", "scorecard": { "CallDrivers": { "Billing": {"temp": "TempValue", "score": 0.0}, "Ordering": {"temp": "TempValue","score": 0.0}, "AccountServices": {"temp": "TempValue", "score": 0.0}, "TechnicalSupport": {"temp": "TempValue", "score": 0.0} } } } }

Hive Table: CREATE EXTERNAL TABLE .voci_test ( confidence double, donedate string, app_data struct<agent_channel:int, agent_clarity:string, agent_emotion:string, client_emotion:string, overall_emotion:string, client_gender:string, scorecard: struct<CallDrivers: map<string, struct<temp:string, score:double>>>> ) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' WITH SERDEPROPERTIES("mapping.end_json" = "end", "ignore.malformed.json" = "true", "dots.in.keys" = "true") STORED AS TEXTFILE LOCATION '/user/xxxxx/voci/test/';

But here are queries results: select size(app_data.scorecard.CallDrivers) from voci_test; --Giving me 4 as expected

select app_data.scorecard.CallDrivers['Billing'].temp from voci_test; --Giving me NULL

select app_data.scorecard.CallDrivers["Billing"] from voci_test; --Giving me NULL

How can access the elements inside the map? here I had stuct defined in side the map as value, but could n;t able to access them,. Any help would be appreciated.

rcongiu commented 7 years ago

Can you attach the files with the json and your create statement ? Using copy and paste is very error prone.

rcongiu commented 4 years ago

closing since I got no answer