From 61a1a4dde3475e78c405d955e04110766d209e04 Mon Sep 17 00:00:00 2001 From: Victor Zoubok Date: Mon, 9 Nov 2026 11:33:32 -0700 Subject: [PATCH 1/4] DX-128331: Gandiva: normalize Darwin host triple to macosx so exp10 libcall is available --- cpp/src/gandiva/engine.cc | 37 ++++++++++- cpp/src/gandiva/engine.h | 5 ++ cpp/src/gandiva/engine_llvm_test.cc | 53 ++++++++++++++++ cpp/src/gandiva/tests/projector_test.cc | 82 +++++++++++++++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) diff --git a/cpp/src/gandiva/engine.cc b/cpp/src/gandiva/engine.cc index 13939981b98c..c868f059acb8 100644 --- a/cpp/src/gandiva/engine.cc +++ b/cpp/src/gandiva/engine.cc @@ -112,9 +112,44 @@ namespace gandiva { +// Oldest macOS release for each architecture. Used as a floor and as the fallback when +// the Darwin kernel version is missing or can't be converted. +constexpr unsigned kMinMacOSMajorArm64 = 11; // first Apple Silicon release +constexpr unsigned kMinMacOSMinorArm64 = 0; +constexpr unsigned kMinMacOSMajorX86 = 10; +constexpr unsigned kMinMacOSMinorX86 = 15; + extern const unsigned char kPrecompiledBitcode[]; extern const size_t kPrecompiledBitcodeSize; +llvm::Triple NormalizeDarwinTriple(llvm::Triple triple) { + // LLVM's default host triple names the OS "darwin", but LLVM only + // enables macOS libcalls (e.g. __exp10 for llvm.exp10) for the "macosx" OS. + // clang's driver does this rewrite; the JIT does not, so do it here. + if (triple.getOS() != llvm::Triple::Darwin) { + return triple; + } + + const llvm::VersionTuple min_version = + triple.isAArch64() ? llvm::VersionTuple(kMinMacOSMajorArm64, kMinMacOSMinorArm64) + : llvm::VersionTuple(kMinMacOSMajorX86, kMinMacOSMinorX86); + + // Only "at least macOS 10.9" matters for libcall selection, so an approximate + // kernel->macOS mapping is acceptable here. + llvm::VersionTuple version = min_version; + llvm::VersionTuple converted; + if (triple.getMacOSXVersion(converted) && converted >= min_version) { + version = converted; + } + + // getMacOSXVersion() leaves the minor unset for darwin20+; print it as "11.0", not + // "11". + const unsigned minor = version.getMinor().value_or(0); + triple.setOSName("macosx" + + llvm::VersionTuple(version.getMajor(), minor).getAsString()); + return triple; +} + namespace { std::once_flag llvm_init_once_flag; @@ -135,7 +170,7 @@ arrow::Result AsArrowResult(llvm::Expected& expected, Result MakeTargetMachineBuilder( const Configuration& conf) { llvm::orc::JITTargetMachineBuilder jtmb( - (llvm::Triple(llvm::sys::getDefaultTargetTriple()))); + NormalizeDarwinTriple(llvm::Triple(llvm::sys::getDefaultTargetTriple()))); if (conf.target_host_cpu()) { jtmb.setCPU(cpu_name.str()); jtmb.addFeatures(cpu_attrs); diff --git a/cpp/src/gandiva/engine.h b/cpp/src/gandiva/engine.h index 23fc366fe15a..b172918a9b3a 100644 --- a/cpp/src/gandiva/engine.h +++ b/cpp/src/gandiva/engine.h @@ -41,6 +41,11 @@ class LLJIT; namespace gandiva { +/// \brief Rewrite a "darwin" host triple to "macosx". +/// LLVM only enables macOS libcalls (e.g. __exp10) for the "macosx" OS name. +/// Non-Darwin triples are returned unchanged. +GANDIVA_EXPORT llvm::Triple NormalizeDarwinTriple(llvm::Triple triple); + /// \brief LLVM Execution engine wrapper. class GANDIVA_EXPORT Engine { public: diff --git a/cpp/src/gandiva/engine_llvm_test.cc b/cpp/src/gandiva/engine_llvm_test.cc index 78f468d13fa1..9b9e18642904 100644 --- a/cpp/src/gandiva/engine_llvm_test.cc +++ b/cpp/src/gandiva/engine_llvm_test.cc @@ -28,6 +28,10 @@ using add_vector_func_t = int64_t (*)(int64_t*, int); class TestEngine : public ::testing::Test { protected: + static std::string Normalize(const std::string& triple) { + return NormalizeDarwinTriple(llvm::Triple(triple)).str(); + } + std::string BuildVecAdd(Engine* gdv_engine) { auto types = gdv_engine->types(); llvm::IRBuilder<>* builder = gdv_engine->ir_builder(); @@ -133,4 +137,53 @@ TEST_F(TestEngine, TestAddOptimised) { EXPECT_EQ(add_func(my_array, 5), 17); } +TEST_F(TestEngine, NormalizeDarwinTripleDarwinBecomesMacOSX) { + llvm::Triple arm = NormalizeDarwinTriple(llvm::Triple("arm64-apple-darwin27.2.0")); + EXPECT_EQ(arm.getOS(), llvm::Triple::MacOSX); + EXPECT_TRUE(arm.isAArch64()); + llvm::VersionTuple v; + ASSERT_TRUE(arm.getMacOSXVersion(v)); + EXPECT_GE(v, llvm::VersionTuple(11, 0)); + + EXPECT_EQ(Normalize("x86_64-apple-darwin19.0.0"), "x86_64-apple-macosx10.15"); +} + +TEST_F(TestEngine, NormalizeDarwinTripleUnversionedOrOldUsesFloor) { + EXPECT_EQ(Normalize("arm64-apple-darwin"), "arm64-apple-macosx11.0"); + EXPECT_EQ(Normalize("arm64-apple-darwin8.0.0"), "arm64-apple-macosx11.0"); + EXPECT_EQ(Normalize("x86_64-apple-darwin3.0.0"), "x86_64-apple-macosx10.15"); +} + +TEST_F(TestEngine, NormalizeDarwinTripleOtherTriplesUnchanged) { + EXPECT_EQ(Normalize("arm64-apple-macosx26.0.0"), "arm64-apple-macosx26.0.0"); + EXPECT_EQ(Normalize("x86_64-unknown-linux-gnu"), "x86_64-unknown-linux-gnu"); + EXPECT_EQ(Normalize("aarch64-unknown-linux-musl"), "aarch64-unknown-linux-musl"); +} + +TEST_F(TestEngine, NormalizeDarwinTripleFloorBoundary) { + // darwin19 is macOS 10.15: x86 stays at its floor, arm64 is raised to 11.0 + EXPECT_EQ(Normalize("x86_64-apple-darwin19.0.0"), "x86_64-apple-macosx10.15"); + EXPECT_EQ(Normalize("arm64-apple-darwin19.0.0"), "arm64-apple-macosx11.0"); + EXPECT_EQ(Normalize("arm64-apple-darwin20.0.0"), "arm64-apple-macosx11.0"); +} + +TEST_F(TestEngine, NormalizeDarwinTripleArchAliases) { + EXPECT_EQ(Normalize("aarch64-apple-darwin"), "aarch64-apple-macosx11.0"); + EXPECT_EQ(Normalize("arm64e-apple-darwin"), "arm64e-apple-macosx11.0"); + EXPECT_EQ(Normalize("i386-apple-darwin"), "i386-apple-macosx10.15"); +} + +TEST_F(TestEngine, NormalizeDarwinTripleOtherAppleAndWindowsUnchanged) { + EXPECT_EQ(Normalize("arm64-apple-ios17.0.0"), "arm64-apple-ios17.0.0"); + EXPECT_EQ(Normalize("x86_64-pc-windows-msvc"), "x86_64-pc-windows-msvc"); +} + +TEST_F(TestEngine, NormalizeDarwinTripleIdempotent) { + for (const char* triple : {"arm64-apple-darwin23.1.0", "arm64-apple-darwin", + "x86_64-apple-darwin8", "x86_64-unknown-linux-gnu"}) { + std::string once = Normalize(triple); + EXPECT_EQ(Normalize(once), once) << triple; + } +} + } // namespace gandiva diff --git a/cpp/src/gandiva/tests/projector_test.cc b/cpp/src/gandiva/tests/projector_test.cc index fe60ea9c91ef..ddf0a1a82c73 100644 --- a/cpp/src/gandiva/tests/projector_test.cc +++ b/cpp/src/gandiva/tests/projector_test.cc @@ -48,6 +48,54 @@ class TestProjector : public ::testing::Test { } protected: + // Compiles round(float64, int32) and evaluates it on the inputs. + // On failure the calling test fails (fatally) instead of getting a null result. + void EvaluateRoundFloat64(const std::vector& values, + const std::vector& scales, bool optimize, + std::shared_ptr* result) { + auto field_value = field("value", arrow::float64()); + auto field_scale = field("scale", int32()); + auto schema = arrow::schema({field_value, field_scale}); + auto field_result = field("result", arrow::float64()); + + auto round_fn = + TreeExprBuilder::MakeFunction("round", + {TreeExprBuilder::MakeField(field_value), + TreeExprBuilder::MakeField(field_scale)}, + arrow::float64()); + auto expr = TreeExprBuilder::MakeExpression(round_fn, field_result); + auto configuration = ConfigurationBuilder().build(optimize); + + std::shared_ptr projector; + auto status = Projector::Make(schema, {expr}, configuration, &projector); + ASSERT_TRUE(status.ok()) << status.message(); + + std::vector valid(values.size(), true); + auto in_batch = arrow::RecordBatch::Make( + schema, static_cast(values.size()), + {MakeArrowArrayFloat64(values, valid), MakeArrowArrayInt32(scales, valid)}); + + arrow::ArrayVector outputs; + status = projector->Evaluate(*in_batch, pool_, &outputs); + ASSERT_TRUE(status.ok()) << status.message(); + ASSERT_EQ(outputs.size(), 1u); + *result = outputs.at(0); + } + + // Runs the case with IR optimization off and on, and checks the result each time. + void CheckRoundFloat64(const std::vector& values, + const std::vector& scales, + const std::vector& expected_values) { + auto expected = MakeArrowArrayFloat64( + expected_values, std::vector(expected_values.size(), true)); + for (bool optimize : {false, true}) { + SCOPED_TRACE(optimize ? "optimize=true" : "optimize=false"); + std::shared_ptr result; + ASSERT_NO_FATAL_FAILURE(EvaluateRoundFloat64(values, scales, optimize, &result)); + EXPECT_ARROW_ARRAY_EQUALS(expected, result); + } + } + arrow::MemoryPool* pool_; }; @@ -2024,6 +2072,40 @@ TEST_F(TestProjector, TestCeiling) { EXPECT_ARROW_ARRAY_EQUALS(out_float64, outputs2.at(0)); } +TEST_F(TestProjector, TestRoundFloat64ScaleInLookupTable) { + // Scales served by the lookup table + CheckRoundFloat64({1.26, 2.34}, {1, 1}, {1.3, 2.3}); +} + +TEST_F(TestProjector, TestRoundFloat64ScaleAtTableBoundary) { + // The first scale outside the lookup table (20); values come back unchanged + CheckRoundFloat64({1.26, -1.26}, {20, 20}, {1.26, -1.26}); +} + +TEST_F(TestProjector, TestRoundFloat64LargeScale) { + // Scales well above the table need no rounding + CheckRoundFloat64({1.26, 2.34, -1.26}, {25, 30, 25}, {1.26, 2.34, -1.26}); +} + +TEST_F(TestProjector, TestRoundFloat64NegativeScale) { + // Negative scales are also outside the table; these inputs round to 0 + CheckRoundFloat64({1.26, 2.34}, {-2, -1}, {0.0, 0.0}); +} + +TEST_F(TestProjector, TestRoundFloat64MixedScalesInOneBatch) { + // Table path (1), exp10 path (25, -1) and the table's last entry (19) in one batch + CheckRoundFloat64({1.26, 1.26, 2.5, 1.26}, {1, 25, -1, 19}, {1.3, 1.26, 0.0, 1.26}); +} + +TEST_F(TestProjector, TestRoundFloat64LargeValuesSkipRounding) { + // |x| >= 2^52 / 10^scale is returned unchanged (the DX-90291 overflow guard) + CheckRoundFloat64({1e300, -1e300, 4.5e15}, {1, 1, 1}, {1e300, -1e300, 4.5e15}); +} + +TEST_F(TestProjector, TestRoundFloat64ZeroValue) { + CheckRoundFloat64({0.0, 0.0, 0.0}, {0, 25, -3}, {0.0, 0.0, 0.0}); +} + TEST_F(TestProjector, TestFloor) { // input fields auto field1 = field("f1", arrow::float32()); From 53ff0f1b168f27906e0ec81a388d935289043147 Mon Sep 17 00:00:00 2001 From: Victor Zoubok Date: Tue, 10 Nov 2026 11:34:06 -0700 Subject: [PATCH 2/4] DX-128331: Gandiva: merge 'unchanged' Darwin triple normalization tests --- cpp/src/gandiva/engine_llvm_test.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cpp/src/gandiva/engine_llvm_test.cc b/cpp/src/gandiva/engine_llvm_test.cc index 9b9e18642904..6e28ac5803fc 100644 --- a/cpp/src/gandiva/engine_llvm_test.cc +++ b/cpp/src/gandiva/engine_llvm_test.cc @@ -155,9 +155,15 @@ TEST_F(TestEngine, NormalizeDarwinTripleUnversionedOrOldUsesFloor) { } TEST_F(TestEngine, NormalizeDarwinTripleOtherTriplesUnchanged) { + // Already-macosx triples are left as-is EXPECT_EQ(Normalize("arm64-apple-macosx26.0.0"), "arm64-apple-macosx26.0.0"); + // Non-Darwin Apple OSes + EXPECT_EQ(Normalize("arm64-apple-ios17.0.0"), "arm64-apple-ios17.0.0"); + // Linux EXPECT_EQ(Normalize("x86_64-unknown-linux-gnu"), "x86_64-unknown-linux-gnu"); EXPECT_EQ(Normalize("aarch64-unknown-linux-musl"), "aarch64-unknown-linux-musl"); + // Windows + EXPECT_EQ(Normalize("x86_64-pc-windows-msvc"), "x86_64-pc-windows-msvc"); } TEST_F(TestEngine, NormalizeDarwinTripleFloorBoundary) { @@ -173,11 +179,6 @@ TEST_F(TestEngine, NormalizeDarwinTripleArchAliases) { EXPECT_EQ(Normalize("i386-apple-darwin"), "i386-apple-macosx10.15"); } -TEST_F(TestEngine, NormalizeDarwinTripleOtherAppleAndWindowsUnchanged) { - EXPECT_EQ(Normalize("arm64-apple-ios17.0.0"), "arm64-apple-ios17.0.0"); - EXPECT_EQ(Normalize("x86_64-pc-windows-msvc"), "x86_64-pc-windows-msvc"); -} - TEST_F(TestEngine, NormalizeDarwinTripleIdempotent) { for (const char* triple : {"arm64-apple-darwin23.1.0", "arm64-apple-darwin", "x86_64-apple-darwin8", "x86_64-unknown-linux-gnu"}) { From 5f4b6df09b80b1fa9cd5adb51cdc6b8cc22ee454 Mon Sep 17 00:00:00 2001 From: Victor Zoubok Date: Tue, 10 Nov 2026 12:49:17 -0700 Subject: [PATCH 3/4] DX-128331: Gandiva: document why round(float64, int32) tests cover the exp10 lowering path --- cpp/src/gandiva/tests/projector_test.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp/src/gandiva/tests/projector_test.cc b/cpp/src/gandiva/tests/projector_test.cc index ddf0a1a82c73..fd80b97b1c4c 100644 --- a/cpp/src/gandiva/tests/projector_test.cc +++ b/cpp/src/gandiva/tests/projector_test.cc @@ -48,8 +48,12 @@ class TestProjector : public ::testing::Test { } protected: - // Compiles round(float64, int32) and evaluates it on the inputs. - // On failure the calling test fails (fatally) instead of getting a null result. + // Compiles round(float64, int32) through the Gandiva JIT and evaluates it on the inputs. + // Unlike the native tests in extended_math_ops_test.cc, this compiles the whole + // round_float64_int32, including the powl(10, scale) fallback in get_scale_multiplier, + // which LLVM lowers to exp10. That is what the Darwin triple fix in engine.cc covers. + // The decimal128 round tests in decimal_test.cc use integer arithmetic instead and + // never reach exp10. void EvaluateRoundFloat64(const std::vector& values, const std::vector& scales, bool optimize, std::shared_ptr* result) { @@ -82,7 +86,9 @@ class TestProjector : public ::testing::Test { *result = outputs.at(0); } - // Runs the case with IR optimization off and on, and checks the result each time. + // Runs the case with IR optimization off and on, and checks the result each time. + // Without the Darwin triple fix, compiling round(float64, int32) aborts the process + // on macOS ("no libcall available for fexp10"), whatever the scale values are. void CheckRoundFloat64(const std::vector& values, const std::vector& scales, const std::vector& expected_values) { From 56e049773258de2dc612a75be91176205d31b67b Mon Sep 17 00:00:00 2001 From: Victor Zoubok Date: Wed, 11 Nov 2026 07:25:44 -0700 Subject: [PATCH 4/4] DX-128331: Gandiva: move round(float64, scale) tests to decimal_test.cc --- cpp/src/gandiva/tests/decimal_test.cc | 95 +++++++++++++++++++++++++ cpp/src/gandiva/tests/projector_test.cc | 88 ----------------------- 2 files changed, 95 insertions(+), 88 deletions(-) diff --git a/cpp/src/gandiva/tests/decimal_test.cc b/cpp/src/gandiva/tests/decimal_test.cc index e395452d828c..121ac378977b 100644 --- a/cpp/src/gandiva/tests/decimal_test.cc +++ b/cpp/src/gandiva/tests/decimal_test.cc @@ -43,6 +43,23 @@ class TestDecimal : public ::testing::Test { int32_t scale); protected: + // Compiles round(float64, int32) through the Gandiva JIT and evaluates it on the + // inputs. Unlike the native tests in extended_math_ops_test.cc, this compiles the whole + // round_float64_int32, including the powl(10, scale) fallback in get_scale_multiplier, + // which LLVM lowers to exp10. That is what the Darwin triple fix in engine.cc covers. + // The decimal128 round tests in decimal_test.cc use integer arithmetic instead and + // never reach exp10. + void EvaluateRoundFloat64(const std::vector& values, + const std::vector& scales, bool optimize, + std::shared_ptr* result); + + // Runs the case with IR optimization off and on, and checks the result each time. + // Without the Darwin triple fix, compiling round(float64, int32) aborts the process + // on macOS ("no libcall available for fexp10"), whatever the scale values are. + void CheckRoundFloat64(const std::vector& values, + const std::vector& scales, + const std::vector& expected_values); + arrow::MemoryPool* pool_; }; @@ -67,6 +84,50 @@ std::vector TestDecimal::MakeDecimalVector(std::vector return ret; } +void TestDecimal::EvaluateRoundFloat64(const std::vector& values, + const std::vector& scales, bool optimize, + std::shared_ptr* result) { + auto field_value = arrow::field("value", arrow::float64()); + auto field_scale = arrow::field("scale", arrow::int32()); + auto schema = arrow::schema({field_value, field_scale}); + auto field_result = arrow::field("result", arrow::float64()); + + auto round_fn = TreeExprBuilder::MakeFunction( + "round", + {TreeExprBuilder::MakeField(field_value), TreeExprBuilder::MakeField(field_scale)}, + arrow::float64()); + auto expr = TreeExprBuilder::MakeExpression(round_fn, field_result); + auto configuration = ConfigurationBuilder().build(optimize); + + std::shared_ptr projector; + auto status = Projector::Make(schema, {expr}, configuration, &projector); + ASSERT_TRUE(status.ok()) << status.message(); + + std::vector valid(values.size(), true); + auto in_batch = arrow::RecordBatch::Make( + schema, static_cast(values.size()), + {MakeArrowArrayFloat64(values, valid), MakeArrowArrayInt32(scales, valid)}); + + arrow::ArrayVector outputs; + status = projector->Evaluate(*in_batch, pool_, &outputs); + ASSERT_TRUE(status.ok()) << status.message(); + ASSERT_EQ(outputs.size(), 1u); + *result = outputs.at(0); +} + +void TestDecimal::CheckRoundFloat64(const std::vector& values, + const std::vector& scales, + const std::vector& expected_values) { + auto expected = MakeArrowArrayFloat64(expected_values, + std::vector(expected_values.size(), true)); + for (bool optimize : {false, true}) { + SCOPED_TRACE(optimize ? "optimize=true" : "optimize=false"); + std::shared_ptr result; + ASSERT_NO_FATAL_FAILURE(EvaluateRoundFloat64(values, scales, optimize, &result)); + EXPECT_ARROW_ARRAY_EQUALS(expected, result); + } +} + TEST_F(TestDecimal, CastLargeBatch) { // Allocating decimal return slots in the record loop can exhaust the stack // when optimization is disabled. A single int32-to-decimal cast is sufficient. @@ -1349,4 +1410,38 @@ TEST_F(TestDecimal, TestCastDecimalVarCharInvalidInputInvalidOutput) { ASSERT_NOT_OK(status); ASSERT_THAT(status.message(), ::testing::HasSubstr("not a valid decimal128 number")); } + +TEST_F(TestDecimal, TestRoundFloat64ScaleInLookupTable) { + // Scales served by the lookup table + CheckRoundFloat64({1.26, 2.34}, {1, 1}, {1.3, 2.3}); +} + +TEST_F(TestDecimal, TestRoundFloat64ScaleAtTableBoundary) { + // The first scale outside the lookup table (20); values come back unchanged + CheckRoundFloat64({1.26, -1.26}, {20, 20}, {1.26, -1.26}); +} + +TEST_F(TestDecimal, TestRoundFloat64LargeScale) { + // Scales well above the table need no rounding + CheckRoundFloat64({1.26, 2.34, -1.26}, {25, 30, 25}, {1.26, 2.34, -1.26}); +} + +TEST_F(TestDecimal, TestRoundFloat64NegativeScale) { + // Negative scales are also outside the table; these inputs round to 0 + CheckRoundFloat64({1.26, 2.34}, {-2, -1}, {0.0, 0.0}); +} + +TEST_F(TestDecimal, TestRoundFloat64MixedScalesInOneBatch) { + // Table path (1), exp10 path (25, -1) and the table's last entry (19) in one batch + CheckRoundFloat64({1.26, 1.26, 2.5, 1.26}, {1, 25, -1, 19}, {1.3, 1.26, 0.0, 1.26}); +} + +TEST_F(TestDecimal, TestRoundFloat64LargeValuesSkipRounding) { + // |x| >= 2^52 / 10^scale is returned unchanged (the DX-90291 overflow guard) + CheckRoundFloat64({1e300, -1e300, 4.5e15}, {1, 1, 1}, {1e300, -1e300, 4.5e15}); +} + +TEST_F(TestDecimal, TestRoundFloat64ZeroValue) { + CheckRoundFloat64({0.0, 0.0, 0.0}, {0, 25, -3}, {0.0, 0.0, 0.0}); +} } // namespace gandiva diff --git a/cpp/src/gandiva/tests/projector_test.cc b/cpp/src/gandiva/tests/projector_test.cc index fd80b97b1c4c..fe60ea9c91ef 100644 --- a/cpp/src/gandiva/tests/projector_test.cc +++ b/cpp/src/gandiva/tests/projector_test.cc @@ -48,60 +48,6 @@ class TestProjector : public ::testing::Test { } protected: - // Compiles round(float64, int32) through the Gandiva JIT and evaluates it on the inputs. - // Unlike the native tests in extended_math_ops_test.cc, this compiles the whole - // round_float64_int32, including the powl(10, scale) fallback in get_scale_multiplier, - // which LLVM lowers to exp10. That is what the Darwin triple fix in engine.cc covers. - // The decimal128 round tests in decimal_test.cc use integer arithmetic instead and - // never reach exp10. - void EvaluateRoundFloat64(const std::vector& values, - const std::vector& scales, bool optimize, - std::shared_ptr* result) { - auto field_value = field("value", arrow::float64()); - auto field_scale = field("scale", int32()); - auto schema = arrow::schema({field_value, field_scale}); - auto field_result = field("result", arrow::float64()); - - auto round_fn = - TreeExprBuilder::MakeFunction("round", - {TreeExprBuilder::MakeField(field_value), - TreeExprBuilder::MakeField(field_scale)}, - arrow::float64()); - auto expr = TreeExprBuilder::MakeExpression(round_fn, field_result); - auto configuration = ConfigurationBuilder().build(optimize); - - std::shared_ptr projector; - auto status = Projector::Make(schema, {expr}, configuration, &projector); - ASSERT_TRUE(status.ok()) << status.message(); - - std::vector valid(values.size(), true); - auto in_batch = arrow::RecordBatch::Make( - schema, static_cast(values.size()), - {MakeArrowArrayFloat64(values, valid), MakeArrowArrayInt32(scales, valid)}); - - arrow::ArrayVector outputs; - status = projector->Evaluate(*in_batch, pool_, &outputs); - ASSERT_TRUE(status.ok()) << status.message(); - ASSERT_EQ(outputs.size(), 1u); - *result = outputs.at(0); - } - - // Runs the case with IR optimization off and on, and checks the result each time. - // Without the Darwin triple fix, compiling round(float64, int32) aborts the process - // on macOS ("no libcall available for fexp10"), whatever the scale values are. - void CheckRoundFloat64(const std::vector& values, - const std::vector& scales, - const std::vector& expected_values) { - auto expected = MakeArrowArrayFloat64( - expected_values, std::vector(expected_values.size(), true)); - for (bool optimize : {false, true}) { - SCOPED_TRACE(optimize ? "optimize=true" : "optimize=false"); - std::shared_ptr result; - ASSERT_NO_FATAL_FAILURE(EvaluateRoundFloat64(values, scales, optimize, &result)); - EXPECT_ARROW_ARRAY_EQUALS(expected, result); - } - } - arrow::MemoryPool* pool_; }; @@ -2078,40 +2024,6 @@ TEST_F(TestProjector, TestCeiling) { EXPECT_ARROW_ARRAY_EQUALS(out_float64, outputs2.at(0)); } -TEST_F(TestProjector, TestRoundFloat64ScaleInLookupTable) { - // Scales served by the lookup table - CheckRoundFloat64({1.26, 2.34}, {1, 1}, {1.3, 2.3}); -} - -TEST_F(TestProjector, TestRoundFloat64ScaleAtTableBoundary) { - // The first scale outside the lookup table (20); values come back unchanged - CheckRoundFloat64({1.26, -1.26}, {20, 20}, {1.26, -1.26}); -} - -TEST_F(TestProjector, TestRoundFloat64LargeScale) { - // Scales well above the table need no rounding - CheckRoundFloat64({1.26, 2.34, -1.26}, {25, 30, 25}, {1.26, 2.34, -1.26}); -} - -TEST_F(TestProjector, TestRoundFloat64NegativeScale) { - // Negative scales are also outside the table; these inputs round to 0 - CheckRoundFloat64({1.26, 2.34}, {-2, -1}, {0.0, 0.0}); -} - -TEST_F(TestProjector, TestRoundFloat64MixedScalesInOneBatch) { - // Table path (1), exp10 path (25, -1) and the table's last entry (19) in one batch - CheckRoundFloat64({1.26, 1.26, 2.5, 1.26}, {1, 25, -1, 19}, {1.3, 1.26, 0.0, 1.26}); -} - -TEST_F(TestProjector, TestRoundFloat64LargeValuesSkipRounding) { - // |x| >= 2^52 / 10^scale is returned unchanged (the DX-90291 overflow guard) - CheckRoundFloat64({1e300, -1e300, 4.5e15}, {1, 1, 1}, {1e300, -1e300, 4.5e15}); -} - -TEST_F(TestProjector, TestRoundFloat64ZeroValue) { - CheckRoundFloat64({0.0, 0.0, 0.0}, {0, 25, -3}, {0.0, 0.0, 0.0}); -} - TEST_F(TestProjector, TestFloor) { // input fields auto field1 = field("f1", arrow::float32());