Hive 中的复合数据结构简介以及一些函数的用法说明

  

get_json_object

A limited version of JSONPath is supported:

·         $ : Root object

·         . : Child operator

·         [] : Subscript operator for array

·         * : Wildcard for []

Syntax not supported that's worth noticing:

·         : Zero length string as key

·         .. : Recursive descent

·         @ : Current object/element

·         () : Script expression

·         ?() : Filter (script) expression.

·         [,] : Union operator

·         [start:end.step] : array slice operator

Example: src_json table is a single column (json), single row table:

+----+

                               json

+----+

{"store":

  {"fruit":\[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],

   "bicycle":{"price":19.95,"color":"red"}

  },

 "email":"amy@only_for_json_udf_test.net",

 "owner":"amy"

}

+----+

The fields of the json object can be extracted using these queries:

hive> SELECT get_json_object(src_json.json, '$.owner') FROM src_json;

amy

 

hive> SELECT get_json_object(src_json.json, '$.store.fruit\[0]') FROM src_json;

{"weight":8,"type":"apple"}

 

hive> SELECT get_json_object(src_json.json, '$.non_exist_key') FROM src_json;

NULL

你可能感兴趣的:(Hive 中的复合数据结构简介以及一些函数的用法说明)