Saving all output to "!!{outputDirectory}!!/udf_get_json_object.q.raw". Enter "record" with no arguments to stop it. >>> !run !!{qFileDirectory}!!/udf_get_json_object.q >>> DESCRIBE FUNCTION get_json_object; 'tab_name' 'get_json_object(json_txt, path) - Extract a json object from path ' 1 row selected >>> DESCRIBE FUNCTION EXTENDED get_json_object; 'tab_name' 'get_json_object(json_txt, path) - Extract a json object from path ' 'Extract json object from a json string based on json path specified, and return json string of the extracted json object. It will return null if the input json string is invalid.' 'A limited version of JSONPath 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' '' 16 rows selected >>> >>> CREATE TABLE dest1(c1 STRING) STORED AS TEXTFILE; No rows affected >>> >>> FROM src INSERT OVERWRITE TABLE dest1 SELECT ' abc ' WHERE src.key = 86; '_c0' No rows selected >>> >>> EXPLAIN SELECT get_json_object(src_json.json, '$.owner') FROM src_json; 'Explain' 'ABSTRACT SYNTAX TREE:' ' (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME src_json))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION get_json_object (. (TOK_TABLE_OR_COL src_json) json) '$.owner')))))' '' 'STAGE DEPENDENCIES:' ' Stage-1 is a root stage' ' Stage-0 is a root stage' '' 'STAGE PLANS:' ' Stage: Stage-1' ' Map Reduce' ' Alias -> Map Operator Tree:' ' src_json ' ' TableScan' ' alias: src_json' ' Select Operator' ' expressions:' ' expr: get_json_object(json, '$.owner')' ' type: string' ' outputColumnNames: _col0' ' File Output Operator' ' compressed: false' ' GlobalTableId: 0' ' table:' ' input format: org.apache.hadoop.mapred.TextInputFormat' ' output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' '' ' Stage: Stage-0' ' Fetch Operator' ' limit: -1' '' '' 31 rows selected >>> >>> SELECT get_json_object(src_json.json, '$') FROM src_json; '_c0' '{"store":{"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],"basket":[[1,2,{"b":"y","a":"x"}],[3,4],[5,6]],"book":[{"author":"Nigel Rees","title":"Sayings of the Century","category":"reference","price":8.95},{"author":"Herman Melville","title":"Moby Dick","category":"fiction","price":8.99,"isbn":"0-553-21311-3"},{"author":"J. R. R. Tolkien","title":"The Lord of the Rings","category":"fiction","reader":[{"age":25,"name":"bob"},{"age":26,"name":"jack"}],"price":22.99,"isbn":"0-395-19395-8"}],"bicycle":{"price":19.95,"color":"red"}},"email":"amy@only_for_json_udf_test.net","owner":"amy","zip code":"94025","fb:testid":"1234"}' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.owner'), get_json_object(src_json.json, '$.store') FROM src_json; '_c0','_c1' 'amy','{"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],"basket":[[1,2,{"b":"y","a":"x"}],[3,4],[5,6]],"book":[{"author":"Nigel Rees","title":"Sayings of the Century","category":"reference","price":8.95},{"author":"Herman Melville","title":"Moby Dick","category":"fiction","price":8.99,"isbn":"0-553-21311-3"},{"author":"J. R. R. Tolkien","title":"The Lord of the Rings","category":"fiction","reader":[{"age":25,"name":"bob"},{"age":26,"name":"jack"}],"price":22.99,"isbn":"0-395-19395-8"}],"bicycle":{"price":19.95,"color":"red"}}' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.store.bicycle'), get_json_object(src_json.json, '$.store.book') FROM src_json; '_c0','_c1' '{"price":19.95,"color":"red"}','[{"author":"Nigel Rees","title":"Sayings of the Century","category":"reference","price":8.95},{"author":"Herman Melville","title":"Moby Dick","category":"fiction","price":8.99,"isbn":"0-553-21311-3"},{"author":"J. R. R. Tolkien","title":"The Lord of the Rings","category":"fiction","reader":[{"age":25,"name":"bob"},{"age":26,"name":"jack"}],"price":22.99,"isbn":"0-395-19395-8"}]' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.store.book[0]'), get_json_object(src_json.json, '$.store.book[*]') FROM src_json; '_c0','_c1' '{"author":"Nigel Rees","title":"Sayings of the Century","category":"reference","price":8.95}','[{"author":"Nigel Rees","title":"Sayings of the Century","category":"reference","price":8.95},{"author":"Herman Melville","title":"Moby Dick","category":"fiction","price":8.99,"isbn":"0-553-21311-3"},{"author":"J. R. R. Tolkien","title":"The Lord of the Rings","category":"fiction","reader":[{"age":25,"name":"bob"},{"age":26,"name":"jack"}],"price":22.99,"isbn":"0-395-19395-8"}]' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.store.book[0].category'), get_json_object(src_json.json, '$.store.book[*].category'), get_json_object(src_json.json, '$.store.book[*].isbn'), get_json_object(src_json.json, '$.store.book[*].reader') FROM src_json; '_c0','_c1','_c2','_c3' 'reference','["reference","fiction","fiction"]','["0-553-21311-3","0-395-19395-8"]','[{"age":25,"name":"bob"},{"age":26,"name":"jack"}]' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.store.book[*].reader[0].age'), get_json_object(src_json.json, '$.store.book[*].reader[*].age') FROM src_json; '_c0','_c1' '25','[25,26]' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.store.basket[0][1]'), get_json_object(src_json.json, '$.store.basket[*]'), get_json_object(src_json.json, '$.store.basket[*][0]'), get_json_object(src_json.json, '$.store.basket[0][*]'), get_json_object(src_json.json, '$.store.basket[*][*]'), get_json_object(src_json.json, '$.store.basket[0][2].b'), get_json_object(src_json.json, '$.store.basket[0][*].b') FROM src_json; '_c0','_c1','_c2','_c3','_c4','_c5','_c6' '2','[[1,2,{"b":"y","a":"x"}],[3,4],[5,6]]','1','[1,2,{"b":"y","a":"x"}]','[1,2,{"b":"y","a":"x"},3,4,5,6]','y','["y"]' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.non_exist_key'), get_json_object(src_json.json, '$..no_recursive'), get_json_object(src_json.json, '$.store.book[10]'), get_json_object(src_json.json, '$.store.book[0].non_exist_key'), get_json_object(src_json.json, '$.store.basket[*].non_exist_key'), get_json_object(src_json.json, '$.store.basket[0][*].non_exist_key') FROM src_json; '_c0','_c1','_c2','_c3','_c4','_c5' '','','','','','' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.zip code') FROM src_json; '_c0' '94025' 1 row selected >>> >>> SELECT get_json_object(src_json.json, '$.fb:testid') FROM src_json; '_c0' '1234' 1 row selected >>> !record