Repository navigation
GH-55505: Gandiva: normalize Darwin host triple to macosx so exp10 libcall is available #55506
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
Open
lriggs
wants to merge
5
commits into
apache:main
Choose a base branch
from
lriggs:gh-55505
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+165
−29
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
060fdfa
GH-55505: Gandiva: normalize Darwin host triple to macosx so exp10 li…
victor6567758 44a9c8f
Fix syntax error
lriggs 110c524
MakeTargetMachineBuilder now starts from JITTargetMachineBuilder::det…
lriggs 972a875
Fix test to use configuration builder for one-off config.
lriggs 7e4d3a9
Merge remote-tracking branch 'upstream/main' into gh-55505
lriggs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: One of my favorite things to do is test-only first commit that fails the CI however here I still don't know what runs on pull requests before the green light from the overseer |
||
| // 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<double>& values, | ||
| const std::vector<int32_t>& scales, bool optimize, | ||
| std::shared_ptr<arrow::Array>* 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<double>& values, | ||
| const std::vector<int32_t>& scales, | ||
| const std::vector<double>& expected_values); | ||
|
|
||
| arrow::MemoryPool* pool_; | ||
| }; | ||
|
|
||
|
|
@@ -67,6 +84,50 @@ std::vector<Decimal128> TestDecimal::MakeDecimalVector(std::vector<std::string> | |
| return ret; | ||
| } | ||
|
|
||
| void TestDecimal::EvaluateRoundFloat64(const std::vector<double>& values, | ||
| const std::vector<int32_t>& scales, bool optimize, | ||
| std::shared_ptr<arrow::Array>* 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> projector; | ||
| auto status = Projector::Make(schema, {expr}, configuration, &projector); | ||
| ASSERT_TRUE(status.ok()) << status.message(); | ||
|
|
||
| std::vector<bool> valid(values.size(), true); | ||
| auto in_batch = arrow::RecordBatch::Make( | ||
| schema, static_cast<int>(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<double>& values, | ||
| const std::vector<int32_t>& scales, | ||
| const std::vector<double>& expected_values) { | ||
| auto expected = MakeArrowArrayFloat64(expected_values, | ||
| std::vector<bool>(expected_values.size(), true)); | ||
| for (bool optimize : {false, true}) { | ||
| SCOPED_TRACE(optimize ? "optimize=true" : "optimize=false"); | ||
| std::shared_ptr<arrow::Array> 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFeatures() is absent in LLVM 8–9
getCPU() is absent in LLVM 8–12
Do we care? LLVM is from 2021 so we probably do not but I'm not sure if pipelines can enforce this in any way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it matters