Skip to content

Commit

Permalink
[CALCITE-6607] RexExecutor can throw during evaluation
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
  • Loading branch information
mihaibudiu committed Oct 23, 2024
1 parent 0c67982 commit 855ad83
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,33 @@ public static RexExecutable getExecutable(RexBuilder rexBuilder, List<RexNode> e

/**
* Do constant reduction using generated code.
*
* @param rexBuilder Builder used to construct expressions
* @param constExps A list of constant expressions
* @param reducedValues An empty list. The function will return
* for each expression on constExps one equivalent
* reduced expression in this list, in the same order.
*/
@Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
List<RexNode> reducedValues) {
String code;
assert reducedValues.isEmpty();
try {
code = compile(rexBuilder, constExps, (list, index, storageType) -> {
String code = compile(rexBuilder, constExps, (list, index, storageType) -> {
throw new UnsupportedOperationException();
});

final RexExecutable executable = new RexExecutable(code, constExps);
executable.setDataContext(dataContext);
executable.reduce(rexBuilder, constExps, reducedValues);
} catch (RuntimeException ex) {
// Give up on reduction and return expressions unchanged.
// Something went wrong during constant reduction (for example,
// we may have attempted a division by zero).
// Give up doing the reduction and return constExps unchanged.
// This effectively moves the error from compile time to runtime.
// We could give a warning here if there was a mechanism for warnings.
reducedValues.clear();
reducedValues.addAll(constExps);
return;
}

final RexExecutable executable = new RexExecutable(code, constExps);
executable.setDataContext(dataContext);
executable.reduce(rexBuilder, constExps, reducedValues);
}

/**
Expand Down

0 comments on commit 855ad83

Please sign in to comment.