Skip to content
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

Remove filter rewrite optimization for range aggregations when segment is not effective match all #15194

Merged
merged 19 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not build shard level ranges if query is not effective match all f…
…or range agg filter rewrite optimization

Signed-off-by: Finn Carroll <carrofin@amazon.com>
  • Loading branch information
finnegancarroll committed Aug 13, 2024
commit 77d8628d2a2af1896c9dd45f6745ae16d9c5d414
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private Helper() {}
* Recursively unwraps query into the concrete form
* for applying the optimization
*/
private static Query unwrapIntoConcreteQuery(Query query) {
public static Query unwrapIntoConcreteQuery(Query query) {
finnegancarroll marked this conversation as resolved.
Show resolved Hide resolved
while (queryWrappers.containsKey(query.getClass())) {
query = queryWrappers.get(query.getClass()).apply(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.opensearch.index.mapper.MappedFieldType;
import org.opensearch.index.mapper.NumericPointEncoder;
import org.opensearch.search.aggregations.bucket.range.RangeAggregator;
import org.opensearch.search.aggregations.support.ValuesSource;
import org.opensearch.search.aggregations.support.ValuesSourceConfig;
import org.opensearch.search.internal.SearchContext;

import java.io.IOException;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -51,8 +54,14 @@ protected boolean canOptimize(ValuesSourceConfig config, RangeAggregator.Range[]
return false;
}

protected void buildRanges(RangeAggregator.Range[] ranges) {
protected void buildRanges(RangeAggregator.Range[] ranges, SearchContext context) {
assert fieldType instanceof NumericPointEncoder;
Query unwrap = Helper.unwrapIntoConcreteQuery(context.query());
if (!(unwrap instanceof MatchAllDocsQuery)) {
setRanges.accept(null);
return;
}

finnegancarroll marked this conversation as resolved.
Show resolved Hide resolved
NumericPointEncoder numericPointEncoder = (NumericPointEncoder) fieldType;
byte[][] lowers = new byte[ranges.length][];
byte[][] uppers = new byte[ranges.length][];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ protected boolean canOptimize() {

@Override
protected void prepare() {
buildRanges(ranges);
buildRanges(ranges, context);
}

@Override
Expand Down