clintropolis opened a new pull request, #13561:
URL: https://github.com/apache/druid/pull/13561

   ### Description
   This PR fixes a bug with nested column "value set" indexes caused by not 
properly validating that the globalId looked up for value is present in the 
global dictionary prior to looking it up in the local dictionary, which when 
"adjusting" the global ids for value type can cause incorrect selection of 
value indexes.
   
   To use an example of a variant typed nested column with 3 values `["1", 
null, -2]` (the test case I added). The string dictionary is `[null, "1"]` and 
the long dictionary is `[-2]` and our local dictionary is `[0, 1, 2]`.
   
   The code for variant typed indexes checks if the value is present in all 
global dictionaries and returns indexes for all matches. So in this case, we 
first lookup "1" in the string dictionary, find it at global id 1, all is good. 
Now, we check the long dictionary for `1`, which due to `-(insertionpoint + 1)` 
gives us `-(1 + 2) = -2`. Since the global id space is actually stacked 
dictionaries, global ids for long and double values must be "adjusted" by the 
size of string dictionary, and size of string + size of long for doubles.
   
   Back to indexOf for longs and doubles. Since prior to this patch we were not 
checking that the globalId is 0 or larger, we then immediately looked up the 
`localDictionary.indexOf(-2 + adjustLong) = localDictionary.indexOf(-2 + 2) = 
localDictionary.indexOf(0)` ... which is an actual value contained in the 
dictionary! We should have skipped the longs completely since there were no 
global matches, but instead we randomly picked the 'null' value index since it 
is 0.
   
   On to doubles, `-(insertionPoint + 1)` gives us `-(0 + 1) = -1`. The double 
adjust value is '3' since 2 strings and 1 long, so `localDictionary.indexOf(-1 
+ 3)` = `localDictionary.indexOf(2)` which is also a real value in our local 
dictionary that is definitely not '1'.
   
   So in this one case, looking for '1' actually ended up matching every row, 
fun! Anyway, my bad, nested column indexes are pretty complicated 😅 
   
   <hr>
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency 
checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md)
 (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in 
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for [code 
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
 is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


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