You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by hy...@apache.org on 2019/06/29 20:56:37 UTC
[calcite] branch master updated: [CALCITE-3060] MutableProject
should be generated based on INVERSE_SURJECTION mapping (DonnyZone)
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 bd42d29 [CALCITE-3060] MutableProject should be generated based on INVERSE_SURJECTION mapping (DonnyZone)
bd42d29 is described below
commit bd42d29123c54200b6c3c213d8dbd8e8ec24db79
Author: wellfengzhu <we...@gmail.com>
AuthorDate: Thu Jun 13 15:39:18 2019 +0800
[CALCITE-3060] MutableProject should be generated based on INVERSE_SURJECTION mapping (DonnyZone)
---
.../java/org/apache/calcite/rel/mutable/MutableRels.java | 13 +++++++++++--
.../java/org/apache/calcite/test/MaterializationTest.java | 9 +++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/rel/mutable/MutableRels.java b/core/src/main/java/org/apache/calcite/rel/mutable/MutableRels.java
index 0604c9a..92f8958 100644
--- a/core/src/main/java/org/apache/calcite/rel/mutable/MutableRels.java
+++ b/core/src/main/java/org/apache/calcite/rel/mutable/MutableRels.java
@@ -53,6 +53,8 @@ import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.util.Util;
+import org.apache.calcite.util.mapping.Mapping;
+import org.apache.calcite.util.mapping.MappingType;
import org.apache.calcite.util.mapping.Mappings;
import com.google.common.collect.Lists;
@@ -136,9 +138,16 @@ public abstract class MutableRels {
if (Mappings.isIdentity(posList, rowType.getFieldCount())) {
return child;
}
+ final Mapping mapping =
+ Mappings.create(
+ MappingType.INVERSE_SURJECTION,
+ rowType.getFieldCount(),
+ posList.size());
+ for (int i = 0; i < posList.size(); i++) {
+ mapping.set(posList.get(i), i);
+ }
return MutableProject.of(
- RelOptUtil.permute(child.cluster.getTypeFactory(), rowType,
- Mappings.bijection(posList).inverse()),
+ RelOptUtil.permute(child.cluster.getTypeFactory(), rowType, mapping),
child,
new AbstractList<RexNode>() {
public int size() {
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 9e9507c..7064254 100644
--- a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
+++ b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
@@ -648,6 +648,15 @@ public class MaterializationTest {
+ " EnumerableTableScan(table=[[hr, m0]])"));
}
+ @Test public void testPermutationError() {
+ checkMaterialize(
+ "select min(\"salary\"), count(*), max(\"salary\"), sum(\"salary\"), \"empid\" "
+ + "from \"emps\" group by \"empid\"",
+ "select count(*), \"empid\" from \"emps\" group by \"empid\"",
+ HR_FKUK_MODEL,
+ CalciteAssert.checkResultContains("EnumerableTableScan(table=[[hr, m0]])"));
+ }
+
@Test public void testSwapJoin() {
checkMaterialize(
"select count(*) as c from \"foodmart\".\"sales_fact_1997\" as s join \"foodmart\".\"time_by_day\" as t on s.\"time_id\" = t.\"time_id\"",