0z5a opened a new pull request, #20341: URL: https://github.com/apache/pinot/pull/20341
Label: `bugfix` (I can't set labels on this repo). ## Summary Fixes #20340. `intersectIndices` only advanced the second array on a match, so when the second array had an element smaller than the current element of the first one, the loop never moved past it and all later matches were dropped. For example, `intersectIndices([0, 3], [1, 2, 3])` (the example from #11442) returned `[]` instead of `[3]`, and `intersectIndices([1, 2, 3, 4], [0, 1, 2, 3])` returned `[]` while the same call with the arguments swapped returned `[1, 2, 3]`. ## Fix The loop is now a normal merge of two increasing arrays: advance the first array when its element is smaller, the second when its element is smaller, and both on a match. The output only changes for inputs where the old loop dropped matches. Inputs that are not increasing are still outside what the function supports, as the doc comment says. ## How I found it I was reading the array scalar functions and the loop only advances `j` on a match. I then tried the inputs from #11442 and from the method's doc comment with the second index array starting lower, and both came back empty. ## Where this can show up in practice This is my estimate; I have not seen a field report. - The pattern from #11442 and the doc comment: parallel multi-value columns such as tag names and tag values, where `intersectIndices(arrayIndexesOfString(tag_names, 'x'), arrayIndexesOfString(tag_values, 'y'))` finds the positions where both match. Once the second column matches at a position where the first column does not, every common position after it is missed, so the query can see no match even though one exists: filters on the result drop rows and `arrayElementAtInt` on it returns the null placeholder. - The result also depends on the argument order, so two queries that differ only in which column comes first can disagree. ## Tests `ArrayFunctionsTest.testIntersectIndices` covers both orders (matches starting in the first or in the second array), the #11442 example, no overlap, and empty arrays. The existing `ScalarTransformFunctionWrapperTest.testIntersectIndices` uses `[0..n-1]` and `[1..n]`, which already worked and gives the same result after the change. ## Testing Done - macOS, JDK 17: `ArrayFunctionsTest` compiled on its own against TestNG with the real `ArrayFunctions` and the `pinot-spi` sources it needs; both tests pass. On `master` the new test fails with `expected [1] but found [0]` (the #11442 case). - I compared the new code with a plain set intersection on 200,000 random pairs of increasing arrays (lengths 0 to 11, values 0 to 24), with both argument orders: 0 mismatches. The old code mismatched on 108,787 of them. - `./mvnw -f pinot-common/pom.xml spotless:check license:check checkstyle:check`: all pass (0 checkstyle violations). - Not run: the full `pinot-common` build and test suite, `ScalarTransformFunctionWrapperTest` in `pinot-core`, and the integration tests (I worked from a partial checkout). -- 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]
