mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Aggregations: if maxOrd is 0 then use noop collector
Before the OrdinalsCollector was used and this leads to a ArrayIndexOutOfBoundsException Closes #6413
This commit is contained in:
parent
e15d2e2514
commit
38be1e0dde
@ -93,6 +93,10 @@ public class CardinalityAggregator extends NumericMetricsAggregator.SingleValue
|
|||||||
if (bytesValues instanceof BytesValues.WithOrdinals) {
|
if (bytesValues instanceof BytesValues.WithOrdinals) {
|
||||||
BytesValues.WithOrdinals values = (BytesValues.WithOrdinals) bytesValues;
|
BytesValues.WithOrdinals values = (BytesValues.WithOrdinals) bytesValues;
|
||||||
final long maxOrd = values.ordinals().getMaxOrd();
|
final long maxOrd = values.ordinals().getMaxOrd();
|
||||||
|
if (maxOrd == 0) {
|
||||||
|
return new EmptyCollector();
|
||||||
|
}
|
||||||
|
|
||||||
final long ordinalsMemoryUsage = OrdinalsCollector.memoryOverhead(maxOrd);
|
final long ordinalsMemoryUsage = OrdinalsCollector.memoryOverhead(maxOrd);
|
||||||
final long countsMemoryUsage = HyperLogLogPlusPlus.memoryUsage(precision);
|
final long countsMemoryUsage = HyperLogLogPlusPlus.memoryUsage(precision);
|
||||||
// only use ordinals if they don't increase memory usage by more than 25%
|
// only use ordinals if they don't increase memory usage by more than 25%
|
||||||
@ -166,6 +170,24 @@ public class CardinalityAggregator extends NumericMetricsAggregator.SingleValue
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class EmptyCollector implements Collector {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collect(int doc, long bucketOrd) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postCollect() {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws ElasticsearchException {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class DirectCollector implements Collector {
|
private static class DirectCollector implements Collector {
|
||||||
|
|
||||||
private final LongValues hashes;
|
private final LongValues hashes;
|
||||||
|
@ -123,6 +123,13 @@ public class CardinalityTests extends ElasticsearchIntegrationTest {
|
|||||||
}
|
}
|
||||||
indexRandom(true, builders);
|
indexRandom(true, builders);
|
||||||
createIndex("idx_unmapped");
|
createIndex("idx_unmapped");
|
||||||
|
|
||||||
|
IndexRequestBuilder[] dummyDocsBuilder = new IndexRequestBuilder[10];
|
||||||
|
for (int i = 0; i < dummyDocsBuilder.length; i++) {
|
||||||
|
dummyDocsBuilder[i] = client().prepareIndex("idx", "type").setSource("a_field", "1");
|
||||||
|
}
|
||||||
|
indexRandom(true, dummyDocsBuilder);
|
||||||
|
|
||||||
ensureSearchable();
|
ensureSearchable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user