-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Remove QueryCollectorContext abstraction #95383
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
Conversation
| // plug in additional collectors, like aggregations | ||
| collectors.add(createAggsCollectorContext(searchContext.getAggsCollector())); | ||
| List<Collector> subCollectors = new ArrayList<>(); | ||
| subCollectors.add(collector); |
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.
I wonder if we can move this complexity in the wrapWithProfilerCollectorIfNeeded method. The ide awould be to use varargs in the method like:
private static Collector wrapWithProfilerCollectorIfNeeded(
Profilers profilers,
Collector collector,
String profilerName,
Collector... children
) {
if (profilers == null) {
return collector;
}
final List<InternalProfileCollector> profileCollectors;
if (children == null) {
profileCollectors = List.of();
} else {
profileCollectors = new ArrayList<>(children.length);
Arrays.stream(children).forEach(c -> profileCollectors.add((InternalProfileCollector) c));
}
return new InternalProfileCollector(
collector,
profilerName,
profileCollectors
);
}
So here we can just call the method like:
// plug in additional collectors, like aggregations
// in this case we pass both collectors as children profile collectors
collector = wrapWithProfilerCollectorIfNeeded(
searchContext.getProfilers(),
MultiCollector.wrap(collector, searchContext.getAggsCollector()),
REASON_SEARCH_MULTI,
collector,
searchContext.getAggsCollector());
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.
I tried that, it looked a bit awkward. I will try again.
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.
I think this will work, #95427 will also help in that direction so that InternalProfileCollector no longer requires a list.
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.
The casting needed was a bit on the way and did not combine well with the varargs, but I found a way to reuse the wrap method for aggs too. It's not perfect but it's better than before I think.
|
I like the direction of this PR, it makes the code much easier to follow. |
server/src/main/java/org/elasticsearch/search/query/QueryPhase.java
Outdated
Show resolved
Hide resolved
|
Pinging @elastic/es-search (Team:Search) |
iverase
left a comment
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.
LGTM
This is to complete the removal of the query collector context abstraction implemented with elastic#95383. The remaining TopDocsCollectorContext is more of a factory than a context object. This commit renames the class and all of its subclasses. It also adds javadocs to its methods to clarify the contract around them.
This is to complete the removal of the query collector context abstraction implemented with #95383. The remaining TopDocsCollectorContext is more of a factory than a context object. This commit renames the class and all of its subclasses. It also adds javadocs to its methods to clarify the contract around them.
The
QueryCollectorContextabstraction was introduced by #24864 based on the requirement that the top docs collector creation needed to be delayed until after all the other collectors had been created. At the same time, collectors get wrapped depending on the search features enabled by the request, but the top score / total hit count collector is the root collector where the wrapping starts, which is why its corresponding context gets added at position0in the list of collector contexts.Requirements have changed since #27666 , which means that we can go back to a simpler way of creating collectors and wrapping them. We no longer need a
QueryCollectorContextabstraction, and we can instead create collectors straight-away, and wrap them as needed. This is much easier to follow compared to the very genericcreate(Collector)method that the context exposes.TopDocsCollectorContextadds some value in that it incorporates all the logic around creating the top docs collector, yet it can be further simplified as well by making thepostProcessmethod more specific.