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 a897dbb8d3506f2d65cdbde3bb3f6ce18b40a424
Author: Mihai Budiu <[email protected]>
AuthorDate: Thu Oct 3 11:58:03 2024 -0700

    Return either all or none of the simplified expressions
    
    Signed-off-by: Mihai Budiu <[email protected]>
---
 core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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 17a28cf328..c2a8b56196 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java
@@ -126,9 +126,13 @@ public class RexExecutorImpl implements RexExecutor {
 
   /**
    * Do constant reduction using generated code.
+   * Returns the reduced expressions in `reducedValues`, which
+   * is supposed to be empty on call.
    */
   @Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
       List<RexNode> reducedValues) {
+    // If this is not empty, the reducedValues.clear() call below is wrong.
+    assert reducedValues.isEmpty();
     try {
       String code = compile(rexBuilder, constExps, (list, index, storageType) 
-> {
         throw new UnsupportedOperationException();
@@ -138,9 +142,12 @@ public class RexExecutorImpl implements RexExecutor {
       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);
     }
   }

Reply via email to