-
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.
Signed-off-by: Sarthak Aggarwal <[email protected]>
- Loading branch information
1 parent
b3b743d
commit 0689c64
Showing
6 changed files
with
490 additions
and
129 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...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,75 @@ | ||
/* | ||
* 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.apache.lucene.util.NumericUtils; | ||
import org.opensearch.index.compositeindex.datacube.MetricStat; | ||
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType; | ||
|
||
/** | ||
* Max value aggregator for star tree | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class MaxValueAggregator implements ValueAggregator<Double> { | ||
|
||
public static final StarTreeNumericType VALUE_AGGREGATOR_TYPE = StarTreeNumericType.DOUBLE; | ||
|
||
@Override | ||
public MetricStat getAggregationType() { | ||
return MetricStat.MAX; | ||
} | ||
|
||
@Override | ||
public StarTreeNumericType getAggregatedValueType() { | ||
return VALUE_AGGREGATOR_TYPE; | ||
} | ||
|
||
@Override | ||
public Double getInitialAggregatedValueForSegmentDocValue(Long segmentDocValue, StarTreeNumericType starTreeNumericType) { | ||
return starTreeNumericType.getDoubleValue(segmentDocValue); | ||
} | ||
|
||
@Override | ||
public Double mergeAggregatedValueAndSegmentValue(Double value, Long segmentDocValue, StarTreeNumericType starTreeNumericType) { | ||
return Math.max(value, starTreeNumericType.getDoubleValue(segmentDocValue)); | ||
} | ||
|
||
@Override | ||
public Double mergeAggregatedValues(Double value, Double aggregatedValue) { | ||
return Math.max(value, aggregatedValue); | ||
} | ||
|
||
@Override | ||
public Double getInitialAggregatedValue(Double value) { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int getMaxAggregatedValueByteSize() { | ||
return Double.BYTES; | ||
} | ||
|
||
@Override | ||
public Long toLongValue(Double value) { | ||
try { | ||
return NumericUtils.doubleToSortableLong(value); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Cannot convert " + value + " to sortable long", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Double toStarTreeNumericTypeValue(Long value, StarTreeNumericType type) { | ||
try { | ||
return type.getDoubleValue(value); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Cannot convert " + value + " to sortable aggregation type", e); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...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,75 @@ | ||
/* | ||
* 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.apache.lucene.util.NumericUtils; | ||
import org.opensearch.index.compositeindex.datacube.MetricStat; | ||
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType; | ||
|
||
/** | ||
* Min value aggregator for star tree | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class MinValueAggregator implements ValueAggregator<Double> { | ||
|
||
public static final StarTreeNumericType VALUE_AGGREGATOR_TYPE = StarTreeNumericType.DOUBLE; | ||
|
||
@Override | ||
public MetricStat getAggregationType() { | ||
return MetricStat.MIN; | ||
} | ||
|
||
@Override | ||
public StarTreeNumericType getAggregatedValueType() { | ||
return VALUE_AGGREGATOR_TYPE; | ||
} | ||
|
||
@Override | ||
public Double getInitialAggregatedValueForSegmentDocValue(Long segmentDocValue, StarTreeNumericType starTreeNumericType) { | ||
return starTreeNumericType.getDoubleValue(segmentDocValue); | ||
} | ||
|
||
@Override | ||
public Double mergeAggregatedValueAndSegmentValue(Double value, Long segmentDocValue, StarTreeNumericType starTreeNumericType) { | ||
return Math.min(value, starTreeNumericType.getDoubleValue(segmentDocValue)); | ||
} | ||
|
||
@Override | ||
public Double mergeAggregatedValues(Double value, Double aggregatedValue) { | ||
return Math.min(value, aggregatedValue); | ||
} | ||
|
||
@Override | ||
public Double getInitialAggregatedValue(Double value) { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int getMaxAggregatedValueByteSize() { | ||
return Double.BYTES; | ||
} | ||
|
||
@Override | ||
public Long toLongValue(Double value) { | ||
try { | ||
return NumericUtils.doubleToSortableLong(value); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Cannot convert " + value + " to sortable long", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Double toStarTreeNumericTypeValue(Long value, StarTreeNumericType type) { | ||
try { | ||
return type.getDoubleValue(value); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Cannot convert " + value + " to sortable aggregation type", e); | ||
} | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...pensearch/index/compositeindex/datacube/startree/aggregators/MaxValueAggregatorTests.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,58 @@ | ||
/* | ||
* 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.apache.lucene.util.NumericUtils; | ||
import org.opensearch.index.compositeindex.datacube.MetricStat; | ||
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class MaxValueAggregatorTests extends OpenSearchTestCase { | ||
private final MaxValueAggregator aggregator = new MaxValueAggregator(); | ||
|
||
public void testGetAggregationType() { | ||
assertEquals(MetricStat.MAX.getTypeName(), aggregator.getAggregationType().getTypeName()); | ||
} | ||
|
||
public void testGetAggregatedValueType() { | ||
assertEquals(MaxValueAggregator.VALUE_AGGREGATOR_TYPE, aggregator.getAggregatedValueType()); | ||
} | ||
|
||
public void testGetInitialAggregatedValueForSegmentDocValue() { | ||
assertEquals(1.0, aggregator.getInitialAggregatedValueForSegmentDocValue(1L, StarTreeNumericType.LONG), 0.0); | ||
assertThrows( | ||
NullPointerException.class, | ||
() -> aggregator.getInitialAggregatedValueForSegmentDocValue(null, StarTreeNumericType.DOUBLE) | ||
); | ||
} | ||
|
||
public void testMergeAggregatedValueAndSegmentValue() { | ||
assertEquals(3.0, aggregator.mergeAggregatedValueAndSegmentValue(2.0, 3L, StarTreeNumericType.LONG), 0.0); | ||
} | ||
|
||
public void testMergeAggregatedValues() { | ||
assertEquals(3.0, aggregator.mergeAggregatedValues(2.0, 3.0), 0.0); | ||
} | ||
|
||
public void testGetInitialAggregatedValue() { | ||
assertEquals(3.0, aggregator.getInitialAggregatedValue(3.0), 0.0); | ||
} | ||
|
||
public void testGetMaxAggregatedValueByteSize() { | ||
assertEquals(Double.BYTES, aggregator.getMaxAggregatedValueByteSize()); | ||
} | ||
|
||
public void testToLongValue() { | ||
assertEquals(NumericUtils.doubleToSortableLong(3.0), aggregator.toLongValue(3.0), 0.0); | ||
} | ||
|
||
public void testToStarTreeNumericTypeValue() { | ||
assertEquals(NumericUtils.sortableLongToDouble(3L), aggregator.toStarTreeNumericTypeValue(3L, StarTreeNumericType.DOUBLE), 0.0); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...pensearch/index/compositeindex/datacube/startree/aggregators/MinValueAggregatorTests.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,58 @@ | ||
/* | ||
* 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.apache.lucene.util.NumericUtils; | ||
import org.opensearch.index.compositeindex.datacube.MetricStat; | ||
import org.opensearch.index.compositeindex.datacube.startree.aggregators.numerictype.StarTreeNumericType; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class MinValueAggregatorTests extends OpenSearchTestCase { | ||
private final MinValueAggregator aggregator = new MinValueAggregator(); | ||
|
||
public void testGetAggregationType() { | ||
assertEquals(MetricStat.MIN.getTypeName(), aggregator.getAggregationType().getTypeName()); | ||
} | ||
|
||
public void testGetAggregatedValueType() { | ||
assertEquals(MinValueAggregator.VALUE_AGGREGATOR_TYPE, aggregator.getAggregatedValueType()); | ||
} | ||
|
||
public void testGetInitialAggregatedValueForSegmentDocValue() { | ||
assertEquals(1.0, aggregator.getInitialAggregatedValueForSegmentDocValue(1L, StarTreeNumericType.LONG), 0.0); | ||
assertThrows( | ||
NullPointerException.class, | ||
() -> aggregator.getInitialAggregatedValueForSegmentDocValue(null, StarTreeNumericType.DOUBLE) | ||
); | ||
} | ||
|
||
public void testMergeAggregatedValueAndSegmentValue() { | ||
assertEquals(2.0, aggregator.mergeAggregatedValueAndSegmentValue(2.0, 3L, StarTreeNumericType.LONG), 0.0); | ||
} | ||
|
||
public void testMergeAggregatedValues() { | ||
assertEquals(2.0, aggregator.mergeAggregatedValues(2.0, 3.0), 0.0); | ||
} | ||
|
||
public void testGetInitialAggregatedValue() { | ||
assertEquals(3.0, aggregator.getInitialAggregatedValue(3.0), 0.0); | ||
} | ||
|
||
public void testGetMaxAggregatedValueByteSize() { | ||
assertEquals(Double.BYTES, aggregator.getMaxAggregatedValueByteSize()); | ||
} | ||
|
||
public void testToLongValue() { | ||
assertEquals(NumericUtils.doubleToSortableLong(3.0), aggregator.toLongValue(3.0), 0.0); | ||
} | ||
|
||
public void testToStarTreeNumericTypeValue() { | ||
assertEquals(NumericUtils.sortableLongToDouble(3L), aggregator.toStarTreeNumericTypeValue(3L, StarTreeNumericType.DOUBLE), 0.0); | ||
} | ||
} |
Oops, something went wrong.