Skip to content

Commit

Permalink
[bugfix]json_length() BE crash fix (#32145)
Browse files Browse the repository at this point in the history
Co-authored-by: Rohit Satardekar <rohitrs1983@gmail.com>
  • Loading branch information
2 people authored and pull[bot] committed Jul 10, 2024
1 parent acd8ebf commit 9875765
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 9875765

Please sign in to comment.