Repository navigation
fix(isthmus)!: honor decimal arithmetic overflow options #1393
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
Merged
nielspardon
merged 10 commits into
substrait-io:main
from
alexandrefimov:decimal-options-1173
Oct 9, 2026
+391
−1
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3880d2a
fix(isthmus)!: preserve concat null handling
alexandrefimov 50d3c0b
fix(isthmus)!: preserve supported string function options
alexandrefimov 15983c3
fix(isthmus): validate string options against the selected operator
alexandrefimov ce8163b
fix(isthmus)!: honor decimal arithmetic overflow options
alexandrefimov 4e90106
refactor(isthmus): share scalar option policies across both directions
alexandrefimov d296fd6
Merge shared scalar option policies into decimal arithmetic
alexandrefimov 38c004b
fix(isthmus): retain decimal options after operand promotion
alexandrefimov afb6809
Merge main and shared scalar option policies
alexandrefimov 78b5454
Merge main and address arithmetic option review
alexandrefimov 571c642
Merge main after integer arithmetic options
alexandrefimov 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
81 changes: 81 additions & 0 deletions
81
isthmus/src/main/java/io/substrait/isthmus/expression/DecimalFunctionOptions.java
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package io.substrait.isthmus.expression; | ||
|
|
||
| import io.substrait.expression.Expression; | ||
| import io.substrait.expression.FunctionOption; | ||
| import io.substrait.extension.DefaultExtensionCatalog; | ||
| import io.substrait.extension.SimpleExtension.ScalarFunctionVariant; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import org.apache.calcite.rex.RexCall; | ||
| import org.apache.calcite.sql.SqlOperator; | ||
| import org.apache.calcite.sql.type.SqlTypeName; | ||
|
|
||
| /** Decimal arithmetic overflow options supported by Calcite. */ | ||
| final class DecimalFunctionOptions implements ScalarFunctionOptionPolicy { | ||
|
|
||
| private static SqlOperator operator(ScalarFunctionVariant function) { | ||
| if (!DefaultExtensionCatalog.FUNCTIONS_ARITHMETIC_DECIMAL.equals(function.urn()) | ||
| || !function.key().equals(function.name() + ":dec_dec") | ||
| || !List.of("add", "subtract", "multiply", "divide", "modulus").contains(function.name())) { | ||
| return null; | ||
| } | ||
| return FunctionMappings.SCALAR_SIGS.stream() | ||
| .filter(sig -> sig.name().equals(function.name())) | ||
| .map(FunctionMappings.Sig::operator) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
|
|
||
| @Override | ||
| public List<FunctionOption> forCall(RexCall call, ScalarFunctionVariant function) { | ||
| SqlOperator operator = operator(function); | ||
| if (operator == null | ||
| || call.getOperator() != operator | ||
| || call.getType().getSqlTypeName() != SqlTypeName.DECIMAL) { | ||
| return List.of(); | ||
| } | ||
| // Calcite's BigDecimal arithmetic does not enforce the declared result precision. | ||
| return List.of(FunctionOption.builder().name("overflow").addValues("SILENT").build()); | ||
|
nielspardon marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public SqlOperator resolve(Expression.ScalarFunctionInvocation expression, SqlOperator selected) { | ||
| SqlOperator nativeOperator = operator(expression.declaration()); | ||
| if (nativeOperator == null || expression.options().isEmpty()) { | ||
| return selected; | ||
| } | ||
| if (selected != nativeOperator) { | ||
| throw new UnsupportedOperationException( | ||
| "No decimal option policy for Calcite operator " + selected.getName()); | ||
| } | ||
| // A remainder is bounded by both operands, so valid decimal inputs cannot overflow | ||
| // the spec's modulus result type. The other operators can exceed its precision. | ||
| List<String> supported = | ||
| expression.declaration().name().equals("modulus") | ||
| ? List.of("SILENT", "SATURATE", "ERROR") | ||
| : List.of("SILENT"); | ||
| String previous = null; | ||
| for (FunctionOption option : expression.options()) { | ||
| ScalarFunctionOptionPolicy.requireDeclaredValues(expression, option); | ||
| String name = option.getName().toLowerCase(Locale.ROOT); | ||
| if (!name.equals("overflow")) { | ||
| throw new UnsupportedOperationException("Unsupported decimal arithmetic option: " + name); | ||
| } | ||
| String value = | ||
| option.values().stream() | ||
| .map(v -> v.toUpperCase(Locale.ROOT)) | ||
| .filter(supported::contains) | ||
| .findFirst() | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| .orElseThrow( | ||
| () -> | ||
| new UnsupportedOperationException( | ||
| "Unsupported decimal arithmetic overflow preferences: " | ||
| + option.values())); | ||
| if (previous != null && !previous.equals(value)) { | ||
| throw new UnsupportedOperationException("Conflicting decimal arithmetic option: overflow"); | ||
| } | ||
| previous = value; | ||
| } | ||
| return selected; | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.