-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Star Tree Min and Max Value Aggregators (#14625)
--------- Signed-off-by: Sarthak Aggarwal <[email protected]>
- Loading branch information
1 parent
3db2525
commit e21f6b8
Showing
18 changed files
with
1,049 additions
and
309 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
27 changes: 27 additions & 0 deletions
27
...org/opensearch/index/compositeindex/datacube/startree/aggregators/MaxValueAggregator.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,27 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.index.compositeindex.datacube.startree.aggregators; | ||
|
||
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType; | ||
|
||
/** | ||
* Max value aggregator for star tree | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
class MaxValueAggregator extends StatelessDoubleValueAggregator { | ||
|
||
public MaxValueAggregator(StarTreeNumericType starTreeNumericType) { | ||
super(starTreeNumericType, null); | ||
} | ||
|
||
@Override | ||
protected Double performValueAggregation(Double aggregatedValue, Double segmentDocValue) { | ||
return Math.max(aggregatedValue, segmentDocValue); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...org/opensearch/index/compositeindex/datacube/startree/aggregators/MinValueAggregator.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,27 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.index.compositeindex.datacube.startree.aggregators; | ||
|
||
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType; | ||
|
||
/** | ||
* Min value aggregator for star tree | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
class MinValueAggregator extends StatelessDoubleValueAggregator { | ||
|
||
public MinValueAggregator(StarTreeNumericType starTreeNumericType) { | ||
super(starTreeNumericType, null); | ||
} | ||
|
||
@Override | ||
protected Double performValueAggregation(Double aggregatedValue, Double segmentDocValue) { | ||
return Math.min(aggregatedValue, segmentDocValue); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...ch/index/compositeindex/datacube/startree/aggregators/StatelessDoubleValueAggregator.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,81 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.index.compositeindex.datacube.startree.aggregators; | ||
|
||
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType; | ||
|
||
/** | ||
* This is an abstract class that defines the common methods for all double value aggregators | ||
* It is stateless. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
abstract class StatelessDoubleValueAggregator implements ValueAggregator<Double> { | ||
|
||
protected final StarTreeNumericType starTreeNumericType; | ||
protected final Double identityValue; | ||
private static final StarTreeNumericType VALUE_AGGREGATOR_TYPE = StarTreeNumericType.DOUBLE; | ||
|
||
public StatelessDoubleValueAggregator(StarTreeNumericType starTreeNumericType, Double identityValue) { | ||
this.starTreeNumericType = starTreeNumericType; | ||
this.identityValue = identityValue; | ||
} | ||
|
||
@Override | ||
public StarTreeNumericType getAggregatedValueType() { | ||
return VALUE_AGGREGATOR_TYPE; | ||
} | ||
|
||
@Override | ||
public Double getInitialAggregatedValueForSegmentDocValue(Long segmentDocValue) { | ||
if (segmentDocValue == null) { | ||
return getIdentityMetricValue(); | ||
} | ||
return starTreeNumericType.getDoubleValue(segmentDocValue); | ||
} | ||
|
||
@Override | ||
public Double mergeAggregatedValues(Double value, Double aggregatedValue) { | ||
if (value == null && aggregatedValue != null) { | ||
return aggregatedValue; | ||
} else if (value != null && aggregatedValue == null) { | ||
return value; | ||
} else if (value == null) { | ||
return getIdentityMetricValue(); | ||
} | ||
return performValueAggregation(value, aggregatedValue); | ||
} | ||
|
||
@Override | ||
public Double toStarTreeNumericTypeValue(Long value) { | ||
try { | ||
if (value == null) { | ||
return getIdentityMetricValue(); | ||
} | ||
return starTreeNumericType.getDoubleValue(value); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Cannot convert " + value + " to sortable aggregation type", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Double getIdentityMetricValue() { | ||
// the identity value that we return should be inline with the existing aggregations | ||
return identityValue; | ||
} | ||
|
||
/** | ||
* Performs stateless aggregation on the value and the segmentDocValue based on the implementation | ||
* | ||
* @param aggregatedValue aggregated value for the segment so far | ||
* @param segmentDocValue current segment doc value | ||
* @return aggregated value | ||
*/ | ||
protected abstract Double performValueAggregation(Double aggregatedValue, Double segmentDocValue); | ||
|
||
} |
Oops, something went wrong.