Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions be/src/vec/functions/function_jsonb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,16 @@ class FunctionJsonbParseBase : public IFunction {
auto&& [col_from, col_from_is_const] =
unpack_if_const(block.get_by_position(arguments[0]).column);

if (col_from_is_const) {
if (col_from->is_null_at(0)) {
auto col_str = ColumnString::create();
col_str->insert_default();
auto null_map = ColumnUInt8::create(1, 1);
auto nullable_col = ColumnNullable::create(std::move(col_str), std::move(null_map));
if (input_rows_count > 1) {
block.get_by_position(result).column =
ColumnConst::create(std::move(nullable_col), input_rows_count);
} else {
block.get_by_position(result).column = std::move(nullable_col);
}
if (col_from_is_const && col_from->is_null_at(0)) {
auto col_str = ColumnString::create();
col_str->insert_default();
auto null_map = ColumnUInt8::create(1, 1);
auto nullable_col = ColumnNullable::create(std::move(col_str), std::move(null_map));
if (input_rows_count > 1) {
block.get_by_position(result).column =
ColumnConst::create(std::move(nullable_col), input_rows_count);
} else {
block.get_by_position(result).column = std::move(nullable_col);
}
return Status::OK();
}
Expand Down Expand Up @@ -303,7 +301,8 @@ class FunctionJsonbParseBase : public IFunction {
continue;
}

const auto& val = col_from_string->get_data_at(i);
auto index = index_check_const(i, col_from_is_const);
const auto& val = col_from_string->get_data_at(index);
auto st = jsonb_value.from_json_string(val.data, val.size);
if (st.ok()) {
// insert jsonb format data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,27 @@ null
8 123
9 [1,2,3]

-- !parse_from_table_value3 --
1 {}
2 {}
3 {}
4 {}
5 {}
6 {}
7 {}
8 {}
8 {}
9 {}

-- !parse_from_table_value4 --
1 {"name":"Alice2","age":32}
2 {"name":"Bob","age":25}
3 {"name":"Jack","age":28}
4 {"name":"Jim","age":33}
5 \N
6 \N
7 [1,2,3]
8 {"key":"value"}
8 {"key2":"value2"}
9 {"key":"value"}

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ suite("test_json_parse") {
qt_parse_from_table_null "SELECT id, json_parse_error_to_null(json_str) FROM test_json_parse_table ORDER BY id;"
qt_parse_from_table_value1 "SELECT id, json_parse_error_to_value(json_str) FROM test_json_parse_table ORDER BY id;"
qt_parse_from_table_value2 "SELECT id, json_parse_error_to_value(json_str, json_value) FROM test_json_parse_table ORDER BY id;"
qt_parse_from_table_value3 "SELECT id, json_parse_error_to_value('{}', json_value) FROM test_json_parse_table ORDER BY id;"
qt_parse_from_table_value4 "SELECT id, json_parse_error_to_value('{invalied}', json_value) FROM test_json_parse_table ORDER BY id;"

check_fold_consistency "json_parse_error_to_null('{\"key\": \"value\"}')"
check_fold_consistency "json_parse_error_to_null('Invalid JSON')"
Expand Down
Loading