-
Notifications
You must be signed in to change notification settings - Fork 43
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
fix: Handle compound filters on related indexed fields #2575
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -473,7 +473,6 @@ func (dir *joinDirection) invert() { | |
} | ||
|
||
type invertibleTypeJoin struct { | ||
documentIterator | ||
docMapper | ||
|
||
root planNode | ||
|
@@ -487,6 +486,9 @@ type invertibleTypeJoin struct { | |
secondaryFieldIndex immutable.Option[int] | ||
secondaryFetchLimit uint | ||
|
||
// docsToYield contains cocuments read and ready to be yielded by this node. | ||
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. typo: documents 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. :) will fix
|
||
docsToYield []core.Doc | ||
|
||
dir joinDirection | ||
} | ||
|
||
|
@@ -556,6 +558,17 @@ func (join *invertibleTypeJoin) processSecondResult(secondDocs []core.Doc) (any, | |
} | ||
|
||
func (join *invertibleTypeJoin) Next() (bool, error) { | ||
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. thought: This function is really difficult to understand. 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. Yes, and IMO the variable names don't really pair up well either, and they actually represent different things in different situations. 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. |
||
if len(join.docsToYield) > 0 { | ||
// If there is one or more documents in the queue, drop the first one - | ||
// it will have been yielded by the last `Next()` call. | ||
join.docsToYield = join.docsToYield[1:] | ||
if len(join.docsToYield) > 0 { | ||
// If there are still documents in the queue, return true yielding the next | ||
// one in the queue. | ||
return true, nil | ||
} | ||
} | ||
|
||
hasFirstValue, err := join.dir.firstNode.Next() | ||
|
||
if err != nil || !hasFirstValue { | ||
|
@@ -577,7 +590,14 @@ func (join *invertibleTypeJoin) Next() (bool, error) { | |
return false, err | ||
} | ||
if join.dir.secondNode == join.root { | ||
join.root.Value().Fields[join.subSelect.Index] = join.subType.Value() | ||
if len(secondDocs) == 0 { | ||
return false, nil | ||
} | ||
for i := range secondDocs { | ||
secondDocs[i].Fields[join.subSelect.Index] = join.subType.Value() | ||
} | ||
join.docsToYield = append(join.docsToYield, secondDocs...) | ||
return true, nil | ||
} else { | ||
secondResult, secondIDResult := join.processSecondResult(secondDocs) | ||
join.dir.firstNode.Value().Fields[join.subSelect.Index] = secondResult | ||
|
@@ -596,11 +616,18 @@ func (join *invertibleTypeJoin) Next() (bool, error) { | |
} | ||
} | ||
|
||
join.currentValue = join.root.Value() | ||
join.docsToYield = append(join.docsToYield, join.root.Value()) | ||
|
||
return true, nil | ||
} | ||
|
||
func (join *invertibleTypeJoin) Value() core.Doc { | ||
if len(join.docsToYield) == 0 { | ||
return core.Doc{} | ||
} | ||
return join.docsToYield[0] | ||
} | ||
|
||
func (join *invertibleTypeJoin) invertJoinDirectionWithIndex( | ||
fieldFilter *mapper.Filter, | ||
index client.IndexDescription, | ||
|
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.
It is not ideal to keep this as-is long-term, as it will prevent a possible performance-shortcut once John's fetcher rework gets merged, but for now it is a simple way of excluding the index fetcher filter's lack of support for compound filters..
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.
If we are going to do this might as well remove the if block all together. It's never going to be of length 0.
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.
Will do. I think it is valid to submit an empty and/or clause, but probably not really worth the extra code for that :)