julianhyde commented on a change in pull request #2458:
URL: https://github.com/apache/calcite/pull/2458#discussion_r687099866
##########
File path:
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
##########
@@ -462,6 +484,22 @@ protected Builder buildAggregate(Aggregate e, Builder
builder,
// as there is at least one aggregate function.
builder.setGroupBy(new SqlNodeList(groupByList, POS));
}
+
+ if (builder.clauses.contains(Clause.HAVING) && !e.getGroupSet()
+ .equals(ImmutableBitSet.union(e.getGroupSets()))) {
+ // groupSet contains at least one column that is not in any groupSets.
+ // To make such columns must appear in the output (their value will
+ // always be NULL), we generate an extra grouping set, then filter
+ // it out using a "HAVING GROUPING_ID(groupSets) <> 0".
+ // We want to generate the
+ final SqlNodeList groupingList = new SqlNodeList(POS);
+ e.getGroupSet().forEach(g ->
+ groupingList.add(builder.context.field(g)));
+ SqlNumericLiteral zero =
SqlNumericLiteral.createExactNumeric(String.valueOf(0), POS);
+ SqlNode condition = SqlStdOperatorTable.NOT_EQUALS.createCall(POS,
+ SqlStdOperatorTable.GROUPING_ID.createCall(groupingList), zero);
Review comment:
yes, `GROUPING` is preferred, even though they are equivalent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]