Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLUTEN-3462][CH] Fix round mismatch #3494

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading