Skip to content

Commit

Permalink
fix round issue: #3462 (#3494)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyang-li authored Oct 24, 2023
1 parent 157f42c commit edc2c53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
39 changes: 7 additions & 32 deletions cpp-ch/local-engine/Functions/SparkFunctionRoundHalfUp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,28 @@
#include <Functions/FunctionsRound.h>


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 <typename T>
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<VectorType>(*in); }
static VectorType load1(ScalarType in) { return in; }
static ScalarType store(ScalarType * out, VectorType val) { return *out = static_cast<ScalarType>(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 <typename T, ScaleMode scale_mode>
Expand Down Expand Up @@ -140,9 +118,6 @@ struct FloatRoundingHalfUpImpl
};





/** Select the appropriate processing algorithm depending on the scale.
*/
template <typename T, RoundingMode rounding_mode, TieBreakingMode tie_breaking_mode>
Expand Down

0 comments on commit edc2c53

Please sign in to comment.