@@ -915,7 +915,8 @@ private boolean isCountField(RexCall call) {
915915 private Pair <List <RexNode >, List <AggCall >> aggregateWithTrimming (
916916 List <UnresolvedExpression > groupExprList ,
917917 List <UnresolvedExpression > aggExprList ,
918- CalcitePlanContext context ) {
918+ CalcitePlanContext context ,
919+ boolean hintBucketNonNull ) {
919920 Pair <List <RexNode >, List <AggCall >> resolved =
920921 resolveAttributesForAggregation (groupExprList , aggExprList , context );
921922 List <RexNode > resolvedGroupByList = resolved .getLeft ();
@@ -1019,6 +1020,7 @@ private Pair<List<RexNode>, List<AggCall>> aggregateWithTrimming(
10191020 List <String > intendedGroupKeyAliases = getGroupKeyNamesAfterAggregation (reResolved .getLeft ());
10201021 context .relBuilder .aggregate (
10211022 context .relBuilder .groupKey (reResolved .getLeft ()), reResolved .getRight ());
1023+ if (hintBucketNonNull ) addIgnoreNullBucketHintToAggregate (context );
10221024 // During aggregation, Calcite projects both input dependencies and output group-by fields.
10231025 // When names conflict, Calcite adds numeric suffixes (e.g., "value0").
10241026 // Apply explicit renaming to restore the intended aliases.
@@ -1141,10 +1143,7 @@ private void visitAggregation(Aggregation node, CalcitePlanContext context, bool
11411143 }
11421144
11431145 Pair <List <RexNode >, List <AggCall >> aggregationAttributes =
1144- aggregateWithTrimming (groupExprList , aggExprList , context );
1145- if (toAddHintsOnAggregate ) {
1146- addIgnoreNullBucketHintToAggregate (context );
1147- }
1146+ aggregateWithTrimming (groupExprList , aggExprList , context , toAddHintsOnAggregate );
11481147
11491148 // schema reordering
11501149 List <RexNode > outputFields = context .relBuilder .fields ();
@@ -1896,11 +1895,7 @@ public RelNode visitRareTopN(RareTopN node, CalcitePlanContext context) {
18961895 .map (context .relBuilder ::isNotNull )
18971896 .toList ());
18981897 }
1899- aggregateWithTrimming (groupExprList , aggExprList , context );
1900-
1901- if (toAddHintsOnAggregate ) {
1902- addIgnoreNullBucketHintToAggregate (context );
1903- }
1898+ aggregateWithTrimming (groupExprList , aggExprList , context , toAddHintsOnAggregate );
19041899
19051900 // 2. add a window column
19061901 List <RexNode > partitionKeys = rexVisitor .analyze (node .getGroupExprList (), context );
@@ -2262,7 +2257,7 @@ public RelNode visitTimechart(
22622257 try {
22632258 // Step 1: Initial aggregation - IMPORTANT: order is [spanExpr, byField]
22642259 groupExprList = Arrays .asList (spanExpr , byField );
2265- aggregateWithTrimming (groupExprList , List .of (node .getAggregateFunction ()), context );
2260+ aggregateWithTrimming (groupExprList , List .of (node .getAggregateFunction ()), context , false );
22662261
22672262 // First rename the timestamp field (2nd to last) to @timestamp
22682263 List <String > fieldNames = context .relBuilder .peek ().getRowType ().getFieldNames ();
0 commit comments