-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
Signed-off-by: Sarthak Aggarwal <[email protected]>
- Loading branch information
There are no files selected for viewing
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); | ||
Check warning on line 63 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MaxValueAggregator.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MaxValueAggregator.java#L62-L63
|
||
} | ||
} | ||
|
||
@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); | ||
Check warning on line 72 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MaxValueAggregator.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MaxValueAggregator.java#L71-L72
|
||
} | ||
} | ||
} |
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); | ||
Check warning on line 63 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MinValueAggregator.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MinValueAggregator.java#L62-L63
|
||
} | ||
} | ||
|
||
@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); | ||
Check warning on line 72 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MinValueAggregator.java Codecov / codecov/patchserver/src/main/java/org/opensearch/index/compositeindex/datacube/startree/aggregators/MinValueAggregator.java#L71-L72
|
||
} | ||
} | ||
} |
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); | ||
} | ||
} |
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); | ||
} | ||
} |