From 85d3679bca2cdc22b5ee47346e26a529c7190c18 Mon Sep 17 00:00:00 2001 From: Hongze Zhang Date: Thu, 8 Apr 2021 21:03:59 +0800 Subject: [PATCH] [NSE-239] Adopt ARROW-7011 --- native-sql-engine/cpp/src/precompile/gandiva.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/native-sql-engine/cpp/src/precompile/gandiva.h b/native-sql-engine/cpp/src/precompile/gandiva.h index f2e6eedaf..e6fff7b94 100644 --- a/native-sql-engine/cpp/src/precompile/gandiva.h +++ b/native-sql-engine/cpp/src/precompile/gandiva.h @@ -40,13 +40,7 @@ T round2(T val, int precision = 2) { } arrow::Decimal128 castDECIMAL(double val, int32_t precision, int32_t scale) { - double dVal = (double)val; - int charsNeeded = 1 + snprintf(NULL, 0, "%.*f", (int)scale, dVal); - char* buffer = reinterpret_cast(malloc(charsNeeded)); - snprintf(buffer, sizeof(buffer), "%.*f", (int)scale, nextafter(val, val + 0.5)); - auto decimal_str = std::string(buffer); - free(buffer); - return arrow::Decimal128::FromString(decimal_str).ValueOrDie(); + return arrow::Decimal128::FromReal(val, precision, scale).ValueOrDie(); } std::string castStringFromDecimal(arrow::Decimal128 val, int32_t scale) {