Skip to content

Commit

Permalink
Prevent errors during constant reduction from crashing the compiler
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
mihaibudiu committed Oct 18, 2024
1 parent 11c444e commit af0ff63
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,19 @@ public static RexExecutable getExecutable(RexBuilder rexBuilder, List<RexNode> e
*/
@Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
List<RexNode> reducedValues) {
String code;
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.
// This effectively moves the error from compile time to runtime.
// We could give a warning here if there was a mechanism for warnings.
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 af0ff63

Please sign in to comment.