Skip to content

Commit 6b67535

Browse files
interfaces fixes for star tree search
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
1 parent 33be5a9 commit 6b67535

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
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 StarTreeMetadata getStarTreeMetadata() {
272+
return starTreeMetadata;
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: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import java.util.concurrent.atomic.AtomicInteger;
8383
import java.util.function.Supplier;
8484

85+
import static org.opensearch.index.compositeindex.datacube.startree.StarTreeTestUtils.assertStarTreeMetadata;
8586
import static org.opensearch.index.compositeindex.datacube.startree.StarTreeTestUtils.validateFileFormats;
8687
import static org.opensearch.index.compositeindex.datacube.startree.fileformats.StarTreeWriter.VERSION_CURRENT;
8788
import static org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeUtils.fullyQualifiedFieldNameForStarTreeDimensionsDocValues;
@@ -1894,6 +1895,7 @@ private void validateStarTreeFileFormats(
18941895
IndexInput metaIn = readState.directory.openInput(metaFileName, IOContext.DEFAULT);
18951896

18961897
StarTreeValues starTreeValues = new StarTreeValues(expectedStarTreeMetadata, dataIn, compositeDocValuesProducer, readState);
1898+
assertStarTreeMetadata(expectedStarTreeMetadata, starTreeValues.getStarTreeMetadata());
18971899
List<StarTreeNumericType> starTreeNumericTypes = new ArrayList<>();
18981900
builder.metricAggregatorInfos.forEach(
18991901
metricAggregatorInfo -> starTreeNumericTypes.add(metricAggregatorInfo.getValueAggregators().getAggregatedValueType())
@@ -2527,7 +2529,8 @@ private StarTreeValues getStarTreeValues(
25272529
null,
25282530
dimDocIdSetIterators,
25292531
metricDocIdSetIterators,
2530-
Map.of(CompositeIndexConstants.SEGMENT_DOCS_COUNT, number)
2532+
Map.of(CompositeIndexConstants.SEGMENT_DOCS_COUNT, number),
2533+
null
25312534
);
25322535
return starTreeValues;
25332536
}
@@ -3678,7 +3681,14 @@ private StarTreeValues getStarTreeValues(
36783681
);
36793682
// metricDocIdSetIterators.put("field2", () -> m1sndv);
36803683
// metricDocIdSetIterators.put("_doc_count", () -> m2sndv);
3681-
StarTreeValues starTreeValues = new StarTreeValues(sf, null, dimDocIdSetIterators, metricDocIdSetIterators, getAttributes(500));
3684+
StarTreeValues starTreeValues = new StarTreeValues(
3685+
sf,
3686+
null,
3687+
dimDocIdSetIterators,
3688+
metricDocIdSetIterators,
3689+
getAttributes(500),
3690+
null
3691+
);
36823692
return starTreeValues;
36833693
}
36843694

@@ -4095,7 +4105,8 @@ public void testMergeFlow() throws IOException {
40954105
null,
40964106
dimDocIdSetIterators,
40974107
metricDocIdSetIterators,
4098-
getAttributes(1000)
4108+
getAttributes(1000),
4109+
null
40994110
);
41004111

41014112
SortedNumericDocValues f2d1sndv = getSortedNumericMock(dimList1, docsWithField1);
@@ -4121,7 +4132,8 @@ public void testMergeFlow() throws IOException {
41214132
null,
41224133
f2dimDocIdSetIterators,
41234134
f2metricDocIdSetIterators,
4124-
getAttributes(1000)
4135+
getAttributes(1000),
4136+
null
41254137
);
41264138

41274139
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)