From dd6a6edc267535b970dcfce64c8a58f6e2874334 Mon Sep 17 00:00:00 2001 From: loneylee Date: Thu, 12 Sep 2024 11:04:30 +0800 Subject: [PATCH] fix tpcds --- .../SparkFunctionDecimalBinaryArithmetic.cpp | 73 ++++++++++++++++--- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/cpp-ch/local-engine/Functions/SparkFunctionDecimalBinaryArithmetic.cpp b/cpp-ch/local-engine/Functions/SparkFunctionDecimalBinaryArithmetic.cpp index 6b4b47a05fa77..25321f68d9752 100644 --- a/cpp-ch/local-engine/Functions/SparkFunctionDecimalBinaryArithmetic.cpp +++ b/cpp-ch/local-engine/Functions/SparkFunctionDecimalBinaryArithmetic.cpp @@ -202,6 +202,19 @@ struct SparkDecimalBinaryOperation return DecimalUtils::scaleMultiplier(max_scale - right.getScale()); }(); + + bool calculate_with_256 = false; + if constexpr (CalculateWith256) + calculate_with_256 = true; + else + { + auto p1 = left.getPrecision(); + auto p2 = left.getPrecision(); + if (DataTypeDecimal::maxPrecision() < p1 + max_scale - left.getScale() + || DataTypeDecimal::maxPrecision() < p2 + max_scale - right.getScale()) + calculate_with_256 = true; + } + ColumnUInt8::MutablePtr col_null_map_to = ColumnUInt8::create(col_left_size, false); ColumnUInt8::Container * vec_null_map_to = &col_null_map_to->getData(); @@ -217,26 +230,66 @@ struct SparkDecimalBinaryOperation if (col_left && col_right) { - process( - col_left->getData(), col_right->getData(), vec_res, scale_left, scale_right, *vec_null_map_to, resultDataType, max_scale); - return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); + if (calculate_with_256) + { + process( + col_left->getData(), + col_right->getData(), + vec_res, + scale_left, + scale_right, + *vec_null_map_to, + resultDataType, + max_scale); + } + else + { + process( + col_left->getData(), + col_right->getData(), + vec_res, + scale_left, + scale_right, + *vec_null_map_to, + resultDataType, + max_scale); + } } else if (col_left_const && col_right) { LeftFieldType const_left = col_left_const->getValue(); - process( - const_left, col_right->getData(), vec_res, scale_left, scale_right, *vec_null_map_to, resultDataType, max_scale); - return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); + + if (calculate_with_256) + { + process( + const_left, col_right->getData(), vec_res, scale_left, scale_right, *vec_null_map_to, resultDataType, max_scale); + } + else + { + process( + const_left, col_right->getData(), vec_res, scale_left, scale_right, *vec_null_map_to, resultDataType, max_scale); + } } else if (col_left && col_right_const) { RightFieldType const_right = col_right_const->getValue(); - process( - col_left->getData(), const_right, vec_res, scale_left, scale_right, *vec_null_map_to, resultDataType, max_scale); - return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); + if (calculate_with_256) + { + process( + col_left->getData(), const_right, vec_res, scale_left, scale_right, *vec_null_map_to, resultDataType, max_scale); + } + else + { + process( + col_left->getData(), const_right, vec_res, scale_left, scale_right, *vec_null_map_to, resultDataType, max_scale); + } + } + else + { + throw Exception(ErrorCodes::LOGICAL_ERROR, "Not supported."); } - throw Exception(ErrorCodes::LOGICAL_ERROR, "Not supported."); + return ColumnNullable::create(std::move(col_res), std::move(col_null_map_to)); } template