gianm commented on code in PR #16849:
URL: https://github.com/apache/druid/pull/16849#discussion_r1706160179


##########
processing/src/main/java/org/apache/druid/segment/TimeAndDimsPointer.java:
##########
@@ -148,19 +177,23 @@
   @Override
   public int compareTo(@Nonnull TimeAndDimsPointer rhs)
   {
-    long timestamp = getTimestamp();
-    long rhsTimestamp = rhs.getTimestamp();
-    int timestampDiff = Long.compare(timestamp, rhsTimestamp);
-    if (timestampDiff != 0) {
-      return timestampDiff;
-    }
-    for (int dimIndex = 0; dimIndex < dimensionSelectors.length; dimIndex++) {
-      int dimDiff = dimensionSelectorComparators[dimIndex].compare(
-          dimensionSelectors[dimIndex],
-          rhs.dimensionSelectors[dimIndex]
-      );
-      if (dimDiff != 0) {
-        return dimDiff;
+    for (int index = 0; index < (dimensionSelectors.length + 1); index++) {
+      if (index == timePosition) {
+        final long timestamp = getTimestamp();
+        final long rhsTimestamp = rhs.getTimestamp();
+        final int timestampDiff = Long.compare(timestamp, rhsTimestamp);
+        if (timestampDiff != 0) {
+          return timestampDiff;
+        }
+      } else {
+        final int dimIndex = index < timePosition ? index : index - 1;
+        final int dimDiff = dimensionSelectorComparators[dimIndex].compare(
+            dimensionSelectors[dimIndex],

Review Comment:
   It can't be out of bounds, because if it's easy to the array length, it 
would get decremented for being `>= timePosition`.



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