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

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


The following commit(s) were added to refs/heads/master by this push:
     new fda9dbda7e6 IGNITE-24291 Calcite reuse Row for non-storing 
accumulators (#11827)
fda9dbda7e6 is described below

commit fda9dbda7e62e9b2eef85caeb0288b01a252d7ff
Author: Maksim Timonin <[email protected]>
AuthorDate: Thu Feb 6 20:48:40 2025 +0300

    IGNITE-24291 Calcite reuse Row for non-storing accumulators (#11827)
---
 .../processors/query/calcite/exec/exp/agg/Accumulators.java |  2 +-
 .../query/calcite/exec/exp/agg/AccumulatorsFactory.java     | 13 +++++++++----
 .../query/calcite/exec/exp/agg/IterableAccumulator.java     |  6 ++----
 .../{IterableAccumulator.java => StoringAccumulator.java}   |  2 +-
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java
 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java
index a8d453c1d86..396683bb08f 100644
--- 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java
+++ 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java
@@ -1425,7 +1425,7 @@ public class Accumulators {
     }
 
     /** */
-    private static class DistinctAccumulator<Row> extends 
AbstractAccumulator<Row> {
+    private static class DistinctAccumulator<Row> extends 
AbstractAccumulator<Row> implements StoringAccumulator {
         /** */
         private final Accumulator<Row> acc;
 
diff --git 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java
 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java
index 2cce341057c..222dd9c3a18 100644
--- 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java
+++ 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java
@@ -236,13 +236,17 @@ public class AccumulatorsFactory<Row> implements 
Supplier<List<AccumulatorWrappe
             for (int i = 0; i < call.getArgList().size(); ++i)
                 argMapping[call.getArgList().get(i)] = i;
 
+            boolean createRow = 
StoringAccumulator.class.isAssignableFrom(accumulator.getClass());
+
             return new Function<Row, Row>() {
                 final RowHandler<Row> hnd = ctx.rowHandler();
 
                 final RowHandler.RowFactory<Row> rowFac = 
hnd.factory(ctx.getTypeFactory(), inputRowType);
 
+                final Row reuseRow = createRow ? null : rowFac.create();
+
                 @Override public Row apply(Row in) {
-                    Row out = rowFac.create();
+                    Row out = createRow ? rowFac.create() : reuseRow;
 
                     for (int i = 0; i < hnd.columnCount(in); ++i) {
                         Object val = hnd.get(i, in);
@@ -319,11 +323,12 @@ public class AccumulatorsFactory<Row> implements 
Supplier<List<AccumulatorWrappe
             if (filterArg >= 0 && Boolean.TRUE != handler.get(filterArg, row))
                 return;
 
-            Row newRow = inAdapter.apply(row);
-            if (newRow == null)
+            Row accRow = inAdapter.apply(row);
+
+            if (accRow == null)
                 return;
 
-            accumulator.add(newRow);
+            accumulator.add(accRow);
         }
 
         /** {@inheritDoc} */
diff --git 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/IterableAccumulator.java
 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/IterableAccumulator.java
index 552b343dd4b..772f137332e 100644
--- 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/IterableAccumulator.java
+++ 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/IterableAccumulator.java
@@ -17,9 +17,7 @@
 
 package org.apache.ignite.internal.processors.query.calcite.exec.exp.agg;
 
-/**
- * Interface for row storing accumulator.
- */
-public interface IterableAccumulator<Row> extends Accumulator<Row>, 
Iterable<Row> {
+/** */
+public interface IterableAccumulator<Row> extends Accumulator<Row>, 
Iterable<Row>, StoringAccumulator {
     // No-op.
 }
diff --git 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/IterableAccumulator.java
 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/StoringAccumulator.java
similarity index 91%
copy from 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/IterableAccumulator.java
copy to 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/StoringAccumulator.java
index 552b343dd4b..66e31d5a45d 100644
--- 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/IterableAccumulator.java
+++ 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/StoringAccumulator.java
@@ -20,6 +20,6 @@ package 
org.apache.ignite.internal.processors.query.calcite.exec.exp.agg;
 /**
  * Interface for row storing accumulator.
  */
-public interface IterableAccumulator<Row> extends Accumulator<Row>, 
Iterable<Row> {
+public interface StoringAccumulator {
     // No-op.
 }

Reply via email to