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 48fcf0023e6 Add window value aggregator for AVG function (#17268)
48fcf0023e6 is described below
commit 48fcf0023e6c170ebc3a151099357052c1440e3a
Author: Yash Mayya <[email protected]>
AuthorDate: Mon Nov 24 20:07:11 2025 -0500
Add window value aggregator for AVG function (#17268)
---
.../pinot/calcite/rel/rules/PinotRuleUtils.java | 6 +--
.../window/aggregate/AvgWindowValueAggregator.java | 62 ++++++++++++++++++++++
.../aggregate/WindowValueAggregatorFactory.java | 2 +
3 files changed, 67 insertions(+), 3 deletions(-)
diff --git
a/pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotRuleUtils.java
b/pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotRuleUtils.java
index 79c9798ccd8..e32b1b213cd 100644
---
a/pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotRuleUtils.java
+++
b/pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotRuleUtils.java
@@ -139,9 +139,9 @@ public class PinotRuleUtils {
// Supported window functions
// OTHER_FUNCTION supported are: BOOL_AND, BOOL_OR
private static final EnumSet<SqlKind> SUPPORTED_WINDOW_FUNCTION_KIND =
- EnumSet.of(SqlKind.SUM, SqlKind.SUM0, SqlKind.MIN, SqlKind.MAX,
SqlKind.COUNT, SqlKind.ROW_NUMBER, SqlKind.RANK,
- SqlKind.DENSE_RANK, SqlKind.NTILE, SqlKind.LAG, SqlKind.LEAD,
SqlKind.FIRST_VALUE, SqlKind.LAST_VALUE,
- SqlKind.OTHER_FUNCTION);
+ EnumSet.of(SqlKind.SUM, SqlKind.SUM0, SqlKind.MIN, SqlKind.MAX,
SqlKind.COUNT, SqlKind.AVG, SqlKind.ROW_NUMBER,
+ SqlKind.RANK, SqlKind.DENSE_RANK, SqlKind.NTILE, SqlKind.LAG,
SqlKind.LEAD, SqlKind.FIRST_VALUE,
+ SqlKind.LAST_VALUE, SqlKind.OTHER_FUNCTION);
public static void validateWindows(Window window) {
int numGroups = window.groups.size();
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/window/aggregate/AvgWindowValueAggregator.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/window/aggregate/AvgWindowValueAggregator.java
new file mode 100644
index 00000000000..0d82f3dde98
--- /dev/null
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/window/aggregate/AvgWindowValueAggregator.java
@@ -0,0 +1,62 @@
+/**
+ * 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.runtime.operator.window.aggregate;
+
+import javax.annotation.Nullable;
+
+
+/**
+ * Window value aggregator for AVG window function.
+ */
+public class AvgWindowValueAggregator implements WindowValueAggregator<Object>
{
+ private double _sum = 0.0;
+ private int _count = 0;
+
+ @Override
+ public void addValue(@Nullable Object value) {
+ if (value != null) {
+ _count++;
+ _sum += ((Number) value).doubleValue();
+ }
+ }
+
+ @Override
+ public void removeValue(@Nullable Object value) {
+ if (value != null) {
+ _count--;
+ _sum -= ((Number) value).doubleValue();
+ }
+ }
+
+ @Override
+ @Nullable
+ public Object getCurrentAggregatedValue() {
+ if (_count == 0) {
+ return null;
+ } else {
+ return _sum / _count;
+ }
+ }
+
+ @Override
+ public void clear() {
+ _sum = 0.0;
+ _count = 0;
+ }
+}
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/window/aggregate/WindowValueAggregatorFactory.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/window/aggregate/WindowValueAggregatorFactory.java
index f86944373da..3be15cc1baa 100644
---
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/window/aggregate/WindowValueAggregatorFactory.java
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/window/aggregate/WindowValueAggregatorFactory.java
@@ -52,6 +52,8 @@ public class WindowValueAggregatorFactory {
return new MaxWindowValueAggregator(supportRemoval);
case "COUNT":
return new CountWindowValueAggregator();
+ case "AVG":
+ return new AvgWindowValueAggregator();
case "BOOLAND":
return new BoolAndValueAggregator();
case "BOOLOR":
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]