xiedeyantu commented on code in PR #4495:
URL: https://github.com/apache/calcite/pull/4495#discussion_r2264178623
##########
core/src/main/java/org/apache/calcite/tools/RelBuilder.java:
##########
@@ -2819,28 +2819,56 @@ private RelBuilder aggregate_(ImmutableBitSet groupSet,
* GROUP_ID returns wrong result</a> and
* <a
href="https://issues.apache.org/jira/browse/CALCITE-4748">[CALCITE-4748]
* If there are duplicate GROUPING SETS, Calcite should return duplicate
- * rows</a>.
+ * rows</a> and
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7126">[CALCITE-7126]
+ * The calculation result of grouping function is wrong</a>.
*/
private RelBuilder rewriteAggregateWithDuplicateGroupSets(
ImmutableBitSet groupSet,
ImmutableSortedMultiset<ImmutableBitSet> groupSets,
List<AggCallPlus> aggregateCalls) {
+ List<AggregateCall> calls =
+ aggregateCalls.stream()
+ .map(AggCallPlus::aggregateCall)
+ .collect(Collectors.toList());
+ return rewriteAggregateWithDuplicateGroupSetsImpl(groupSet, groupSets,
calls);
+ }
+
+ private RelBuilder rewriteAggregateWithDuplicateGroupSetsImpl(
+ ImmutableBitSet groupSet,
+ ImmutableSortedMultiset<ImmutableBitSet> groupSets,
+ List<AggregateCall> aggregateCalls) {
+ final int groupCount = groupSet.cardinality();
+ // No need to handle the case without GROUP BY in aggregate.
+ if (groupCount > 0) {
+ aggregateCalls = aggregateCalls.stream()
+ .map(c -> c.withAllowChangeNullable(false))
Review Comment:
Because AggCallBinding is needed to infer the type of the aggregation
function, the entire logic is deeply nested and most of it is in Aggregate.
Saving a flag in the builder still requires passing parameters layer by layer,
and finally it also acts on the aggregation function. Therefore, the idea of
this version is to put the flag in AggregateCall.
--
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]