You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/09/03 00:16:02 UTC
[14/50] incubator-calcite git commit: [CALCITE-787] Star table
wrongly assigned to materialized view (Amogh Margoor)
[CALCITE-787] Star table wrongly assigned to materialized view (Amogh Margoor)
Close apache/incubator-calcite#103
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/d38e6b1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/d38e6b1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/d38e6b1b
Branch: refs/heads/branch-release
Commit: d38e6b1b92497c0e4e43847c4ab756e888dac1f3
Parents: 5a36560
Author: Amogh Margoor <am...@qubole.com>
Authored: Mon Jul 6 08:26:18 2015 -0400
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Jul 16 15:22:15 2015 -0700
----------------------------------------------------------------------
.../calcite/plan/RelOptMaterialization.java | 9 +++-
.../calcite/plan/volcano/VolcanoPlanner.java | 7 ++-
.../org/apache/calcite/test/LatticeTest.java | 56 ++++++++++++++++++++
3 files changed, 68 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/d38e6b1b/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java b/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java
index 8c9eaae..f945e65 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptMaterialization.java
@@ -77,8 +77,12 @@ public class RelOptMaterialization {
/**
* Converts a relational expression to one that uses a
* {@link org.apache.calcite.schema.impl.StarTable}.
- * The relational expression is already in leaf-join-form, per
+ *
+ * <p>The relational expression is already in leaf-join-form, per
* {@link #toLeafJoinForm(org.apache.calcite.rel.RelNode)}.
+ *
+ * @return Rewritten expression, or null if expression cannot be rewritten
+ * to use the star
*/
public static RelNode tryUseStar(RelNode rel,
final RelOptTable starRelOptTable) {
@@ -191,7 +195,8 @@ public class RelOptMaterialization {
}
});
if (rel2 == rel) {
- return rel;
+ // No rewrite happened.
+ return null;
}
final Program program = Programs.hep(
ImmutableList.of(ProjectFilterTransposeRule.INSTANCE,
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/d38e6b1b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
index 6634cf3..e57a760 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
@@ -391,8 +391,11 @@ public class VolcanoPlanner extends AbstractRelOptPlanner {
// First, if the materialization is in terms of a star table, rewrite
// the query in terms of the star table.
if (materialization.starTable != null) {
- root = RelOptMaterialization.tryUseStar(
- root, materialization.starRelOptTable);
+ RelNode newRoot = RelOptMaterialization.tryUseStar(root,
+ materialization.starRelOptTable);
+ if (newRoot != null) {
+ root = newRoot;
+ }
}
// Push filters to the bottom, and combine projects on top.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/d38e6b1b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/LatticeTest.java b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
index 92d121b..77e7943 100644
--- a/core/src/test/java/org/apache/calcite/test/LatticeTest.java
+++ b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
@@ -624,6 +624,62 @@ public class LatticeTest {
}
/** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-787">[CALCITE-787]
+ * Star table wrongly assigned to materialized view</a>. */
+ @Test public void testOneLatticeOneMV() {
+ final AtomicInteger counter = new AtomicInteger();
+ final Class<JdbcTest.EmpDeptTableFactory> clazz =
+ JdbcTest.EmpDeptTableFactory.class;
+
+ final String mv = " materializations: [\n"
+ + " {\n"
+ + " table: \"m0\",\n"
+ + " view: \"m0v\",\n"
+ + " sql: \"select * from \\\"foodmart\\\".\\\"sales_fact_1997\\\" "
+ + "where \\\"product_id\\\" = 10\" "
+ + " }\n"
+ + " ]\n";
+
+ final String model = ""
+ + "{\n"
+ + " version: '1.0',\n"
+ + " schemas: [\n"
+ + JdbcTest.FOODMART_SCHEMA
+ + ",\n"
+ + " {\n"
+ + " name: 'adhoc',\n"
+ + " tables: [\n"
+ + " {\n"
+ + " name: 'EMPLOYEES',\n"
+ + " type: 'custom',\n"
+ + " factory: '"
+ + clazz.getName()
+ + "',\n"
+ + " operand: {'foo': true, 'bar': 345}\n"
+ + " }\n"
+ + " ],\n"
+ + " lattices: " + "[" + INVENTORY_LATTICE
+ + " ]\n"
+ + " },\n"
+ + " {\n"
+ + " name: 'mat',\n"
+ + mv
+ + " }\n"
+ + " ]\n"
+ + "}";
+
+ CalciteAssert.model(model)
+ .withDefaultSchema("foodmart")
+ .query("select * from \"foodmart\".\"sales_fact_1997\" where \"product_id\" = 10")
+ .enableMaterializations(true)
+ .substitutionMatches(
+ CalciteAssert.checkRel(
+ "EnumerableTableScan(table=[[mat, m0]])\n",
+ counter));
+ assertThat(counter.intValue(), equalTo(1));
+ }
+
+ /** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-760">[CALCITE-760]
* Aggregate recommender blows up if row count estimate is too high</a>. */
@Ignore