You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by za...@apache.org on 2019/12/29 13:31:23 UTC
[calcite] branch master updated (06b0bb4 -> 5ddded1)
This is an automated email from the ASF dual-hosted git repository.
zabetak pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.
discard 06b0bb4 [CALCITE-3632] Add IntersectToIntersectUnify Rule in SubstitutionVisitor (xy2953396112)
new 5ddded1 [CALCITE-3632] Add IntersectToIntersectUnify Rule in SubstitutionVisitor (xy2953396112)
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (06b0bb4)
\
N -- N -- N refs/heads/master (5ddded1)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
[calcite] 01/01: [CALCITE-3632] Add IntersectToIntersectUnify Rule
in SubstitutionVisitor (xy2953396112)
Posted by za...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zabetak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 5ddded14bf510edec83c007a3bad89cda9ff2935
Author: dz <95...@qq.com>
AuthorDate: Thu Dec 26 14:53:49 2019 +0800
[CALCITE-3632] Add IntersectToIntersectUnify Rule in SubstitutionVisitor (xy2953396112)
Close apache/calcite#1692
---
.../apache/calcite/plan/SubstitutionVisitor.java | 30 +++++++++++++++++++++-
.../apache/calcite/test/MaterializationTest.java | 25 ++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
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 389f4f5..5398fcc 100644
--- a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
+++ b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
@@ -27,6 +27,7 @@ import org.apache.calcite.rel.mutable.Holder;
import org.apache.calcite.rel.mutable.MutableAggregate;
import org.apache.calcite.rel.mutable.MutableCalc;
import org.apache.calcite.rel.mutable.MutableFilter;
+import org.apache.calcite.rel.mutable.MutableIntersect;
import org.apache.calcite.rel.mutable.MutableJoin;
import org.apache.calcite.rel.mutable.MutableRel;
import org.apache.calcite.rel.mutable.MutableRelVisitor;
@@ -134,7 +135,8 @@ public class SubstitutionVisitor {
AggregateToAggregateUnifyRule.INSTANCE,
AggregateOnCalcToAggregateUnifyRule.INSTANCE,
UnionToUnionUnifyRule.INSTANCE,
- UnionOnCalcsToUnionUnifyRule.INSTANCE);
+ UnionOnCalcsToUnionUnifyRule.INSTANCE,
+ IntersectToIntersectUnifyRule.INSTANCE);
/**
* Factory for a builder for relational expressions.
@@ -1630,6 +1632,32 @@ public class SubstitutionVisitor {
}
}
+ /**
+ * A {@link SubstitutionVisitor.UnifyRule} that matches a
+ * {@link MutableIntersect} to a {@link MutableIntersect} where the query and target
+ * have the same inputs but might not have the same order.
+ */
+ private static class IntersectToIntersectUnifyRule extends AbstractUnifyRule {
+ public static final IntersectToIntersectUnifyRule INSTANCE =
+ new IntersectToIntersectUnifyRule();
+
+ private IntersectToIntersectUnifyRule() {
+ super(any(MutableIntersect.class), any(MutableIntersect.class), 0);
+ }
+
+ public UnifyResult apply(UnifyRuleCall call) {
+ final MutableIntersect query = (MutableIntersect) call.query;
+ final MutableIntersect target = (MutableIntersect) call.target;
+ final List<MutableRel> queryInputs = new ArrayList<>(query.getInputs());
+ final List<MutableRel> targetInputs = new ArrayList<>(target.getInputs());
+ if (query.isAll() == target.isAll()
+ && sameRelCollectionNoOrderConsidered(queryInputs, targetInputs)) {
+ return call.result(target);
+ }
+ return null;
+ }
+ }
+
/** Check if list0 and list1 contains the same nodes -- order is not considered. */
private static boolean sameRelCollectionNoOrderConsidered(
List<MutableRel> list0, List<MutableRel> list1) {
diff --git a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
index 6cab20a..7aa0a8c 100644
--- a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
+++ b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
@@ -2837,6 +2837,7 @@ public class MaterializationTest {
checkNoMaterialize(sql0 + " union " + sql1, sql0 + " union all " + sql1,
HR_FKUK_MODEL);
}
+
@Test public void testUnionOnCalcsToUnion() {
String mv = ""
+ "select \"deptno\", \"salary\"\n"
@@ -2857,6 +2858,30 @@ public class MaterializationTest {
checkMaterialize(mv, query);
}
+ @Test public void testIntersectToIntersect0() {
+ final String mv = ""
+ + "select \"deptno\" from \"emps\"\n"
+ + "intersect\n"
+ + "select \"deptno\" from \"depts\"";
+ final String query = ""
+ + "select \"deptno\" from \"depts\"\n"
+ + "intersect\n"
+ + "select \"deptno\" from \"emps\"";
+ checkMaterialize(mv, query, true);
+ }
+
+ @Test public void testIntersectToIntersect1() {
+ final String mv = ""
+ + "select \"deptno\" from \"emps\"\n"
+ + "intersect all\n"
+ + "select \"deptno\" from \"depts\"";
+ final String query = ""
+ + "select \"deptno\" from \"depts\"\n"
+ + "intersect all\n"
+ + "select \"deptno\" from \"emps\"";
+ checkMaterialize(mv, query, true);
+ }
+
private static <E> List<List<List<E>>> list3(E[][][] as) {
final ImmutableList.Builder<List<List<E>>> builder =
ImmutableList.builder();