From 0ea87fba6f04c423c752475bfffadddbebeecce4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 6 Apr 2025 10:16:11 +0800 Subject: [PATCH] branch-2.1: [Bug][function] fix the string cast jsonb cause null map have not init value #49810 (#49817) Cherry-picked from #49810 Co-authored-by: HappenLee --- be/src/vec/functions/function_cast.h | 12 ++++++------ .../json_functions/test_json_function.out | 5 +++++ .../json_functions/test_json_function.groovy | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/be/src/vec/functions/function_cast.h b/be/src/vec/functions/function_cast.h index cf3ea7b079..5df75b05a5 100644 --- a/be/src/vec/functions/function_cast.h +++ b/be/src/vec/functions/function_cast.h @@ -442,7 +442,7 @@ struct ConvertImpl { // 300 -> 00:03:00 360 will be parse failed , so value maybe null ColumnUInt8::MutablePtr col_null_map_to; ColumnUInt8::Container* vec_null_map_to = nullptr; - col_null_map_to = ColumnUInt8::create(size); + col_null_map_to = ColumnUInt8::create(size, 0); vec_null_map_to = &col_null_map_to->get_data(); for (size_t i = 0; i < size; ++i) { (*vec_null_map_to)[i] = !TimeCast::try_parse_time( @@ -513,7 +513,7 @@ struct ConvertImplToTimeType { // create null column ColumnUInt8::MutablePtr col_null_map_to; - col_null_map_to = ColumnUInt8::create(size); + col_null_map_to = ColumnUInt8::create(size, 0); auto& vec_null_map_to = col_null_map_to->get_data(); UInt32 from_precision = 0; @@ -591,7 +591,7 @@ struct ConvertImplGenericFromString { size_t size = col_from.size(); col_to->reserve(size); - ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(size); + ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(size, 0); ColumnUInt8::Container* vec_null_map_to = &col_null_map_to->get_data(); const bool is_complex = is_complex_type(data_type_to); DataTypeSerDe::FormatOptions format_options; @@ -708,7 +708,7 @@ struct ConvertImplGenericFromJsonb { size_t size = col_from.size(); col_to->reserve(size); - ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(size); + ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(size, 0); ColumnUInt8::Container* vec_null_map_to = &col_null_map_to->get_data(); const bool is_complex = is_complex_type(data_type_to); const bool is_dst_string = is_string_or_fixed_string(data_type_to); @@ -788,7 +788,7 @@ struct ConvertImplGenericToJsonb { auto column_string = ColumnString::create(); JsonbWriter writer; - ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(col_from.size()); + ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(col_from.size(), 0); ColumnUInt8::Container* vec_null_map_to = &col_null_map_to->get_data(); DataTypeSerDe::FormatOptions format_options; format_options.converted_from_string = true; @@ -1539,7 +1539,7 @@ struct StringParsing { ColumnUInt8::MutablePtr col_null_map_to; ColumnUInt8::Container* vec_null_map_to [[maybe_unused]] = nullptr; - col_null_map_to = ColumnUInt8::create(row); + col_null_map_to = ColumnUInt8::create(row, 0); vec_null_map_to = &col_null_map_to->get_data(); const ColumnString::Chars* chars = &col_from_string->get_chars(); 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 bd14394d37..45d1d1b9e0 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 @@ -155,3 +155,8 @@ true -- !sql -- \N +-- !sql -- +\N \N +false \N +true \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 4bd88bf131..20ef0843e3 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 @@ -77,4 +77,6 @@ suite("test_json_function", "arrow_flight_sql") { qt_sql """SELECT JSON_CONTAINS('','1','\$.a')""" qt_sql """SELECT JSON_CONTAINS('""','1','\$.a')""" qt_sql """SELECT JSON_CONTAINS("",'1','\$.a')""" + + qt_sql """select k6, json_extract_string(cast(k7 as json), "\$.a") as x10 from test_query_db.baseall group by k6, x10 order by 1,2; """ }