-
Notifications
You must be signed in to change notification settings - Fork 860
SOLR-18418: Fix complement()/intersect() with asymmetric on= #4873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dsmiley
wants to merge
2
commits into
apache:main
Choose a base branch
from
dsmiley:SOLR-18418-complement-intersect-asymmetric-on-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
changelog/unreleased/SOLR-18418-fix-complement-intersect-asymmetric-on.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| title: Fix complement() and intersect() streaming expressions silently returning wrong | ||
| results when on= maps two differently-named fields | ||
| type: fixed | ||
| authors: | ||
| - name: David Smiley | ||
| url: https://home.apache.org/phonebook.html?uid=dsmiley | ||
| links: | ||
| - name: SOLR-18418 | ||
| url: https://issues.apache.org/jira/browse/SOLR-18418 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ public class ComplementStream extends TupleStream implements Expressible { | |
| private PushBackStream streamB; | ||
| private TupleStream originalStreamB; | ||
| private StreamEqualitor eq; | ||
| private StreamComparator crossStreamComparator; | ||
|
|
||
| public ComplementStream(TupleStream streamA, TupleStream streamB, StreamEqualitor eq) | ||
| throws IOException { | ||
|
|
@@ -94,15 +95,23 @@ public ComplementStream(StreamExpression expression, StreamFactory factory) thro | |
| private void init(TupleStream streamA, TupleStream streamB, StreamEqualitor eq) | ||
| throws IOException { | ||
| this.streamA = new PushBackStream(streamA); | ||
| this.streamB = new PushBackStream(new UniqueStream(streamB, eq)); | ||
| // dedup streamB using only its own (right-side) field(s); using the full, possibly | ||
| // asymmetric eq here would compare streamB's field against a field it doesn't have. | ||
| this.streamB = | ||
| new PushBackStream(new UniqueStream(streamB, StreamEqualitor.deriveRightEqualitor(eq))); | ||
| this.originalStreamB = streamB; // hold onto this for toExpression | ||
| this.eq = eq; | ||
|
|
||
| // streamA and streamB must both be sorted so that comp can be derived from | ||
| if (!eq.isDerivedFrom(streamA.getStreamSort()) || !eq.isDerivedFrom(streamB.getStreamSort())) { | ||
| if (!eq.isDerivedFromLeft(this.streamA.getStreamSort()) | ||
| || !eq.isDerivedFromRight(this.streamB.getStreamSort())) { | ||
| throw new IOException( | ||
| "Invalid ComplementStream - both substream comparators (sort) must be a superset of this stream's equalitor."); | ||
| } | ||
|
|
||
| // comparator used to order a streamA tuple against a streamB tuple; unlike either stream's own | ||
| // sort, it carries eq's (possibly different) left/right field names. | ||
| crossStreamComparator = StreamEqualitor.deriveComparator(eq, this.streamA.getStreamSort()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -201,9 +210,12 @@ public Tuple read() throws IOException { | |
| } | ||
|
|
||
| // if a != b && a < b then we know there is no b which a might equal so return a | ||
| if (!eq.test(a, b) && streamA.getStreamSort().compare(a, b) < 0) { | ||
| streamB.pushBack(b); | ||
| return a; | ||
| if (!eq.test(a, b)) { | ||
| eq.assertFieldsPresent(a, b); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. The placement limits performance impact some more, even though it's detection isn't 100% bulletproof. |
||
| if (crossStreamComparator.compare(a, b) < 0) { | ||
| streamB.pushBack(b); | ||
| return a; | ||
| } | ||
| } | ||
|
|
||
| // if a == b then ignore a cause it exists in b | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is going to be on every tuple reaching this point (and same for other call-sites in this PR). It has some overhead (hashmap lookups) but it saves frustration / trust issues. I think it's the right trade-off.