This is an automated email from the ASF dual-hosted git repository. eldenmoon pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new a9e2a92055e [Bug](Function) fix json contains with empty value (#36320) a9e2a92055e is described below commit a9e2a92055eb98b9cfd6da1fdebbe294aa0b5e25 Author: lihangyu <15605149...@163.com> AuthorDate: Mon Jun 17 10:16:41 2024 +0800 [Bug](Function) fix json contains with empty value (#36320) --- be/src/vec/functions/function_jsonb.cpp | 7 ++++++- .../query_p0/sql_functions/json_functions/test_json_function.out | 9 +++++++++ .../sql_functions/json_functions/test_json_function.groovy | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/be/src/vec/functions/function_jsonb.cpp b/be/src/vec/functions/function_jsonb.cpp index 5618612d278..425145d2408 100644 --- a/be/src/vec/functions/function_jsonb.cpp +++ b/be/src/vec/functions/function_jsonb.cpp @@ -1362,6 +1362,11 @@ struct JsonbContainsUtil { auto jsonb_value1 = jsonb_data1_column->get_data_at(i); auto jsonb_value2 = jsonb_data2_column->get_data_at(i); + if (jsonb_value1.size == 0 || jsonb_value2.size == 0) { + null_map->get_data()[i] = 1; + res->insert_data(nullptr, 0); + continue; + } // doc is NOT necessary to be deleted since JsonbDocument will not allocate memory JsonbDocument* doc1 = JsonbDocument::createDocument(jsonb_value1.data, jsonb_value1.size); @@ -1370,7 +1375,7 @@ struct JsonbContainsUtil { JsonbValue* value1 = doc1->getValue()->findValue(path, nullptr); JsonbValue* value2 = doc2->getValue(); - if (UNLIKELY(jsonb_value1.size == 0 || jsonb_value2.size == 0 || !value1 || !value2)) { + if (!value1 || !value2) { null_map->get_data()[i] = 1; res->insert_data(nullptr, 0); continue; diff --git a/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out b/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out index 2aa6c3e7d3d..bd14394d375 100644 --- a/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out +++ b/regression-test/data/query_p0/sql_functions/json_functions/test_json_function.out @@ -146,3 +146,12 @@ true -- !sql -- true +-- !sql -- +\N + +-- !sql -- +\N + +-- !sql -- +\N + diff --git a/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy b/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy index 0bbbdb9c018..4bd88bf131e 100644 --- a/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/json_functions/test_json_function.groovy @@ -74,5 +74,7 @@ suite("test_json_function", "arrow_flight_sql") { qt_sql "SELECT JSON_CONTAINS('{\"name\": \"John\", \"age\": 30, \"city\": \"New York\", \"hobbies\": [\"reading\", \"travelling\"]}', '{\"age\": 31, \"hobbies\": [\"reading\"]}', '\$');" qt_sql "SELECT JSON_CONTAINS('{\"name\": \"John\", \"age\": 30, \"projects\": [{\"name\": \"Project A\", \"year\": 2020}, {\"name\": \"Project B\", \"year\": 2021}]}', '{\"projects\": [{\"name\": \"Project A\"}]}', '\$');" qt_sql "SELECT JSON_CONTAINS('{\"name\": \"John\", \"age\": 30, \"address\": {\"city\": \"New York\", \"country\": \"USA\"}}', '{\"address\": {\"city\": \"New York\"}}', '\$');" - + qt_sql """SELECT JSON_CONTAINS('','1','\$.a')""" + qt_sql """SELECT JSON_CONTAINS('""','1','\$.a')""" + qt_sql """SELECT JSON_CONTAINS("",'1','\$.a')""" } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org