mirror of
https://github.com/apache/impala.git
synced 2026-01-09 06:05:09 -05:00
This patch implements the same function as Hive UDF get_json_object.
We reuse RapidJson to parse the json string. In order to track the
memory used in RapidJson, we wrap FunctionContext into an allocator.
get_json_object accepts two parameters: a json string and a selector
(json path). We parse the json string into a Document tree and then
perform BFS according to the selector. For example, to process
get_json_object('[{\"a\":1}, {\"a\":2}, {\"a\":3}]', '$[*].a'),
we first perform '$[*]' to extract all the items in the root array.
Then we get a queue consists of {a:1},{a:2},{a:3} and perform '.a'
selector on all values in the queue. The final results is 1,2,3 in the
queue. As there're multiple results, they should be encapsulated into
an array. The output results is a string of '[1,2,3]'.
More examples can be found in expr-test.cc.
Test:
* Add unit tests in expr-test
* Add e2e tests in exprs.test
* Add tests in test_alloc_fail.py to check handling of out of memory
Change-Id: I6a9d3598cb3beca0865a7edb094f3a5b602dbd2f
Reviewed-on: http://gerrit.cloudera.org:8080/10950
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
68 lines
2.0 KiB
Plaintext
68 lines
2.0 KiB
Plaintext
====
|
|
---- QUERY
|
|
# Due to somewhat non-determinstic way memory allocation happens in Impala now,
|
|
# we will just check to make sure the exception is a memory allocation failure.
|
|
select group_concat(l_comment) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
select min(l_comment) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
select max(l_comment) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
select rank() over (partition by l_orderkey order by l_commitdate) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
select first_value(l_comment) over (partition by l_orderkey order by l_commitdate) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
select last_value(l_comment) over (partition by l_orderkey order by l_commitdate) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
select cast(l_comment as char(120)) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
# This aims to exercise malloc() failure in the Serialize() function of appx_median() but
|
|
# allocation can sometimes fail in the Init() functions as well.
|
|
select appx_median(l_quantity), appx_median(l_discount) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
# This aims to exercise malloc() failure in the Serialize() functions of distinctpc() and
|
|
# ndv() but allocation can sometimes fail in the Init() functions as well.
|
|
select ndv(l_partkey), distinctpc(l_suppkey) from tpch.lineitem
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
# IMPALA-5252: Verify HiveUdfCall allocations are checked.
|
|
create function replace_string(string) returns string
|
|
location '$FILESYSTEM_PREFIX/test-warehouse/impala-hive-udfs.jar'
|
|
symbol='org.apache.impala.ReplaceStringUdf';
|
|
select replace_string(l_comment) from tpch.lineitem limit 10;
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|
|
---- QUERY
|
|
with t as (select '[0,1]' as s union all select '[1,2]' union all select '[2,3]')
|
|
select get_json_object(t.s, '$[0]') from t;
|
|
---- CATCH
|
|
failed to allocate
|
|
====
|