get_json_object()的用法

2020-06-10  本文已影响0人  大道至简_6a43

hive> select get_json_object('{

    >  "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"

    > }','$.store.fruit[0].weight');

OK

8

Time taken: 0.141 seconds, Fetched: 1 row(s)

hive> select get_json_object('{

    >  "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"

    > }','$.store.fruit[1].type');

OK

pear

hive> select get_json_object('{

    >  "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"

    > }','$.store.fruit.type');

OK

["apple","pear"]

Time taken: 0.137 seconds, Fetched: 1 row(s)

get_json_object中对于外层的直接'$.key.key[index].key2'; index对应数组中第几个json,key2对应数组中json的key;

上一篇下一篇

猜你喜欢

热点阅读