diff --git a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala index 833e21b0c254..57b5a09fc1a6 100644 --- a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala +++ b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala @@ -457,4 +457,14 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS )(checkOperatorMatch[ProjectExecTransformer]) } } + + test("test round issue: https://github.com/oap-project/gluten/issues/3462") { + runQueryAndCompare( + "select round(0.41875d * id , 4) from range(10);" + )(checkOperatorMatch[ProjectExecTransformer]) + + runQueryAndCompare( + "select round(0.41875f * id , 4) from range(10);" + )(checkOperatorMatch[ProjectExecTransformer]) + } } diff --git a/cpp-ch/local-engine/Functions/SparkFunctionRoundHalfUp.h b/cpp-ch/local-engine/Functions/SparkFunctionRoundHalfUp.h index 6bd3b04eaeee..01d628c5c63a 100644 --- a/cpp-ch/local-engine/Functions/SparkFunctionRoundHalfUp.h +++ b/cpp-ch/local-engine/Functions/SparkFunctionRoundHalfUp.h @@ -19,50 +19,28 @@ #include -namespace local_engine +namespace local_engine { using namespace DB; - -/// Implementation for round half up. Not vectorized. - -inline float roundHalfUp(float x) -{ - return roundf(x); - - UNREACHABLE(); -} - -inline double roundHalfUp(double x) -{ - return round(x); - - UNREACHABLE(); -} - template class BaseFloatRoundingHalfUpComputation { public: using ScalarType = T; - using VectorType = T; + using VectorType = Float64; static const size_t data_count = 1; - static VectorType load(const ScalarType * in) { return *in; } - static VectorType load1(const ScalarType in) { return in; } - static VectorType store(ScalarType * out, ScalarType val) { return *out = val;} + static VectorType load(const ScalarType * in) { return static_cast(*in); } + static VectorType load1(ScalarType in) { return in; } + static ScalarType store(ScalarType * out, VectorType val) { return *out = static_cast(val); } static VectorType multiply(VectorType val, VectorType scale) { return val * scale; } static VectorType divide(VectorType val, VectorType scale) { return val / scale; } - static VectorType apply(VectorType val){return roundHalfUp(val);} - - static VectorType prepare(size_t scale) - { - return load1(scale); - } + static VectorType apply(VectorType val) { return round(val); } + static VectorType prepare(size_t scale) { return load1(scale); } }; - /** Implementation of low-level round-off functions for floating-point values. */ template @@ -140,9 +118,6 @@ struct FloatRoundingHalfUpImpl }; - - - /** Select the appropriate processing algorithm depending on the scale. */ template