clintropolis commented on code in PR #13297:
URL: https://github.com/apache/druid/pull/13297#discussion_r1012393944


##########
processing/src/main/java/org/apache/druid/segment/nested/NestedFieldLiteralColumnIndexSupplier.java:
##########
@@ -223,16 +214,41 @@ private <T> IntIntPair getLocalRangeFromDictionary(
       }
     }
     globalEndIndex = Math.max(globalStartIndex, globalEndIndex);
-    // end index is not inclusive, so we find the last value in the local 
dictionary that falls within the range
+
+    // with global dictionary id range settled, now lets map that onto a local 
dictionary id range
+    int localFound = localDictionary.indexOf(globalStartIndex);
+    if (localFound < 0) {
+      // the first valid global index is not within the local dictionary, so 
the insertion point is where we begin
+      localStartIndex = -(localFound + 1);
+      // if the computed local start index violates the global range, shift up 
by 1
+      int actualGlobalStartIndex = localDictionary.get(localStartIndex);
+      if (actualGlobalStartIndex < globalStartIndex) {

Review Comment:
   ok so i looked a lot closer in debugger and working things out by hand, and 
this code on the start index is pointless and only can be hit in cases where 
the range will effectively be empty anyway so can be dropped. it also uncovered 
a missing bounds check on `FixedIndexed` get method, which I have fixed and 
added tests for 😅
   
   I've re-arranged some things so the logic is simplified, it was really only 
the end index that needed adjustment when it was missing from the local 
dictionary, and that was because I was doing the shifting to account for the 
end index being exclusive in a funny manner. I think its clearer now. Thanks 
for asking this question!



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