This is an automated email from the ASF dual-hosted git repository. mbudiu pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 855ad83e561300ef33d8fc1ace3e4649f7832ede Author: Mihai Budiu <[email protected]> AuthorDate: Wed Oct 2 16:34:14 2024 -0700 [CALCITE-6607] RexExecutor can throw during evaluation Signed-off-by: Mihai Budiu <[email protected]> --- .../org/apache/calcite/rex/RexExecutorImpl.java | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java b/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java index b32399b02f..3a894d0fba 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java +++ b/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java @@ -126,25 +126,33 @@ public class RexExecutorImpl implements RexExecutor { /** * 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); } /**
