-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for the rate aggregation under a composite agg (#76992)
rate aggregation should support being a sub-aggregation of a composite agg. The catch is that the composite aggregation source must be a date histogram. Other sources can be present but their must be exactly one date histogram source otherwise the rate aggregation does not know which interval to compare its unit rate to. closes #76988
- Loading branch information
Showing
7 changed files
with
415 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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
56 changes: 56 additions & 0 deletions
56
...ava/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSource.java
This file contains 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,56 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.search.aggregations.bucket.composite; | ||
|
||
import org.elasticsearch.common.Rounding; | ||
import org.elasticsearch.common.util.BigArrays; | ||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
import org.elasticsearch.search.DocValueFormat; | ||
import org.elasticsearch.search.aggregations.bucket.histogram.SizedBucketAggregator; | ||
|
||
/** | ||
* A {@link SingleDimensionValuesSource} for date histogram values. | ||
*/ | ||
public class DateHistogramValuesSource extends LongValuesSource implements SizedBucketAggregator { | ||
private final RoundingValuesSource preparedRounding; | ||
|
||
DateHistogramValuesSource( | ||
BigArrays bigArrays, | ||
MappedFieldType fieldType, | ||
RoundingValuesSource roundingValuesSource, | ||
DocValueFormat format, | ||
boolean missingBucket, | ||
int size, | ||
int reverseMul | ||
) { | ||
super(bigArrays, fieldType, roundingValuesSource::longValues, roundingValuesSource::round, format, missingBucket, size, reverseMul); | ||
this.preparedRounding = roundingValuesSource; | ||
} | ||
|
||
@Override | ||
public double bucketSize(long bucket, Rounding.DateTimeUnit unitSize) { | ||
if (unitSize != null) { | ||
Long value = toComparable((int) bucket); | ||
assert value != null : "unexpected null value in composite agg bucket [" + (int) bucket + "]"; | ||
return preparedRounding.roundingSize(value, unitSize); | ||
} else { | ||
return 1.0; | ||
} | ||
} | ||
|
||
@Override | ||
public double bucketSize(Rounding.DateTimeUnit unitSize) { | ||
if (unitSize != null) { | ||
return preparedRounding.roundingSize(unitSize); | ||
} else { | ||
return 1.0; | ||
} | ||
} | ||
|
||
} |
This file contains 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 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 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
Oops, something went wrong.