[ https://issues.apache.org/jira/browse/CALCITE-3060?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16862799#comment-16862799 ]
Feng Zhu commented on CALCITE-3060: ----------------------------------- Hi, [~hyuan]. This issue is similar to the issue I found in CALCITE-3087. We should fix the mapping beheavior. {code:java} query ================================================================================================== Aggregate(groupSet: {0}, groupSets: [{0}], calls: [COUNT()]) Project(projects: [$0, $3]) Scan(table: [hr, emps]) target ================================================================================================== Aggregate(groupSet: {0}, groupSets: [{0}], calls: [MIN($1), COUNT(), MAX($1), SUM($1)]) Project(projects: [$0, $3]) Scan(table: [hr, emps]){code} When _unifyAggregate(query, target)_, a MutableProject will be generated. {code:java} MutableRels.createProject(target, projects) //empid ($0), count($2) projects = [0, 2] // call MutableRels.createProject Mappings.bijection(projects{code} However, the posList is not always a bijection mapping. We should use *INVERSE_SURJECTION* mapping, as that in RelFieldTrimmer. > Materialized view: "target out of range" error > ---------------------------------------------- > > Key: CALCITE-3060 > URL: https://issues.apache.org/jira/browse/CALCITE-3060 > Project: Calcite > Issue Type: Bug > Affects Versions: 1.19.0 > Reporter: Anton Haidai > Priority: Major > Labels: pull-request-available > Time Spent: 10m > Remaining Estimate: 0h > > "MaterializationTest": > {code} > @Test public void testPermutationError() { > CalciteAssert.that() > .withMaterializations( > HR_FKUK_MODEL, > "m0", > "select min(\"salary\"), count(*), max(\"salary\"), > sum(\"salary\"), \"empid\" from \"emps\" group by \"empid\"", > "m1", > "select min(\"salary\"), count(*), max(\"salary\"), > sum(\"salary\"), \"deptno\", \"empid\" from \"emps\" group by \"empid\", > \"deptno\"" > ) > .query( > "select count(*), \"empid\" from \"emps\" group by \"empid\"") > .enableMaterializations(true) > .explainContains("EnumerableTableScan(table=[[hr, m0]])") > .sameResultWithMaterializationsDisabled(); > } > {code} > Error (looks like the mapping is expected to be bijection but it is not): > {code} > Caused by: java.lang.IllegalArgumentException: target out of range > at org.apache.calcite.util.Permutation.<init>(Permutation.java:69) > at org.apache.calcite.util.mapping.Mappings.bijection(Mappings.java:394) > at > org.apache.calcite.rel.mutable.MutableRels.createProject(MutableRels.java:142) > at > org.apache.calcite.plan.SubstitutionVisitor.unifyAggregates(SubstitutionVisitor.java:1269) > at > org.apache.calcite.plan.SubstitutionVisitor$AggregateOnProjectToAggregateUnifyRule.apply(SubstitutionVisitor.java:1345) > at > org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:531) > at > org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:466) > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)