This is an automated email from the ASF dual-hosted git repository.

yashmayya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 73645dafec9 Fix missing aggregate FILTER in multi-stage EXPLAIN when 
asking servers (#19767)
73645dafec9 is described below

commit 73645dafec94d08dfec2a6f776d4fc96957156e9
Author: Yash Mayya <[email protected]>
AuthorDate: Tue Oct 6 18:35:51 2026 -0700

    Fix missing aggregate FILTER in multi-stage EXPLAIN when asking servers 
(#19767)
---
 .../planner/logical/PlanNodeToRelConverter.java    | 14 ++++-
 .../logical/PlanNodeToRelConverterTest.java        | 64 ++++++++++++++++++++++
 2 files changed, 75 insertions(+), 3 deletions(-)

diff --git 
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/PlanNodeToRelConverter.java
 
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/PlanNodeToRelConverter.java
index 973d502e7b3..9b39f80cbd1 100644
--- 
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/PlanNodeToRelConverter.java
+++ 
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/logical/PlanNodeToRelConverter.java
@@ -111,9 +111,17 @@ public final class PlanNodeToRelConverter {
         int[] groupKeyArr = 
node.getGroupKeys().stream().mapToInt(Integer::intValue).toArray();
         RelBuilder.GroupKey groupKey = _builder.groupKey(groupKeyArr);
 
-        List<RelBuilder.AggCall> aggCalls =
-            node.getAggCalls().stream().map(functionCall -> 
RexExpressionUtils.toAggCall(_builder, functionCall))
-                .collect(Collectors.toList());
+        List<RexExpression.FunctionCall> functionCalls = node.getAggCalls();
+        List<Integer> filterArgs = node.getFilterArgs();
+        List<RelBuilder.AggCall> aggCalls = new 
ArrayList<>(functionCalls.size());
+        for (int i = 0; i < functionCalls.size(); i++) {
+          RelBuilder.AggCall aggCall = RexExpressionUtils.toAggCall(_builder, 
functionCalls.get(i));
+          int filterArg = filterArgs.get(i);
+          if (filterArg >= 0) {
+            aggCall = aggCall.filter(_builder.field(filterArg));
+          }
+          aggCalls.add(aggCall);
+        }
 
         _builder.aggregate(groupKey, aggCalls);
       } catch (RuntimeException e) {
diff --git 
a/pinot-query-planner/src/test/java/org/apache/pinot/query/planner/logical/PlanNodeToRelConverterTest.java
 
b/pinot-query-planner/src/test/java/org/apache/pinot/query/planner/logical/PlanNodeToRelConverterTest.java
new file mode 100644
index 00000000000..d642beb5118
--- /dev/null
+++ 
b/pinot-query-planner/src/test/java/org/apache/pinot/query/planner/logical/PlanNodeToRelConverterTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.query.planner.logical;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.query.planner.plannode.AggregateNode;
+import org.apache.pinot.query.planner.plannode.ExplainedNode;
+import org.apache.pinot.query.planner.plannode.PlanNode;
+import org.apache.pinot.query.planner.plannode.ProjectNode;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+/// Tests for [PlanNodeToRelConverter].
+public class PlanNodeToRelConverterTest {
+
+  @Test
+  public void testAggregateFilter() {
+    // COUNT(*), COUNT(*) FILTER (WHERE c) ... GROUP BY a
+    DataSchema leafSchema = new DataSchema(new String[]{"a", "b", "c"},
+        new ColumnDataType[]{ColumnDataType.INT, ColumnDataType.INT, 
ColumnDataType.BOOLEAN});
+    PlanNode leaf = new ExplainedNode(0, leafSchema, null, List.of(), "Leaf", 
Map.of());
+    DataSchema projectSchema =
+        new DataSchema(new String[]{"a", "c"}, new 
ColumnDataType[]{ColumnDataType.INT, ColumnDataType.BOOLEAN});
+    PlanNode project = new ProjectNode(0, projectSchema, null, List.of(leaf),
+        List.of(new RexExpression.InputRef(0), new RexExpression.InputRef(2)));
+    DataSchema aggregateSchema = new DataSchema(new String[]{"a", "cnt", 
"filteredCnt"},
+        new ColumnDataType[]{ColumnDataType.INT, ColumnDataType.LONG, 
ColumnDataType.LONG});
+    RexExpression.FunctionCall count = new 
RexExpression.FunctionCall(ColumnDataType.LONG, "COUNT", List.of());
+    PlanNode aggregate = new AggregateNode(0, aggregateSchema, null, 
List.of(project), List.of(count, count),
+        List.of(-1, 1), List.of(0), AggregateNode.AggType.DIRECT, false, null, 
-1);
+
+    RelBuilder relBuilder = 
RelBuilder.create(Frameworks.newConfigBuilder().build());
+    RelNode relNode = PlanNodeToRelConverter.convert(relBuilder, aggregate);
+    assertEquals(RelOptUtil.toString(relNode),
+        "LogicalAggregate(group=[{0}], agg#0=[COUNT()], agg#1=[COUNT() FILTER 
$1])\n"
+            + "  LogicalProject(a=[$0], c=[$2])\n"
+            + "    Leaf\n");
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to