This is an automated email from the ASF dual-hosted git repository.
hyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 60457b2 [CALCITE-4774] Materialized view recognition fails for
equivalent predicates (dz)
60457b2 is described below
commit 60457b28c890f12cc811528bd4f3b098bc3d00f7
Author: dz <[email protected]>
AuthorDate: Tue Sep 14 15:59:34 2021 +0800
[CALCITE-4774] Materialized view recognition fails for equivalent
predicates (dz)
Close #2514
---
.../apache/calcite/plan/SubstitutionVisitor.java | 2 ++
.../MaterializedViewSubstitutionVisitorTest.java | 32 ++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git
a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
index 1ad33f2..e0f78b0 100644
--- a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
+++ b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
@@ -285,6 +285,8 @@ public class SubstitutionVisitor {
public static @Nullable RexNode splitFilter(final RexSimplify simplify,
RexNode condition, RexNode target) {
final RexBuilder rexBuilder = simplify.rexBuilder;
+ condition = simplify.simplify(condition);
+ target = simplify.simplify(target);
RexNode condition2 = canonizeNode(rexBuilder, condition);
RexNode target2 = canonizeNode(rexBuilder, target);
diff --git
a/core/src/test/java/org/apache/calcite/test/MaterializedViewSubstitutionVisitorTest.java
b/core/src/test/java/org/apache/calcite/test/MaterializedViewSubstitutionVisitorTest.java
index f5f71f5..bed699f 100644
---
a/core/src/test/java/org/apache/calcite/test/MaterializedViewSubstitutionVisitorTest.java
+++
b/core/src/test/java/org/apache/calcite/test/MaterializedViewSubstitutionVisitorTest.java
@@ -1575,6 +1575,38 @@ public class MaterializedViewSubstitutionVisitorTest
extends AbstractMaterialize
sql(mv, query).ok();
}
+ @Test void testRexPredicate() {
+ final String mv = ""
+ + "select \"name\"\n"
+ + "from \"emps\"\n"
+ + "where \"deptno\" > 100 and \"deptno\" > 50\n"
+ + "group by \"name\"";
+ final String query = ""
+ + "select \"name\"\n"
+ + "from \"emps\"\n"
+ + "where \"deptno\" > 100"
+ + "group by \"name\"";
+ sql(mv, query).withChecker(
+ resultContains(""
+ + "EnumerableTableScan(table=[[hr, MV0]])")).ok();
+ }
+
+ @Test void testRexPredicate1() {
+ final String query = ""
+ + "select \"name\"\n"
+ + "from \"emps\"\n"
+ + "where \"deptno\" > 100 and \"deptno\" > 50\n"
+ + "group by \"name\"";
+ final String mv = ""
+ + "select \"name\"\n"
+ + "from \"emps\"\n"
+ + "where \"deptno\" > 100"
+ + "group by \"name\"";
+ sql(mv, query).withChecker(
+ resultContains(""
+ + "EnumerableTableScan(table=[[hr, MV0]])")).ok();
+ }
+
final JavaTypeFactoryImpl typeFactory =
new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
private final RexBuilder rexBuilder = new RexBuilder(typeFactory);