[Bug](Function) fix json contains with empty value (#36320) (#36418)

This commit is contained in:
lihangyu
2024-06-18 10:20:45 +08:00
committed by GitHub
parent 4ae8607b2e
commit 4a117800ca
3 changed files with 18 additions and 2 deletions

View File

@ -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;

View File

@ -146,3 +146,12 @@ true
-- !sql --
true
-- !sql --
\N
-- !sql --
\N
-- !sql --
\N

View File

@ -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')"""
}