MOD-7206: [2.6] Fix sorting multiple fields #4717
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the changes in the pull request
Fixing sorting by multiple keys, when the two rows are missing the primary(s) key(s) but hold a value for secondary(s).
Consider the case where
doc1 = {docID = 1, n = 93}
,doc2 = {docID = 2, n = 46}
.We want to sort by a
missing
field as the primary sort, and byn
as a secondary.... SORTBY 2 @missing @n ...
Since both are missing a value for
missing
, we should treat them as equals and continue to compare them according to the secondaryn
key. We get thatdoc2
is the first anddoc1
is the second (doc1.n > doc2.n
)Before the fix, we would see that they both are missing
missing
and we will immediately fall back to comparing them by docID (our last resort). In this case we get thatdoc1
is the first anddoc2
is the second (doc1.docID < doc2.docID
)Which issues this PR fixes
2.8
and forwardOnly relevant for the 2.6 branch.
Mark if applicable