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

Avoid global ordinals in composite aggregation #74559

Merged
merged 18 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* A specialized {@link PriorityQueue} implementation for composite buckets.
Expand Down Expand Up @@ -56,6 +58,7 @@ public int hashCode() {

private LongArray docCounts;
private boolean afterKeyIsSet = false;
private int leafReaderOrd = -1; // current LeafReaderContext ordinal

/**
* Constructs a composite queue with the specified size and sources.
Expand Down Expand Up @@ -230,14 +233,26 @@ LeafBucketCollector getLeafCollector(Comparable forceLeadSourceValue,
LeafReaderContext context, LeafBucketCollector in) throws IOException {
int last = arrays.length - 1;
LeafBucketCollector collector = in;
boolean requiresRehashingWhenSwitchingLeafReaders = false;
while (last > 0) {
collector = arrays[last--].getLeafCollector(context, collector);
SingleDimensionValuesSource<?> valuesSource = arrays[last--];
requiresRehashingWhenSwitchingLeafReaders |= valuesSource.requiresRehashingWhenSwitchingLeafReaders();
collector = valuesSource.getLeafCollector(context, collector);
}
SingleDimensionValuesSource<?> valuesSource = arrays[last];
requiresRehashingWhenSwitchingLeafReaders |= valuesSource.requiresRehashingWhenSwitchingLeafReaders();
if (forceLeadSourceValue != null) {
collector = arrays[last].getLeafCollector(forceLeadSourceValue, context, collector);
collector = valuesSource.getLeafCollector(forceLeadSourceValue, context, collector);
} else {
collector = arrays[last].getLeafCollector(context, collector);
collector = valuesSource.getLeafCollector(context, collector);
}
boolean switchedLeafReaders = context.ord != leafReaderOrd;
if (map.isEmpty() == false && requiresRehashingWhenSwitchingLeafReaders && switchedLeafReaders) {
List<Map.Entry<Slot, Integer>> entries = map.entrySet().stream().collect(Collectors.toList());
map.clear();
entries.forEach(e -> map.put(e.getKey(), e.getValue()));
}
leafReaderOrd = context.ord;
return collector;
}

Expand Down

This file was deleted.

Loading