Skip to content

Commit

Permalink
support for empty sequential doc values iterator
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Jul 5, 2024
1 parent 786162f commit 3e94f68
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public List<MetricAggregatorInfo> generateMetricAggregatorInfos(MapperService ma
for (Metric metric : this.starTreeField.getMetrics()) {
for (MetricStat metricType : metric.getMetrics()) {
IndexNumericFieldData.NumericType numericType;
SequentialDocValuesIterator metricStatReader = null;
SequentialDocValuesIterator metricStatReader;
Mapper fieldMapper = mapperService.documentMapper().mappers().getMapper(metric.getField());
if (fieldMapper instanceof NumberFieldMapper) {
numericType = ((NumberFieldMapper) fieldMapper).fieldType().numericType();
Expand All @@ -145,12 +145,14 @@ public List<MetricAggregatorInfo> generateMetricAggregatorInfos(MapperService ma
FieldInfo metricFieldInfos = state.fieldInfos.fieldInfo(metric.getField());
DocValuesType metricDocValuesType = metricFieldInfos.getDocValuesType();
if (metricType != MetricStat.COUNT) {
// Need not initialize the metric reader for COUNT metric type
// Need not initialize the metric reader with relevant doc id set iterator for COUNT metric type
metricStatReader = starTreeDocValuesIteratorAdapter.getDocValuesIterator(
metricDocValuesType,
metricFieldInfos,
fieldProducerMap.get(metricFieldInfos.name)
);
} else {
metricStatReader = new SequentialDocValuesIterator();
}

MetricAggregatorInfo metricAggregatorInfo = new MetricAggregatorInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/**
* Coordinates the reading of documents across multiple DocIdSetIterators.
* It encapsulates a single DocIdSetIterator and maintains the latest document ID and its associated value.
*
* @opensearch.experimental
*/
@ExperimentalApi
Expand Down Expand Up @@ -43,6 +44,34 @@ public SequentialDocValuesIterator(DocIdSetIterator docIdSetIterator) {
this.docIdSetIterator = docIdSetIterator;
}

/**
* Creates a SequentialDocValuesIterator with an empty DocIdSetIterator.
*
*/
public SequentialDocValuesIterator() {
this.docIdSetIterator = new DocIdSetIterator() {
@Override
public int docID() {
return NO_MORE_DOCS;
}

@Override
public int nextDoc() {
return NO_MORE_DOCS;
}

@Override
public int advance(int target) {
return NO_MORE_DOCS;
}

@Override
public long cost() {
return 0;
}
};
}

/**
* Returns the value associated with the latest document.
*
Expand Down

0 comments on commit 3e94f68

Please sign in to comment.