rcongiu/Hive-JSON-Serde — Issue #3: Nested JSON objects with different types
Author: binnyg
Created: 2012-02-27 05:51:33+00:00
State: open

How do you create a table with different types under nested structure? Lets say I have the following JSON object(returned by twitter API). Nested json object(user) has a boolean, string and integer.

{ "id_str" : "1732912097569888868",
"text" : "Like, grow up !",
"user" : {
"default_profile" : false,
"default_profile_image" : false,
"description" : "My profile description",
"favourites_count" : 1,
}
}

This is how I created the table

CREATE EXTERNAL TABLE tweets (
id_str string,
text string,
user map)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://sample-tweets/test-data';

Following works
select id_str, text from tweets;
select id_str, text, user['description'] from tweets;

Following doesn't work for obvious reason. contributors_enabled is a boolean type and hence I get "Caused by: java\.lang\.ClassCastException: java\.lang\.Boolean cannot be cast to java\.lang\.String"
select user['contributors_enabled'] from tweets;

Is there a way to tell hive to treat all columns as Strings? Appreciate your input. Thanks.