[ 
https://issues.apache.org/jira/browse/CALCITE-1984?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16164389#comment-16164389
 ] 

fei.chen commented on CALCITE-1984:
-----------------------------------

postgres=# 
postgres=# 
postgres=# create table emps(deptno varchar(20),empid varchar(20),salary int);
CREATE TABLE
postgres=# insert into emps values('d1','e1',11);
INSERT 0 1
postgres=# insert into emps values('d1','e1',12);
INSERT 0 1
postgres=# create view mo as select deptno,empid,salary from emps group by 
deptno,empid,salary;
CREATE VIEW
postgres=# select t1.deptno,count(distinct t1.empid) from  (select deptno,empid 
from emps group by deptno,empid) as t1 group by t1.deptno;
 deptno | count 
--------+-------
 d1     |     1
(1 row)

postgres=# select deptno,count(empid) from mo group by deptno;
 deptno | count 
--------+-------
 d1     |     2
(1 row)

postgres=# 

> MaterialView rewrite failed
> ---------------------------
>
>                 Key: CALCITE-1984
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1984
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.13.0
>            Reporter: fei.chen
>            Assignee: Julian Hyde
>
> I had written a test as follows . It runs to succeed . But , the result seems 
> not right . The “count distinct” aggregation should not be changed to “count”.
> {code:java}
> @Test public void testAggregateMaterializationOnCountDistinctQuery1() {
>     checkMaterialize(
>         "select \"deptno\",  \"empid\" ,\"salary\"\n"
>             + "from \"emps\" group by \"deptno\",  \"empid\",\"salary\"",
>         "select \"deptno\", count( distinct \"empid\")" + "from (select 
> \"deptno\",  \"empid\" \n"
>             + "from \"emps\" group by \"deptno\",  \"empid\")  group by 
> \"deptno\"",
>         HR_FKUK_MODEL,
>         CalciteAssert.checkResultContains(
>             "EnumerableAggregate(group=[{0}], S=[COUNT($1)])\n" +
>                 "  EnumerableTableScan(table=[[hr, m0]]"));
>   }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to