Skip to content

Commit

Permalink
[bugfix]json_length() BE crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitrs1983 committed Mar 12, 2024
1 parent f7776bb commit 3c62ebe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions be/src/vec/functions/function_jsonb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,8 @@ struct JsonbLengthUtil {
MutableColumnPtr res = return_type->create_column();

for (size_t i = 0; i < input_rows_count; ++i) {
if (jsonb_data_column->is_null_at(i) || path_column->is_null_at(i)) {
if (jsonb_data_column->is_null_at(i) || path_column->is_null_at(i) ||
(jsonb_data_column->get_data_at(i).size == 0)) {
null_map->get_data()[i] = 1;
res->insert_data(nullptr, 0);
continue;
Expand All @@ -1100,7 +1101,7 @@ struct JsonbLengthUtil {
// doc is NOT necessary to be deleted since JsonbDocument will not allocate memory
JsonbDocument* doc = JsonbDocument::createDocument(jsonb_value.data, jsonb_value.size);
JsonbValue* value = doc->getValue()->findValue(path, nullptr);
if (UNLIKELY(jsonb_value.size == 0 || !value)) {
if (UNLIKELY(!value)) {
null_map->get_data()[i] = 1;
res->insert_data(nullptr, 0);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7494,6 +7494,9 @@ false
-- !sql_json_length --
2

-- !sql_json_length --
\N

-- !select_length --
1 \N \N
2 null 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ suite("test_jsonb_load_and_function", "p0") {
qt_sql_json_length """SELECT json_length('{"k1":"v31","k2":300}')"""
qt_sql_json_length """SELECT json_length('{"a.b.c":{"k1.a1":"v31", "k2": 300},"a":"niu"}')"""
qt_sql_json_length """SELECT json_length('{"a":{"k1.a1":"v31", "k2": 300},"b":"niu"}','\$.a')"""
qt_sql_json_length """SELECT json_length('abc','\$.k1')"""

qt_select_length """SELECT id, j, json_length(j) FROM ${testTable} ORDER BY id"""
qt_select_length """SELECT id, j, json_length(j, '\$[1]') FROM ${testTable} ORDER BY id"""
Expand Down

0 comments on commit 3c62ebe

Please sign in to comment.