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


##########
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:
   Mapping would make things even more confusing, because there are the 
following lines at the end of this method.
   ```
   if (groupId != NO_GROUP_ID && type == AggregateType.MAP) {
      output[output.length - 1] = groupId;
   }
   
   ```
   
   



-- 
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