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

Simplify the ValuesSourceRegistry structure #56154

Merged
merged 1 commit into from
May 5, 2020
Merged
Changes from all commits
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
Simplify the ValuesSourceRegistry structure
Follow up to #55747.
  • Loading branch information
imotov committed May 4, 2020
commit ad56f7bd6099d9fa33c15f2e2c7a43c6d2c1461c
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,30 @@ public ValuesSourceRegistry build() {

/** Maps Aggregation names to (ValuesSourceType, Supplier) pairs, keyed by ValuesSourceType */
private final AggregationUsageService usageService;
private Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry;
private Map<String, Map<ValuesSourceType, AggregatorSupplier>> aggregatorRegistry;
public ValuesSourceRegistry(Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry,
AggregationUsageService usageService) {
/*
Make an immutatble copy of our input map. Since this is write once, read many, we'll spend a bit of extra time to shape this
into a Map.of(), which is more read optimized than just using a hash map.
*/
Map.Entry[] copiedEntries = new Map.Entry[aggregatorRegistry.size()];
@SuppressWarnings("unchecked")
Map.Entry<String, Map<ValuesSourceType, AggregatorSupplier>>[] copiedEntries = new Map.Entry[aggregatorRegistry.size()];
int i = 0;
for (Map.Entry<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> entry : aggregatorRegistry.entrySet()) {
String aggName = entry.getKey();
List<Map.Entry<ValuesSourceType, AggregatorSupplier>> values = entry.getValue();
Map.Entry newEntry = Map.entry(aggName, List.of(values.toArray()));
@SuppressWarnings("unchecked") Map.Entry<String, Map<ValuesSourceType, AggregatorSupplier>> newEntry =
Map.entry(aggName, Map.ofEntries(values.toArray(new Map.Entry[0])));
copiedEntries[i++] = newEntry;
}
this.aggregatorRegistry = Map.ofEntries(copiedEntries);
this.usageService = usageService;
}

private AggregatorSupplier findMatchingSuppier(ValuesSourceType valuesSourceType,
List<Map.Entry<ValuesSourceType, AggregatorSupplier>> supportedTypes) {
for (Map.Entry<ValuesSourceType, AggregatorSupplier> candidate : supportedTypes) {
if (candidate.getKey().equals(valuesSourceType)) {
return candidate.getValue();
}
}
return null;
Map<ValuesSourceType, AggregatorSupplier> supportedTypes) {
return supportedTypes.get(valuesSourceType);
}

public AggregatorSupplier getAggregator(ValuesSourceType valuesSourceType, String aggregationName) {
Expand Down