get_json_object不能解析json里面中文的key

get_json_object不能解析json里面中文的key

一般来说不会把json中的key定义为中文,但是如果是中文的话可以用 hive 的json_tuple

json_tuple

A new json_tuple() UDTF is introduced in Hive 0.7. It takes a set of names (keys) and a JSON string, and returns a tuple of values using one function. This is much more efficient than calling GET_JSON_OBJECT to retrieve more than one key from a single JSON string. In any case where a single JSON string would be parsed more than once, your query will be more efficient if you parse it once, which is what JSON_TUPLE is for. As JSON_TUPLE is a UDTF, you will need to use the LATERAL VIEW syntax in order to achieve the same goal.

For example,

select a.timestamp, get_json_object(a.appevents, '$.eventid'), get_json_object(a.appenvets, '$.eventname') from log a;

should be changed to:

select a.timestamp, b.*

from log a lateral view json_tuple(a.appevent, 'eventid''eventname') b as f1, f2;

你可能感兴趣的:(hive)