forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Star tree] Doc count field support in star tree (opensearch-project#…
…15282) --------- Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
- Loading branch information
1 parent
16c6fcb
commit 0e55758
Showing
14 changed files
with
644 additions
and
205 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
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
70 changes: 70 additions & 0 deletions
70
...org/opensearch/index/compositeindex/datacube/startree/aggregators/DocCountAggregator.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,70 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Aggregator to handle '_doc_count' field | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class DocCountAggregator implements ValueAggregator<Long> { | ||
|
||
private static final StarTreeNumericType VALUE_AGGREGATOR_TYPE = StarTreeNumericType.LONG; | ||
|
||
public DocCountAggregator() {} | ||
|
||
@Override | ||
public StarTreeNumericType getAggregatedValueType() { | ||
return VALUE_AGGREGATOR_TYPE; | ||
} | ||
|
||
/** | ||
* If _doc_count field for a doc is missing, we increment the _doc_count by '1' for the associated doc | ||
* otherwise take the actual value present in the field | ||
*/ | ||
@Override | ||
public Long getInitialAggregatedValueForSegmentDocValue(Long segmentDocValue) { | ||
if (segmentDocValue == null) { | ||
return getIdentityMetricValue(); | ||
} | ||
return segmentDocValue; | ||
} | ||
|
||
@Override | ||
public Long mergeAggregatedValueAndSegmentValue(Long value, Long segmentDocValue) { | ||
assert value != null; | ||
return mergeAggregatedValues(value, segmentDocValue); | ||
} | ||
|
||
@Override | ||
public Long mergeAggregatedValues(Long value, Long aggregatedValue) { | ||
if (value == null) { | ||
value = getIdentityMetricValue(); | ||
} | ||
if (aggregatedValue == null) { | ||
aggregatedValue = getIdentityMetricValue(); | ||
} | ||
return value + aggregatedValue; | ||
} | ||
|
||
@Override | ||
public Long toAggregatedValueType(Long rawValue) { | ||
return rawValue; | ||
} | ||
|
||
/** | ||
* If _doc_count field for a doc is missing, we increment the _doc_count by '1' for the associated doc | ||
*/ | ||
@Override | ||
public Long getIdentityMetricValue() { | ||
return 1L; | ||
} | ||
} |
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.