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


##########
processing/src/main/java/org/apache/druid/query/rowsandcols/semantic/DefaultFramedOnHeapAggregatable.java:
##########
@@ -58,20 +63,20 @@
       AggregatorFactory[] aggFactories
   )
   {
-    if (frame.isLowerUnbounded() && frame.isUpperUnbounded()) {
+    if (frame.getAdapter(Unbounded.class) != null) {
       return computeUnboundedAggregates(aggFactories);
     }
 
-
-    if (frame.getPeerType() == WindowFrame.PeerType.ROWS) {
-      if (frame.isLowerUnbounded()) {
-        return computeCumulativeAggregates(aggFactories, 
frame.getUpperOffset());
-      } else if (frame.isUpperUnbounded()) {
-        return computeReverseCumulativeAggregates(aggFactories, 
frame.getLowerOffset());
+    WindowFrame.Rows rowsFrame = frame.getAdapter(WindowFrame.Rows.class);
+    if (rowsFrame != null) {
+      if (rowsFrame.lowerOffset == null) {
+        return computeCumulativeAggregates(aggFactories, 
rowsFrame.upperOffset);

Review Comment:
   ## Dereferenced variable may be null
   
   Variable [upperOffset](1) may be null at this access as suggested by 
[this](2) null guard.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/6442)



##########
processing/src/main/java/org/apache/druid/query/rowsandcols/semantic/DefaultFramedOnHeapAggregatable.java:
##########
@@ -85,7 +90,306 @@
         }
       }
     } else {
-      throw new UOE("RANGE peer groupings are unsupported");
+      Groups groupFrame = frame.getAdapter(WindowFrame.Groups.class);
+      return computeGroupAggregates(aggFactories, groupFrame);
+    }
+  }
+
+  /**
+   * 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.Groups 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.Groups 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.Groups 
frame, int[] groupBoundaries)

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



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