AMashenkov commented on code in PR #4522:
URL: https://github.com/apache/ignite-3/pull/4522#discussion_r1799499466


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/agg/AggregateRow.java:
##########
@@ -73,9 +102,29 @@ public Object[] createOutput(ImmutableBitSet allFields, 
byte groupId) {
     /** Writes aggregate state of the given row to given array. */
     public void writeTo(Object[] output, ImmutableBitSet allFields, byte 
groupId) {
         int cardinality = allFields.cardinality();
+
+        AccumulatorsState result = new AccumulatorsState(accs.size());
+
         for (int i = 0; i < accs.size(); i++) {
-            AccumulatorWrapper<RowT> wrapper = accs.get(i);
-            output[i + cardinality] = wrapper.end();
+            AccumulatorWrapper<RowT> acc = accs.get(i);
+
+            state.setIndex(i);
+            result.setIndex(i);
+
+            if (acc.isDistinct()) {
+                Set<Object> distinctSet = distinctSets.get(i);
+
+                for (var arg : distinctSet) {
+                    acc.accumulator().add(state, new Object[]{arg});
+                }
+            }
+
+            acc.accumulator().end(state, result);
+
+            output[i + cardinality] = acc.convertResult(result.get());

Review Comment:
   Can `allFields` be replaced with mapping?
   `i + cardinality` can be `mapping.get(i)`
   
   Or `allFields` may differ from row to row?



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to