Feng Zhu created CALCITE-3930:
---------------------------------

             Summary: When converting Aggregate to SQL, add Having clause if a 
group key is not in group sets
                 Key: CALCITE-3930
                 URL: https://issues.apache.org/jira/browse/CALCITE-3930
             Project: Calcite
          Issue Type: Bug
          Components: core
            Reporter: Feng Zhu


According to the discussion in CALCITE-3893 and CALCITE-3895, RelNode below is 
allowed in Calcite.
{code:java}
  final RelBuilder builder = RelBuilder.create(config().build());
  RelNode aggregate = builder.scan("EMP")
        .aggregate(
            builder.groupKey(ImmutableBitSet.of(0),
            (Iterable<ImmutableBitSet>) ImmutableList.of(
                ImmutableBitSet.of())),
            builder.countStar("C"))
        .build();
  });


LogicalAggregate(group=[{0}], groups=[[{}]], C=[COUNT()])
{code}
But the SQL is not correct ('deptno is not being grouped').
{code:java}
SELECT deptno, count(*) AS C
FROM emp
GROUP BY grouping sets (())
{code}
We need to address such cases.
{code:java}
SELECT deptno, count(*) AS C
FROM emp
GROUP BY grouping sets (deptno,())
Having GROUPING_ID(deptno) = 1
{code}



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

Reply via email to