|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.apache.lucene.codecs.lucene90; |
| 10 | + |
| 11 | +import org.apache.lucene.codecs.DocValuesProducer; |
| 12 | +import org.apache.lucene.index.BinaryDocValues; |
| 13 | +import org.apache.lucene.index.DocValuesType; |
| 14 | +import org.apache.lucene.index.FieldInfo; |
| 15 | +import org.apache.lucene.index.FieldInfos; |
| 16 | +import org.apache.lucene.index.IndexOptions; |
| 17 | +import org.apache.lucene.index.NumericDocValues; |
| 18 | +import org.apache.lucene.index.SegmentReadState; |
| 19 | +import org.apache.lucene.index.SortedDocValues; |
| 20 | +import org.apache.lucene.index.SortedNumericDocValues; |
| 21 | +import org.apache.lucene.index.SortedSetDocValues; |
| 22 | +import org.apache.lucene.index.VectorEncoding; |
| 23 | +import org.apache.lucene.index.VectorSimilarityFunction; |
| 24 | +import org.opensearch.index.compositeindex.datacube.startree.aggregators.MetricEntry; |
| 25 | + |
| 26 | +import java.io.IOException; |
| 27 | +import java.util.Collections; |
| 28 | +import java.util.List; |
| 29 | + |
| 30 | +import static org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeHelper.fullFieldNameForStarTreeDimensionsDocValues; |
| 31 | +import static org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeHelper.fullFieldNameForStarTreeMetricsDocValues; |
| 32 | + |
| 33 | +/** |
| 34 | + * This class is a custom abstraction of the {@link DocValuesProducer} for the Star Tree index structure. |
| 35 | + * It is responsible for providing access to various types of document values (numeric, binary, sorted, sorted numeric, |
| 36 | + * and sorted set) for fields in the Star Tree index. |
| 37 | + * |
| 38 | + * @opensearch.experimental |
| 39 | + */ |
| 40 | +public class StarTree99DocValuesProducer extends DocValuesProducer { |
| 41 | + |
| 42 | + Lucene90DocValuesProducer lucene90DocValuesProducer; |
| 43 | + private final List<FieldInfo> dimensions; |
| 44 | + private final List<MetricEntry> metrics; |
| 45 | + private final FieldInfos fieldInfos; |
| 46 | + |
| 47 | + public StarTree99DocValuesProducer( |
| 48 | + SegmentReadState state, |
| 49 | + String dataCodec, |
| 50 | + String dataExtension, |
| 51 | + String metaCodec, |
| 52 | + String metaExtension, |
| 53 | + List<FieldInfo> dimensions, |
| 54 | + List<MetricEntry> metricEntries, |
| 55 | + String compositeFieldName |
| 56 | + ) throws IOException { |
| 57 | + this.dimensions = dimensions; |
| 58 | + this.metrics = metricEntries; |
| 59 | + |
| 60 | + // populates the dummy list of field infos to fetch doc id set iterators for respective fields. |
| 61 | + this.fieldInfos = new FieldInfos(getFieldInfoList(compositeFieldName)); |
| 62 | + SegmentReadState segmentReadState = new SegmentReadState(state.directory, state.segmentInfo, fieldInfos, state.context); |
| 63 | + lucene90DocValuesProducer = new Lucene90DocValuesProducer(segmentReadState, dataCodec, dataExtension, metaCodec, metaExtension); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public NumericDocValues getNumeric(FieldInfo field) throws IOException { |
| 68 | + return this.lucene90DocValuesProducer.getNumeric(field); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public BinaryDocValues getBinary(FieldInfo field) throws IOException { |
| 73 | + return this.lucene90DocValuesProducer.getBinary(field); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public SortedDocValues getSorted(FieldInfo field) throws IOException { |
| 78 | + return this.lucene90DocValuesProducer.getSorted(field); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException { |
| 83 | + return this.lucene90DocValuesProducer.getSortedNumeric(field); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException { |
| 88 | + return this.lucene90DocValuesProducer.getSortedSet(field); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void checkIntegrity() throws IOException { |
| 93 | + this.lucene90DocValuesProducer.checkIntegrity(); |
| 94 | + } |
| 95 | + |
| 96 | + // returns the doc id set iterator based on field name |
| 97 | + public SortedNumericDocValues getSortedNumeric(String fieldName) throws IOException { |
| 98 | + return this.lucene90DocValuesProducer.getSortedNumeric(fieldInfos.fieldInfo(fieldName)); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public void close() throws IOException { |
| 103 | + this.lucene90DocValuesProducer.close(); |
| 104 | + } |
| 105 | + |
| 106 | + private FieldInfo[] getFieldInfoList(String compositeFieldName) { |
| 107 | + FieldInfo[] fieldInfoList = new FieldInfo[this.dimensions.size() + metrics.size()]; |
| 108 | + // field number is not really used. We depend on unique field names to get the desired iterator |
| 109 | + int fieldNumber = 0; |
| 110 | + |
| 111 | + for (FieldInfo dimension : this.dimensions) { |
| 112 | + fieldInfoList[fieldNumber] = new FieldInfo( |
| 113 | + fullFieldNameForStarTreeDimensionsDocValues(compositeFieldName, dimension.getName()), |
| 114 | + fieldNumber, |
| 115 | + false, |
| 116 | + false, |
| 117 | + true, |
| 118 | + IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, |
| 119 | + DocValuesType.SORTED_NUMERIC, |
| 120 | + -1, |
| 121 | + Collections.emptyMap(), |
| 122 | + 0, |
| 123 | + 0, |
| 124 | + 0, |
| 125 | + 0, |
| 126 | + VectorEncoding.FLOAT32, |
| 127 | + VectorSimilarityFunction.EUCLIDEAN, |
| 128 | + false, |
| 129 | + false |
| 130 | + ); |
| 131 | + fieldNumber++; |
| 132 | + } |
| 133 | + for (MetricEntry metric : metrics) { |
| 134 | + fieldInfoList[fieldNumber] = new FieldInfo( |
| 135 | + fullFieldNameForStarTreeMetricsDocValues(compositeFieldName, metric.getMetricName(), metric.getMetricStat().getTypeName()), |
| 136 | + fieldNumber, |
| 137 | + false, |
| 138 | + false, |
| 139 | + true, |
| 140 | + IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, |
| 141 | + DocValuesType.SORTED_NUMERIC, |
| 142 | + -1, |
| 143 | + Collections.emptyMap(), |
| 144 | + 0, |
| 145 | + 0, |
| 146 | + 0, |
| 147 | + 0, |
| 148 | + VectorEncoding.FLOAT32, |
| 149 | + VectorSimilarityFunction.EUCLIDEAN, |
| 150 | + false, |
| 151 | + false |
| 152 | + ); |
| 153 | + fieldNumber++; |
| 154 | + } |
| 155 | + return fieldInfoList; |
| 156 | + } |
| 157 | + |
| 158 | +} |
0 commit comments