From 024d898b0e2596736def31d22598f49c60ce4e64 Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Sat, 5 Oct 2024 09:09:14 +0000 Subject: [PATCH] Backport #69787 to 24.8: Fix 'Bad get' in maxMap state serialization --- src/AggregateFunctions/AggregateFunctionSumMap.cpp | 5 +++-- .../03237_max_map_state_decimal_serialization.reference | 1 + .../03237_max_map_state_decimal_serialization.sql | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/03237_max_map_state_decimal_serialization.reference create mode 100644 tests/queries/0_stateless/03237_max_map_state_decimal_serialization.sql diff --git a/src/AggregateFunctions/AggregateFunctionSumMap.cpp b/src/AggregateFunctions/AggregateFunctionSumMap.cpp index 9a94c3dfe1a..099f110b775 100644 --- a/src/AggregateFunctions/AggregateFunctionSumMap.cpp +++ b/src/AggregateFunctions/AggregateFunctionSumMap.cpp @@ -298,12 +298,13 @@ public: Field value = values[col_idx]; /// Compatibility with previous versions. - if (value.getType() == Field::Types::Decimal32) + WhichDataType value_type(values_types[col_idx]); + if (value_type.isDecimal32()) { auto source = value.safeGet>(); value = DecimalField(source.getValue(), source.getScale()); } - else if (value.getType() == Field::Types::Decimal64) + else if (value_type.isDecimal64()) { auto source = value.safeGet>(); value = DecimalField(source.getValue(), source.getScale()); diff --git a/tests/queries/0_stateless/03237_max_map_state_decimal_serialization.reference b/tests/queries/0_stateless/03237_max_map_state_decimal_serialization.reference new file mode 100644 index 00000000000..31b1da2af43 --- /dev/null +++ b/tests/queries/0_stateless/03237_max_map_state_decimal_serialization.reference @@ -0,0 +1 @@ +{"x":"\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"} diff --git a/tests/queries/0_stateless/03237_max_map_state_decimal_serialization.sql b/tests/queries/0_stateless/03237_max_map_state_decimal_serialization.sql new file mode 100644 index 00000000000..8742f470cf0 --- /dev/null +++ b/tests/queries/0_stateless/03237_max_map_state_decimal_serialization.sql @@ -0,0 +1 @@ +select maxMapState([0], [toDateTime64(0, 0)]) as x format JSONEachRow;