This is an automated email from the ASF dual-hosted git repository.

zabetak pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new f768501a91 [CALCITE-7450] Refactor ValuesReduceRuleTest inside 
RelOptRulesTest (addendum)
f768501a91 is described below

commit f768501a91a6de08b73a87842b8644b6781d132b
Author: Darpan <[email protected]>
AuthorDate: Fri Mar 27 09:36:05 2026 +0530

    [CALCITE-7450] Refactor ValuesReduceRuleTest inside RelOptRulesTest 
(addendum)
---
 .../calcite/rel/rules/ValuesReduceRuleTest.java    | 69 ----------------------
 .../org/apache/calcite/test/RelOptRulesTest.java   | 15 +++++
 .../org/apache/calcite/test/RelOptRulesTest.xml    | 12 ++++
 3 files changed, 27 insertions(+), 69 deletions(-)

diff --git 
a/core/src/test/java/org/apache/calcite/rel/rules/ValuesReduceRuleTest.java 
b/core/src/test/java/org/apache/calcite/rel/rules/ValuesReduceRuleTest.java
deleted file mode 100644
index 81472fce76..0000000000
--- a/core/src/test/java/org/apache/calcite/rel/rules/ValuesReduceRuleTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.rel.rules;
-
-import org.apache.calcite.plan.RelOptUtil;
-import org.apache.calcite.plan.hep.HepPlanner;
-import org.apache.calcite.plan.hep.HepProgram;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.sql.parser.SqlParser;
-import org.apache.calcite.tools.FrameworkConfig;
-import org.apache.calcite.tools.Frameworks;
-import org.apache.calcite.tools.Planner;
-
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-/**
- * Tests for {@link ValuesReduceRule}.
- */
-class ValuesReduceRuleTest {
-
-  /** Test case for
-   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7450";>[CALCITE-7450]
-   * ValuesReduceRule incorrectly drops tuples when filter condition is
-   * irreducible</a>.
-   *
-   * <p> {@code RAND()} function, is non-deterministic
-   * therefore not reduced by {@code ReduceExpressionsRule}. */
-  @Test void testFilterWithNonDeterministicConditionDoesNotDropTuples()
-      throws Exception {
-    final FrameworkConfig config = Frameworks.newConfigBuilder()
-        .defaultSchema(Frameworks.createRootSchema(true))
-        .parserConfig(SqlParser.config().withCaseSensitive(false))
-        .build();
-
-    final Planner planner = Frameworks.getPlanner(config);
-    final String sql = "SELECT * FROM (VALUES (0, 1, 2), (3, 4, 5)) "
-        + "AS t(a, b, c) WHERE RAND(t.a) > 0.5";
-    final RelNode planBefore =
-        planner.rel(planner.validate(planner.parse(sql))).rel;
-
-    final HepProgram program = HepProgram.builder()
-        .addRuleInstance(CoreRules.PROJECT_FILTER_VALUES_MERGE)
-        .build();
-    final HepPlanner hepPlanner = new HepPlanner(program);
-    hepPlanner.setRoot(planBefore);
-    final RelNode planAfter = hepPlanner.findBestExp();
-
-    // RAND() is non-deterministic, so the condition cannot be reduced.
-    // The plan must remain unchanged.
-    assertThat(RelOptUtil.toString(planAfter), 
is(RelOptUtil.toString(planBefore)));
-  }
-}
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 5b9b9d8aba..1009d3688e 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -12267,4 +12267,19 @@ private void 
checkLoptOptimizeJoinRule(LoptOptimizeJoinRule rule) {
         .withTopDownGeneralDecorrelate(true)
         .check();
   }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7450";>[CALCITE-7450]
+   * ValuesReduceRule incorrectly drops tuples when filter condition is
+   * irreducible</a>.
+   *
+   * <p>{@code RAND()} is non-deterministic and therefore not reduced by
+   * {@code ReduceExpressionsRule}. The rule must leave the plan unchanged. */
+  @Test void testFilterWithNonDeterministicConditionDoesNotDropTuples() {
+    final String sql = "SELECT * FROM (VALUES (0, 1, 2), (3, 4, 5)) "
+        + "AS t(a, b, c) WHERE RAND(t.a) > 0.5";
+    sql(sql)
+        .withRule(CoreRules.PROJECT_FILTER_VALUES_MERGE)
+        .checkUnchanged();
+  }
 }
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 9cb281d0a5..f04ced869d 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -6058,6 +6058,18 @@ LogicalProject(COMM=[$6])
   LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 }))])
     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+    </Resource>
+  </TestCase>
+  <TestCase name="testFilterWithNonDeterministicConditionDoesNotDropTuples">
+    <Resource name="sql">
+      <![CDATA[SELECT * FROM (VALUES (0, 1, 2), (3, 4, 5)) AS t(a, b, c) WHERE 
RAND(t.a) > 0.5]]>
+    </Resource>
+    <Resource name="planBefore">
+      <![CDATA[
+LogicalProject(A=[$0], B=[$1], C=[$2])
+  LogicalFilter(condition=[>(RAND($0), CAST(0.5:DECIMAL(2, 1)):DOUBLE NOT 
NULL)])
+    LogicalValues(tuples=[[{ 0, 1, 2 }, { 3, 4, 5 }]])
 ]]>
     </Resource>
   </TestCase>

Reply via email to