-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add support for value_count for exponential_histogram field #136163
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
Merged
JonasKunz
merged 12 commits into
elastic:main
from
JonasKunz:exp-histo-querydsl-valuecount
Oct 14, 2025
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
989880d
Add exponential histogram value counts aggregation
JonasKunz 2e06feb
Add value count aggregation tests
JonasKunz 87e0ec0
Add yaml rest test
JonasKunz f771daa
Fix test edge case failure
JonasKunz 2275e61
Fix test flakes
JonasKunz 09dfdeb
Refine required apis for yaml rest tests
JonasKunz 092bbe2
Self-review fixes
JonasKunz 225241c
Fix testing conventions
JonasKunz e40e4d1
Merge branch 'main' into exp-histo-querydsl-valuecount
JonasKunz bdd5667
make ExponentialHistogramFieldType final
JonasKunz 56863dd
Merge remote-tracking branch 'elastic/main' into exp-histo-querydsl-v…
JonasKunz 1c32d60
[CI] Auto commit changes from spotless
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...k/exponentialhistogram/aggregations/metrics/ExponentialHistogramAggregatorsRegistrar.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.exponentialhistogram.aggregations.metrics; | ||
|
||
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder; | ||
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; | ||
import org.elasticsearch.xpack.exponentialhistogram.aggregations.support.ExponentialHistogramValuesSourceType; | ||
|
||
/** | ||
* Utility class providing static methods to register aggregators for the aggregate_metric values source | ||
*/ | ||
public class ExponentialHistogramAggregatorsRegistrar { | ||
|
||
public static void registerValueCountAggregator(ValuesSourceRegistry.Builder builder) { | ||
builder.register( | ||
ValueCountAggregationBuilder.REGISTRY_KEY, | ||
ExponentialHistogramValuesSourceType.EXPONENTIAL_HISTOGRAM, | ||
ExponentialHistogramValueCountAggregator::new, | ||
true | ||
); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...k/exponentialhistogram/aggregations/metrics/ExponentialHistogramValueCountAggregator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.exponentialhistogram.aggregations.metrics; | ||
|
||
import org.elasticsearch.common.util.BigArrays; | ||
import org.elasticsearch.common.util.LongArray; | ||
import org.elasticsearch.core.Releasables; | ||
import org.elasticsearch.search.aggregations.AggregationExecutionContext; | ||
import org.elasticsearch.search.aggregations.Aggregator; | ||
import org.elasticsearch.search.aggregations.InternalAggregation; | ||
import org.elasticsearch.search.aggregations.LeafBucketCollector; | ||
import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; | ||
import org.elasticsearch.search.aggregations.metrics.InternalValueCount; | ||
import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; | ||
import org.elasticsearch.search.aggregations.support.AggregationContext; | ||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; | ||
import org.elasticsearch.xpack.exponentialhistogram.aggregations.support.ExponentialHistogramValuesSource; | ||
import org.elasticsearch.xpack.exponentialhistogram.fielddata.ExponentialHistogramValuesReader; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
class ExponentialHistogramValueCountAggregator extends NumericMetricsAggregator.SingleValue { | ||
|
||
private final ExponentialHistogramValuesSource.ExponentialHistogram valuesSource; | ||
|
||
// a count per bucket | ||
private LongArray counts; | ||
|
||
ExponentialHistogramValueCountAggregator( | ||
String name, | ||
ValuesSourceConfig valuesSourceConfig, | ||
AggregationContext aggregationContext, | ||
Aggregator parent, | ||
Map<String, Object> metadata | ||
) throws IOException { | ||
super(name, aggregationContext, parent, metadata); | ||
assert valuesSourceConfig.hasValues(); | ||
this.valuesSource = (ExponentialHistogramValuesSource.ExponentialHistogram) valuesSourceConfig.getValuesSource(); | ||
counts = bigArrays().newLongArray(1, true); | ||
} | ||
|
||
@Override | ||
public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, final LeafBucketCollector sub) throws IOException { | ||
BigArrays bigArrays = bigArrays(); | ||
ExponentialHistogramValuesReader values = valuesSource.getHistogramValues(aggCtx.getLeafReaderContext()); | ||
|
||
return new LeafBucketCollectorBase(sub, values) { | ||
@Override | ||
public void collect(int doc, long bucket) throws IOException { | ||
counts = bigArrays.grow(counts, bucket + 1); | ||
if (values.advanceExact(doc)) { | ||
counts.increment(bucket, values.valuesCountValue()); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public double metric(long owningBucketOrd) { | ||
return owningBucketOrd >= counts.size() ? 0 : counts.get(owningBucketOrd); | ||
} | ||
|
||
@Override | ||
public InternalAggregation buildAggregation(long bucket) { | ||
if (bucket >= counts.size()) { | ||
return buildEmptyAggregation(); | ||
} | ||
return new InternalValueCount(name, counts.get(bucket), metadata()); | ||
} | ||
|
||
@Override | ||
public InternalAggregation buildEmptyAggregation() { | ||
return InternalValueCount.empty(name, metadata()); | ||
} | ||
|
||
@Override | ||
public void doClose() { | ||
Releasables.close(counts); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.