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

Support Dynamic Pruning in Cardinality Aggregation #13821

Merged
merged 30 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3414609
Cardinality aggregation dynamic pruning changes
rishabhmaurya Feb 14, 2024
0d6f151
Reading
bowenlan-amzn May 16, 2024
a18b597
remaining disjunction scorer full understand
bowenlan-amzn May 21, 2024
85133c4
utilize competitive iterator api to perform pruning
bowenlan-amzn May 24, 2024
9d4701c
handle missing input
bowenlan-amzn May 24, 2024
77fceea
add change log
bowenlan-amzn May 24, 2024
d53182b
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn May 24, 2024
09f957c
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 2, 2024
bfcfa74
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 3, 2024
f76cd8e
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 3, 2024
9991575
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 3, 2024
d0043ae
clean up
bowenlan-amzn Jun 4, 2024
82a5f06
Clean up
bowenlan-amzn Jun 4, 2024
35ee3ed
Test fix
bowenlan-amzn Jun 5, 2024
f35ac3a
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 6, 2024
5d4c6f2
Do all the scoring within Cardinality
bowenlan-amzn Jun 6, 2024
101d642
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 6, 2024
a2f4bfb
clean unnecessary
bowenlan-amzn Jun 6, 2024
d4a3a5d
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 7, 2024
29f0841
fix
bowenlan-amzn Jun 7, 2024
04d6339
Add dynamic flag for this feature
bowenlan-amzn Jun 7, 2024
b5888a0
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 7, 2024
f1098f8
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 9, 2024
c47a35b
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 10, 2024
8ea3588
Add random test, small bug fix
bowenlan-amzn Jun 10, 2024
1ae4a3a
address comment
bowenlan-amzn Jun 10, 2024
36f3745
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 10, 2024
db35f72
Address comments
bowenlan-amzn Jun 11, 2024
0d02f6f
Merge branch 'main' into 11959-cardi-agg-pruning
bowenlan-amzn Jun 11, 2024
5f7dad3
address comments
bowenlan-amzn Jun 11, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Move Remote Store Migration from DocRep to GA and modify remote migration settings name ([#14100](https://github.com/opensearch-project/OpenSearch/pull/14100))
- Derived field object type support ([#13720](https://github.com/opensearch-project/OpenSearch/pull/13720))
- [Query Insights] Add cpu and memory metrics to top n queries ([#13739](https://github.com/opensearch-project/OpenSearch/pull/13739))
- Support Dynamic Pruning in Cardinality Aggregation ([#13821](https://github.com/opensearch-project/OpenSearch/pull/13821))

### Dependencies
- Bump `com.github.spullara.mustache.java:compiler` from 0.9.10 to 0.9.13 ([#13329](https://github.com/opensearch-project/OpenSearch/pull/13329), [#13559](https://github.com/opensearch-project/OpenSearch/pull/13559))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.common.settings.Settings;
Expand All @@ -59,6 +60,7 @@
import static java.util.Collections.emptyMap;
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
import static org.opensearch.search.SearchService.CARDINALITY_AGGREGATION_PRUNING_THRESHOLD;
import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
import static org.opensearch.search.aggregations.AggregationBuilders.cardinality;
import static org.opensearch.search.aggregations.AggregationBuilders.global;
Expand Down Expand Up @@ -255,6 +257,36 @@ public void testSingleValuedString() throws Exception {
assertCount(count, numDocs);
}

public void testDisableDynamicPruning() throws Exception {
SearchResponse response = client().prepareSearch("idx")
.addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value"))
.get();
assertSearchResponse(response);

Cardinality count1 = response.getAggregations().get("cardinality");

final ClusterUpdateSettingsResponse updateSettingResponse = client().admin()
.cluster()
.prepareUpdateSettings()
.setTransientSettings(Settings.builder().put(CARDINALITY_AGGREGATION_PRUNING_THRESHOLD.getKey(), 0))
.get();
assertEquals(updateSettingResponse.getTransientSettings().get(CARDINALITY_AGGREGATION_PRUNING_THRESHOLD.getKey()), "0");

response = client().prepareSearch("idx")
.addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value"))
.get();
assertSearchResponse(response);
Cardinality count2 = response.getAggregations().get("cardinality");

assertEquals(count1, count2);

client().admin()
.cluster()
.prepareUpdateSettings()
.setTransientSettings(Settings.builder().putNull(CARDINALITY_AGGREGATION_PRUNING_THRESHOLD.getKey()))
.get();
}

public void testSingleValuedNumeric() throws Exception {
SearchResponse response = client().prepareSearch("idx")
.addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ public void apply(Settings value, Settings current, Settings previous) {
SearchService.MAX_OPEN_PIT_CONTEXT,
SearchService.MAX_PIT_KEEPALIVE_SETTING,
SearchService.MAX_AGGREGATION_REWRITE_FILTERS,
SearchService.CARDINALITY_AGGREGATION_PRUNING_THRESHOLD,
CreatePitController.PIT_INIT_KEEP_ALIVE,
Node.WRITE_PORTS_FILE_SETTING,
Node.NODE_NAME_SETTING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import java.util.function.Function;
import java.util.function.LongSupplier;

import static org.opensearch.search.SearchService.CARDINALITY_AGGREGATION_PRUNING_THRESHOLD;
import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
import static org.opensearch.search.SearchService.MAX_AGGREGATION_REWRITE_FILTERS;

Expand Down Expand Up @@ -189,6 +190,7 @@
private final boolean concurrentSearchSettingsEnabled;
private final SetOnce<Boolean> requestShouldUseConcurrentSearch = new SetOnce<>();
private final int maxAggRewriteFilters;
private final int cardinalityAggregationPruningThreshold;

DefaultSearchContext(
ReaderContext readerContext,
Expand Down Expand Up @@ -244,6 +246,7 @@
this.requestToAggReduceContextBuilder = requestToAggReduceContextBuilder;

this.maxAggRewriteFilters = evaluateFilterRewriteSetting();
this.cardinalityAggregationPruningThreshold = evaluateCardinalityAggregationPruningThreshold();
}

@Override
Expand Down Expand Up @@ -1010,4 +1013,16 @@
}
return 0;
}

@Override
public int cardinalityAggregationPruningThreshold() {
return cardinalityAggregationPruningThreshold;

Check warning on line 1019 in server/src/main/java/org/opensearch/search/DefaultSearchContext.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/DefaultSearchContext.java#L1019

Added line #L1019 was not covered by tests
}

private int evaluateCardinalityAggregationPruningThreshold() {
if (clusterService != null) {
return clusterService.getClusterSettings().get(CARDINALITY_AGGREGATION_PRUNING_THRESHOLD);
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
Property.NodeScope
);

// value 0 can disable dynamic pruning optimization in cardinality aggregation
public static final Setting<Integer> CARDINALITY_AGGREGATION_PRUNING_THRESHOLD = Setting.intSetting(
"search.dynamic_pruning.cardinality_aggregation.max_allowed_cardinality",
100,
mch2 marked this conversation as resolved.
Show resolved Hide resolved
0,
Property.Dynamic,
Property.NodeScope
);

public static final int DEFAULT_SIZE = 10;
public static final int DEFAULT_FROM = 0;

Expand Down
Loading
Loading