github-advanced-security[bot] commented on code in PR #15365:
URL: https://github.com/apache/druid/pull/15365#discussion_r1449129744


##########
processing/src/main/java/org/apache/druid/query/rowsandcols/semantic/DefaultFramedOnHeapAggregatable.java:
##########
@@ -85,7 +87,305 @@
         }
       }
     } else {
-      throw new UOE("RANGE peer groupings are unsupported");
+      return computeGroupAggregates(aggFactories, frame);
+    }
+  }
+
+  /**
+   * Handles population/creation of new RAC columns.
+   */
+  static class ResultPopulator
+  {
+
+    private final Object[][] results;
+    private final AggregatorFactory[] aggFactories;
+
+    public ResultPopulator(AggregatorFactory[] aggFactories, int numRows)
+    {
+      this.aggFactories = aggFactories;
+      results = new Object[aggFactories.length][numRows];
+    }
+
+    public void write(Interval outputRows, AggIntervalCursor aggCursor)
+    {
+      for (int col = 0; col < aggFactories.length; col++) {
+        Arrays.fill(results[col], outputRows.a, outputRows.b, 
aggCursor.getValue(col));
+      }
+    }
+
+    public void appendTo(AppendableRowsAndColumns rac)
+    {
+      for (int i = 0; i < aggFactories.length; ++i) {
+        rac.addColumn(
+            aggFactories[i].getName(),
+            new ObjectArrayColumn(results[i], 
aggFactories[i].getIntermediateType())
+        );
+      }
+    }
+  }
+
+  private RowsAndColumns computeGroupAggregates(
+      AggregatorFactory[] aggFactories,
+      WindowFrame frame)
+  {
+    Iterable<AggInterval> groupIterator = buildGroupIteratorFor(rac, frame);
+    ResultPopulator resultRac = new ResultPopulator(aggFactories, 
rac.numRows());
+    AggIntervalCursor aggCursor = new AggIntervalCursor(rac, aggFactories);
+    for (AggInterval aggInterval : groupIterator) {
+      aggCursor.moveTo(aggInterval.inputRows);
+      resultRac.write(aggInterval.outputRows, aggCursor);
+    }
+    resultRac.appendTo(rac);
+    return rac;
+  }
+
+  public static Iterable<AggInterval> 
buildGroupIteratorFor(AppendableRowsAndColumns rac, WindowFrame frame)
+  {
+    int[] groupBoundaries = 
ClusteredGroupPartitioner.fromRAC(rac).computeBoundaries(frame.getOrderByColNames());
+    return new GroupIteratorForWindowFrame(rac, frame, groupBoundaries);
+  }
+
+  static class GroupIteratorForWindowFrame implements Iterable<AggInterval>
+  {
+    private final int[] groupBoundaries;
+    private final int numGroups;
+    // lower inclusive
+    private final int lowerOffset;
+    // upper exclusive
+    private final int upperOffset;
+
+    public GroupIteratorForWindowFrame(RowsAndColumns rac, WindowFrame frame, 
int[] groupBoundaries)

Review Comment:
   ## Useless parameter
   
   The parameter 'rac' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/6441)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to