dario-liberman commented on code in PR #18760:
URL: https://github.com/apache/pinot/pull/18760#discussion_r3471273074


##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/funnel/SortedAggregationResult.java:
##########
@@ -50,7 +78,50 @@ public void add(int step, int correlationId) {
     _correlatedSteps[step] = true;
   }
 
+  /**
+   * Multi-key add. Data must be sorted by correlationIds[0] (primary key).
+   * Secondary keys are tracked via HashMap within each primary-key group.
+   *
+   * <p>Within a primary-key group, rows for the same (primary, secondary) 
combination may appear
+   * non-contiguously (e.g. interleaved with other secondary keys). This is 
handled correctly
+   * because the HashMap accumulates all step observations per secondary key 
regardless of row order.
+   */
+  public void addMultiKey(int step, int[] correlationIds) {
+    int primaryId = correlationIds[0];
+    if (primaryId != _lastPrimaryId) {
+      flushMultiKeyGroup();
+      _lastPrimaryId = primaryId;
+      _secondaryKeySteps.clear();
+    }
+
+    _lookupKey.clear();
+    for (int k = 1; k < correlationIds.length; k++) {
+      _lookupKey.add(correlationIds[k]);
+    }
+
+    boolean[] steps = _secondaryKeySteps.get(_lookupKey);
+    if (steps == null) {
+      steps = new boolean[_numSteps];
+      _secondaryKeySteps.put(new IntArrayList(_lookupKey), steps);

Review Comment:
   I see you try to remove the sorting key from the array, but it is innocuous, 
it's the same for every entry here. The cost of all this moving around and 
specially the cost of memory allocation and garbage collection is much higher 
than adding one more int to a hash code calculation or equality calculation 
which is all that you aim to achieve here.



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