From 058c3af4e917babdc29a2a3aaf0446d2d3f2943d Mon Sep 17 00:00:00 2001 From: Hu Shenggang Date: Tue, 23 Sep 2025 10:25:54 +0800 Subject: [PATCH] [fix](function) A crash caused by nullptr in json_exists_path --- be/src/vec/functions/function_jsonb.cpp | 2 +- .../json_functions/test_json_exists_path.out | 5 +++ .../test_json_exists_path.groovy | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/be/src/vec/functions/function_jsonb.cpp b/be/src/vec/functions/function_jsonb.cpp index 7d83fa4c9beb91..de2b52480a99f3 100644 --- a/be/src/vec/functions/function_jsonb.cpp +++ b/be/src/vec/functions/function_jsonb.cpp @@ -727,7 +727,7 @@ class FunctionJsonbExtractPath : public IFunction { VectorizedUtils::update_null_map(*result_null_map, *path_null_map, path_const); } - if (0 == simd::count_zero_num(reinterpret_cast(data_null_map->data()), + if (0 == simd::count_zero_num(reinterpret_cast(result_null_map->data()), input_rows_count)) { return create_all_null_result(); } diff --git a/regression-test/data/query_p0/sql_functions/json_functions/test_json_exists_path.out b/regression-test/data/query_p0/sql_functions/json_functions/test_json_exists_path.out index 31f5da434da6f7..ec932f45fbf90a 100644 --- a/regression-test/data/query_p0/sql_functions/json_functions/test_json_exists_path.out +++ b/regression-test/data/query_p0/sql_functions/json_functions/test_json_exists_path.out @@ -117,3 +117,8 @@ true 12 \N $.k2 \N 13 \N $.k3 \N +-- !test_all_null2 -- +2 {"k1":"v31","k2":{"sub_key":1234.56}} \N \N +4 {"k1":"v31","k2":300} \N \N +6 {"k1":"v31","k2":300} \N \N + diff --git a/regression-test/suites/query_p0/sql_functions/json_functions/test_json_exists_path.groovy b/regression-test/suites/query_p0/sql_functions/json_functions/test_json_exists_path.groovy index dedf9bb91f6e32..317523f51fdf57 100644 --- a/regression-test/suites/query_p0/sql_functions/json_functions/test_json_exists_path.groovy +++ b/regression-test/suites/query_p0/sql_functions/json_functions/test_json_exists_path.groovy @@ -163,6 +163,38 @@ suite("test_json_exists_path") { exception "Invalid Json Path for value: \$." } + sql """ + drop table if exists json_exists_path_test2; + """ + + sql """ + create table json_exists_path_test2 ( + id int, + json_col json not null, + json_path string + ) distributed by hash(id) buckets 1 properties("replication_num" = "1"); + """ + + sql """ + insert into json_exists_path_test2 values + (1, '{"k1":"v31","k2":300}', '\$.k1'), + (2, '{"k1":"v31","k2":{"sub_key": 1234.56}}', null), + (3, '{"k1":"v31","k2": null}', '\$.k2'), + (4, '{"k1":"v31","k2":300}', null), + (5, '{"id": 123, "name": "doris"}', '\$.'), + (6, '{"k1":"v31","k2":300}', null), + (7, '{"k1":"v31","k2":{"sub_key": 1234.56}}', null); + """ + + qt_test_all_null2 """ + select + id + , json_col + , json_path + , json_exists_path(json_col, json_path) + from json_exists_path_test2 where id % 2 = 0 order by id + """ + test { sql """ select json_exists_path(json_col_non_null, '\$.') from json_exists_path_test where id = 5;