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 7294460 [CALCITE-3223] MV fails to match when there is
Non-RexInputRef in the projects (Jin Xing)
7294460 is described below
commit 729446005617059c0ce9fef4068087e4ca9ca139
Author: jinxing <[email protected]>
AuthorDate: Thu Aug 1 12:06:38 2019 +0800
[CALCITE-3223] MV fails to match when there is Non-RexInputRef in the
projects (Jin Xing)
Close #1346
---
.../org/apache/calcite/plan/SubstitutionVisitor.java | 19 +++++++++++--------
.../org/apache/calcite/test/MaterializationTest.java | 18 ++++++++++++++++++
2 files changed, 29 insertions(+), 8 deletions(-)
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 4e251d3..6e9d0ed 100644
--- a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
+++ b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
@@ -1131,20 +1131,23 @@ public class SubstitutionVisitor {
}
final List<RexNode> exprList = new ArrayList<>();
final RexBuilder rexBuilder = model.cluster.getRexBuilder();
- for (RelDataTypeField field : model.rowType.getFieldList()) {
- exprList.add(rexBuilder.makeZeroLiteral(field.getType()));
+ for (int i = 0; i < model.rowType.getFieldCount(); i++) {
+ exprList.add(null);
}
for (Ord<RexNode> expr : Ord.zip(project.projects)) {
if (expr.e instanceof RexInputRef) {
final int target = ((RexInputRef) expr.e).getIndex();
- exprList.set(target,
- rexBuilder.ensureType(expr.e.getType(),
- RexInputRef.of(expr.i, input.rowType),
- false));
- } else {
- throw MatchFailed.INSTANCE;
+ if (exprList.get(target) == null) {
+ exprList.set(target,
+ rexBuilder.ensureType(expr.e.getType(),
+ RexInputRef.of(expr.i, input.rowType),
+ false));
+ }
}
}
+ if (exprList.indexOf(null) != -1) {
+ throw MatchFailed.INSTANCE;
+ }
return MutableProject.of(model.rowType, input, exprList);
}
}
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 6fc37c8..0175f74 100644
--- a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
+++ b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
@@ -166,6 +166,24 @@ public class MaterializationTest {
.sameResultWithMaterializationsDisabled();
}
+ @Test public void testFilterToProject0() {
+ String union =
+ "select * from \"emps\" where \"empid\" > 300\n"
+ + "union all select * from \"emps\" where \"empid\" < 200";
+ String mv = "select *, \"empid\" * 2 from (" + union + ")";
+ String query = "select * from (" + union + ") where (\"empid\" * 2) > 3";
+ checkMaterialize(mv, query);
+ }
+
+ @Test public void testFilterToProject1() {
+ String agg =
+ "select \"deptno\", count(*) as \"c\", sum(\"salary\") as \"s\"\n"
+ + "from \"emps\" group by \"deptno\"";
+ String mv = "select \"c\", \"s\", \"s\" from (" + agg + ")";
+ String query = "select * from (" + agg + ") where (\"s\" * 0.8) > 10000";
+ checkNoMaterialize(mv, query, HR_FKUK_MODEL);
+ }
+
@Test public void testFilterQueryOnProjectView() {
try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
MaterializationService.setThreadLocal();