Skip to content

Commit 12f6493

Browse files
interfaces fixes for star tree search (#15603)
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
1 parent 4516065 commit 12f6493

File tree

6 files changed

+46
-19
lines changed

6 files changed

+46
-19
lines changed

server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetadata.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.logging.log4j.Logger;
1212
import org.apache.lucene.index.CorruptIndexException;
1313
import org.apache.lucene.store.IndexInput;
14+
import org.opensearch.common.annotation.ExperimentalApi;
1415
import org.opensearch.index.compositeindex.CompositeIndexMetadata;
1516
import org.opensearch.index.compositeindex.datacube.Metric;
1617
import org.opensearch.index.compositeindex.datacube.MetricStat;
@@ -30,6 +31,7 @@
3031
*
3132
* @opensearch.experimental
3233
*/
34+
@ExperimentalApi
3335
public class StarTreeMetadata extends CompositeIndexMetadata {
3436
private static final Logger logger = LogManager.getLogger(StarTreeMetadata.class);
3537

server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/node/FixedLengthStarTreeNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ public StarTreeNode getChildForDimensionValue(Long dimensionValue) throws IOExce
201201
StarTreeNode resultStarTreeNode = null;
202202
if (null != dimensionValue) {
203203
resultStarTreeNode = binarySearchChild(dimensionValue);
204-
assert null != resultStarTreeNode;
205204
}
206205
return resultStarTreeNode;
207206
}

server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/index/StarTreeValues.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.opensearch.index.compositeindex.datacube.startree.index;
1010

1111
import org.apache.lucene.codecs.DocValuesProducer;
12-
import org.apache.lucene.index.DocValues;
1312
import org.apache.lucene.index.FieldInfo;
1413
import org.apache.lucene.index.SegmentReadState;
1514
import org.apache.lucene.index.SortedNumericDocValues;
@@ -74,6 +73,11 @@ public class StarTreeValues implements CompositeIndexValues {
7473
*/
7574
private final Map<String, String> attributes;
7675

76+
/**
77+
* A metadata for the star-tree
78+
*/
79+
private final StarTreeMetadata starTreeMetadata;
80+
7781
/**
7882
* Constructs a new StarTreeValues object with the provided parameters.
7983
* Used for testing.
@@ -89,13 +93,15 @@ public StarTreeValues(
8993
StarTreeNode root,
9094
Map<String, Supplier<DocIdSetIterator>> dimensionDocValuesIteratorMap,
9195
Map<String, Supplier<DocIdSetIterator>> metricDocValuesIteratorMap,
92-
Map<String, String> attributes
96+
Map<String, String> attributes,
97+
StarTreeMetadata compositeIndexMetadata
9398
) {
9499
this.starTreeField = starTreeField;
95100
this.root = root;
96101
this.dimensionDocValuesIteratorMap = dimensionDocValuesIteratorMap;
97102
this.metricDocValuesIteratorMap = metricDocValuesIteratorMap;
98103
this.attributes = attributes;
104+
this.starTreeMetadata = compositeIndexMetadata;
99105
}
100106

101107
/**
@@ -114,7 +120,7 @@ public StarTreeValues(
114120
SegmentReadState readState
115121
) throws IOException {
116122

117-
StarTreeMetadata starTreeMetadata = (StarTreeMetadata) compositeIndexMetadata;
123+
starTreeMetadata = (StarTreeMetadata) compositeIndexMetadata;
118124

119125
// build skip star node dimensions
120126
Set<String> skipStarNodeCreationInDims = starTreeMetadata.getSkipStarNodeCreationInDims();
@@ -244,7 +250,7 @@ public DocIdSetIterator getDimensionDocIdSetIterator(String dimension) {
244250
return dimensionDocValuesIteratorMap.get(dimension).get();
245251
}
246252

247-
return DocValues.emptySortedNumeric();
253+
throw new IllegalArgumentException("dimension [" + dimension + "] does not exist in the segment.");
248254
}
249255

250256
/**
@@ -259,7 +265,10 @@ public DocIdSetIterator getMetricDocIdSetIterator(String fullyQualifiedMetricNam
259265
return metricDocValuesIteratorMap.get(fullyQualifiedMetricName).get();
260266
}
261267

262-
return DocValues.emptySortedNumeric();
268+
throw new IllegalArgumentException("metric [" + fullyQualifiedMetricName + "] does not exist in the segment.");
263269
}
264270

271+
public int getStarTreeDocumentCount() {
272+
return starTreeMetadata.getStarTreeDocCount();
273+
}
265274
}

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/StarTreeTestUtils.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.junit.Assert.assertFalse;
3838
import static org.junit.Assert.assertNotEquals;
3939
import static org.junit.Assert.assertNotNull;
40-
import static org.junit.Assert.assertThrows;
40+
import static org.junit.Assert.assertNull;
4141
import static org.junit.Assert.assertTrue;
4242

4343
public class StarTreeTestUtils {
@@ -208,11 +208,7 @@ public static void validateFileFormats(
208208
if (child.getStarTreeNodeType() != StarTreeNodeType.NULL.getValue()) {
209209
assertNotNull(starTreeNode.getChildForDimensionValue(child.getDimensionValue()));
210210
} else {
211-
StarTreeNode finalStarTreeNode = starTreeNode;
212-
assertThrows(
213-
AssertionError.class,
214-
() -> finalStarTreeNode.getChildForDimensionValue(child.getDimensionValue())
215-
);
211+
assertNull(starTreeNode.getChildForDimensionValue(child.getDimensionValue()));
216212
}
217213
assertStarTreeNode(child, resultChildNode);
218214
assertNotEquals(child.getStarTreeNodeType(), StarTreeNodeType.STAR.getValue());

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/builder/AbstractStarTreeBuilderTests.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@ private void validateStarTreeFileFormats(
18941894
IndexInput metaIn = readState.directory.openInput(metaFileName, IOContext.DEFAULT);
18951895

18961896
StarTreeValues starTreeValues = new StarTreeValues(expectedStarTreeMetadata, dataIn, compositeDocValuesProducer, readState);
1897+
assertEquals(expectedStarTreeMetadata.getStarTreeDocCount(), starTreeValues.getStarTreeDocumentCount());
18971898
List<StarTreeNumericType> starTreeNumericTypes = new ArrayList<>();
18981899
builder.metricAggregatorInfos.forEach(
18991900
metricAggregatorInfo -> starTreeNumericTypes.add(metricAggregatorInfo.getValueAggregators().getAggregatedValueType())
@@ -2527,7 +2528,8 @@ private StarTreeValues getStarTreeValues(
25272528
null,
25282529
dimDocIdSetIterators,
25292530
metricDocIdSetIterators,
2530-
Map.of(CompositeIndexConstants.SEGMENT_DOCS_COUNT, number)
2531+
Map.of(CompositeIndexConstants.SEGMENT_DOCS_COUNT, number),
2532+
null
25312533
);
25322534
return starTreeValues;
25332535
}
@@ -3678,7 +3680,14 @@ private StarTreeValues getStarTreeValues(
36783680
);
36793681
// metricDocIdSetIterators.put("field2", () -> m1sndv);
36803682
// metricDocIdSetIterators.put("_doc_count", () -> m2sndv);
3681-
StarTreeValues starTreeValues = new StarTreeValues(sf, null, dimDocIdSetIterators, metricDocIdSetIterators, getAttributes(500));
3683+
StarTreeValues starTreeValues = new StarTreeValues(
3684+
sf,
3685+
null,
3686+
dimDocIdSetIterators,
3687+
metricDocIdSetIterators,
3688+
getAttributes(500),
3689+
null
3690+
);
36823691
return starTreeValues;
36833692
}
36843693

@@ -4088,14 +4097,20 @@ public void testMergeFlow() throws IOException {
40884097
() -> d4sndv
40894098
);
40904099

4091-
Map<String, Supplier<DocIdSetIterator>> metricDocIdSetIterators = Map.of("field2", () -> m1sndv, "_doc_count", () -> m2sndv);
4100+
Map<String, Supplier<DocIdSetIterator>> metricDocIdSetIterators = Map.of(
4101+
"sf_field2_sum_metric",
4102+
() -> m1sndv,
4103+
"sf__doc_count_doc_count_metric",
4104+
() -> m2sndv
4105+
);
40924106

40934107
StarTreeValues starTreeValues = new StarTreeValues(
40944108
compositeField,
40954109
null,
40964110
dimDocIdSetIterators,
40974111
metricDocIdSetIterators,
4098-
getAttributes(1000)
4112+
getAttributes(1000),
4113+
null
40994114
);
41004115

41014116
SortedNumericDocValues f2d1sndv = getSortedNumericMock(dimList1, docsWithField1);
@@ -4115,13 +4130,19 @@ public void testMergeFlow() throws IOException {
41154130
() -> f2d4sndv
41164131
);
41174132

4118-
Map<String, Supplier<DocIdSetIterator>> f2metricDocIdSetIterators = Map.of("field2", () -> f2m1sndv, "_doc_count", () -> f2m2sndv);
4133+
Map<String, Supplier<DocIdSetIterator>> f2metricDocIdSetIterators = Map.of(
4134+
"sf_field2_sum_metric",
4135+
() -> f2m1sndv,
4136+
"sf__doc_count_doc_count_metric",
4137+
() -> f2m2sndv
4138+
);
41194139
StarTreeValues starTreeValues2 = new StarTreeValues(
41204140
compositeField,
41214141
null,
41224142
f2dimDocIdSetIterators,
41234143
f2metricDocIdSetIterators,
4124-
getAttributes(1000)
4144+
getAttributes(1000),
4145+
null
41254146
);
41264147

41274148
this.docValuesConsumer = LuceneDocValuesConsumerFactory.getDocValuesConsumerForCompositeCodec(

server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/node/FixedLengthStarTreeNodeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void testGetChildForNullNode() throws IOException {
191191

192192
public void testGetChildForInvalidDimensionValue() throws IOException {
193193
long invalidDimensionValue = Long.MAX_VALUE;
194-
assertThrows(AssertionError.class, () -> starTreeNode.getChildForDimensionValue(invalidDimensionValue));
194+
assertNull(starTreeNode.getChildForDimensionValue(invalidDimensionValue));
195195
}
196196

197197
public void testOnlyRootNodePresent() throws IOException {

0 commit comments

Comments
 (0)