You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "jin xing (JIRA)" <ji...@apache.org> on 2019/07/20 09:34:00 UTC

[jira] [Updated] (CALCITE-3203) When matching materializations, match Project with child of Aggregate

     [ https://issues.apache.org/jira/browse/CALCITE-3203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

jin xing updated CALCITE-3203:
------------------------------
    Description: 
In current code, {{SubstitutionVisitor}} & {{MaterializedViewSubstitutionVisitor}} fail to support below matching:

{code:java}
   query:   Project(projects: [$0, *(2, $1)])
                  Aggregate(groupSet: {0}, groupSets: [{0}], calls: [SUM($1)])
                     Scan(table: [hr, emps])</li>
   target:  Project(projects: [$0, *(2, $1), *(2, $2)])
                  Aggregate(groupSet: {0}, groupSets: [{0}], calls: [SUM($1), COUNT()])
                     Scan(table: [hr, emps])</li>
{code}

And below test fails

{code:java}
MaterializationTest.java
  @Test public void testAggregate() {
    checkMaterialize(
      "select \"deptno\", count(1), 2 * sum(\"empid\") from "
        + "(select * from \"emps\" union all select * from \"emps\")"
        + "group by \"deptno\"",
      "select \"deptno\", 2 * sum(\"empid\") from "
        + "(select * from \"emps\" union all select * from \"emps\")"
        + "group by \"deptno\"");
  }
{code}

The reason is that {{Project&Aggregate}} are not taken into consideration at the same time in current matching rules.
It might make sense to create a rule of {{ProjectOnAggregateToProjectOnAggregateUnifyRule}} to handle such case.


> When matching materializations, match Project with child of Aggregate
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-3203
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3203
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: jin xing
>            Priority: Major
>
> In current code, {{SubstitutionVisitor}} & {{MaterializedViewSubstitutionVisitor}} fail to support below matching:
> {code:java}
>    query:   Project(projects: [$0, *(2, $1)])
>                   Aggregate(groupSet: {0}, groupSets: [{0}], calls: [SUM($1)])
>                      Scan(table: [hr, emps])</li>
>    target:  Project(projects: [$0, *(2, $1), *(2, $2)])
>                   Aggregate(groupSet: {0}, groupSets: [{0}], calls: [SUM($1), COUNT()])
>                      Scan(table: [hr, emps])</li>
> {code}
> And below test fails
> {code:java}
> MaterializationTest.java
>   @Test public void testAggregate() {
>     checkMaterialize(
>       "select \"deptno\", count(1), 2 * sum(\"empid\") from "
>         + "(select * from \"emps\" union all select * from \"emps\")"
>         + "group by \"deptno\"",
>       "select \"deptno\", 2 * sum(\"empid\") from "
>         + "(select * from \"emps\" union all select * from \"emps\")"
>         + "group by \"deptno\"");
>   }
> {code}
> The reason is that {{Project&Aggregate}} are not taken into consideration at the same time in current matching rules.
> It might make sense to create a rule of {{ProjectOnAggregateToProjectOnAggregateUnifyRule}} to handle such case.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)