You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Wang Yanlin (Jira)" <ji...@apache.org> on 2020/11/04 01:08:00 UTC

[jira] [Assigned] (CALCITE-4376) Materialized view recognition fails when target project different column sequence with GROUP BY

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

Wang Yanlin reassigned CALCITE-4376:
------------------------------------

    Assignee: Wang Yanlin

> Materialized view recognition fails when target project different column sequence with GROUP BY
> -----------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4376
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4376
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Wang Yanlin
>            Assignee: Wang Yanlin
>            Priority: Major
>
> When target project a different column sequence with group by, materialized view recognition will fail, see the case below
> {noformat}
> @Test void test() {
>     final String mv = "" +
>         "select \"deptno\", \"name\" from ("
>         + "select \"name\", \"deptno\", \"commission\"  as cnt\n"
>         + "from \"emps\"\n"
>         + " group by \"name\", \"deptno\", \"commission\") t";
>     final String query = ""
>         + "select \"deptno\", \"commission\" as cnt\n"
>         + "from \"emps\"\n"
>         + "group by \"deptno\", \"commission\"";
>     sql(mv, query).withChecker(
>         resultContains(""
>             + "EnumerableTableScan(table=[[hr, MV0]])")).ok();
>   }
> {noformat}
> After the call of  "AggregateOnCalcToAggregateUnifyRule", the result query is
> {noformat}
> Holder
>   Aggregate(groupSet: {1, 2}, groupSets: [{1, 2}], calls: [])
>     Aggregate(groupSet: {0, 1, 2}, groupSets: [{0, 1, 2}], calls: [])
>       Calc(program: (expr#0..4=[{inputs}], name=[$t2], deptno=[$t1], commission=[$t4]))
>         Scan(table: [hr, emps])
> {noformat}
> ,  and the target is
> {noformat}
> Calc(program: (expr#0..2=[{inputs}], deptno=[$t1], name=[$t0]))
>   Aggregate(groupSet: {0, 1, 2}, groupSets: [{0, 1, 2}], calls: [])
>     Calc(program: (expr#0..4=[{inputs}], name=[$t2], deptno=[$t1], commission=[$t4]))
>       Scan(table: [hr, emps])
> {noformat}
> There is no match for 
> {noformat}
> query descendant: Aggregate(groupSet: {1, 2}, groupSets: [{1, 2}], calls: [])
> target descendant:  Calc(program: (expr#0..2=[{inputs}], deptno=[$t1], name=[$t0]))
> {noformat}
>  and the recognition fails. Maybe always add a calc in the call result of "AggregateOnCalcToAggregateUnifyRule", make the call result like this
> {noformat}
> Holder
>   Aggregate(groupSet: {1, 2}, groupSets: [{1, 2}], calls: [])
>     Calc (xxxx) // always add a calc here
>     Aggregate(groupSet: {0, 1, 2}, groupSets: [{0, 1, 2}], calls: [])
>       Calc(program: (expr#0..4=[{inputs}], name=[$t2], deptno=[$t1], commission=[$t4]))
>         Scan(table: [hr, emps])
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)