Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Star Tree] Interfaces Fixes for Star Tree Search #15603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.store.IndexInput;
import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.index.compositeindex.CompositeIndexMetadata;
import org.opensearch.index.compositeindex.datacube.Metric;
import org.opensearch.index.compositeindex.datacube.MetricStat;
Expand All @@ -30,6 +31,7 @@
*
* @opensearch.experimental
*/
@ExperimentalApi
public class StarTreeMetadata extends CompositeIndexMetadata {
private static final Logger logger = LogManager.getLogger(StarTreeMetadata.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public StarTreeNode getChildForDimensionValue(Long dimensionValue) throws IOExce
StarTreeNode resultStarTreeNode = null;
if (null != dimensionValue) {
resultStarTreeNode = binarySearchChild(dimensionValue);
assert null != resultStarTreeNode;
}
return resultStarTreeNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.index.compositeindex.datacube.startree.index;

import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SortedNumericDocValues;
Expand Down Expand Up @@ -74,6 +73,11 @@
*/
private final Map<String, String> attributes;

/**
* A metadata for the star-tree
*/
private final StarTreeMetadata starTreeMetadata;

/**
* Constructs a new StarTreeValues object with the provided parameters.
* Used for testing.
Expand All @@ -89,13 +93,15 @@
StarTreeNode root,
Map<String, Supplier<DocIdSetIterator>> dimensionDocValuesIteratorMap,
Map<String, Supplier<DocIdSetIterator>> metricDocValuesIteratorMap,
Map<String, String> attributes
Map<String, String> attributes,
StarTreeMetadata compositeIndexMetadata
) {
this.starTreeField = starTreeField;
this.root = root;
this.dimensionDocValuesIteratorMap = dimensionDocValuesIteratorMap;
this.metricDocValuesIteratorMap = metricDocValuesIteratorMap;
this.attributes = attributes;
this.starTreeMetadata = compositeIndexMetadata;
}

/**
Expand All @@ -114,7 +120,7 @@
SegmentReadState readState
) throws IOException {

StarTreeMetadata starTreeMetadata = (StarTreeMetadata) compositeIndexMetadata;
starTreeMetadata = (StarTreeMetadata) compositeIndexMetadata;

// build skip star node dimensions
Set<String> skipStarNodeCreationInDims = starTreeMetadata.getSkipStarNodeCreationInDims();
Expand Down Expand Up @@ -244,7 +250,7 @@
return dimensionDocValuesIteratorMap.get(dimension).get();
}

return DocValues.emptySortedNumeric();
throw new IllegalArgumentException("dimension [" + dimension + "] does not exist in the segment.");

Check warning on line 253 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/index/StarTreeValues.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L253 was not covered by tests
}

/**
Expand All @@ -259,7 +265,10 @@
return metricDocValuesIteratorMap.get(fullyQualifiedMetricName).get();
}

return DocValues.emptySortedNumeric();
throw new IllegalArgumentException("metric [" + fullyQualifiedMetricName + "] does not exist in the segment.");

Check warning on line 268 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/index/StarTreeValues.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L268 was not covered by tests
}

public int getStarTreeDocumentCount() {
return starTreeMetadata.getStarTreeDocCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class StarTreeTestUtils {
Expand Down Expand Up @@ -208,11 +208,7 @@ public static void validateFileFormats(
if (child.getStarTreeNodeType() != StarTreeNodeType.NULL.getValue()) {
assertNotNull(starTreeNode.getChildForDimensionValue(child.getDimensionValue()));
} else {
StarTreeNode finalStarTreeNode = starTreeNode;
assertThrows(
AssertionError.class,
() -> finalStarTreeNode.getChildForDimensionValue(child.getDimensionValue())
);
assertNull(starTreeNode.getChildForDimensionValue(child.getDimensionValue()));
}
assertStarTreeNode(child, resultChildNode);
assertNotEquals(child.getStarTreeNodeType(), StarTreeNodeType.STAR.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,7 @@ private void validateStarTreeFileFormats(
IndexInput metaIn = readState.directory.openInput(metaFileName, IOContext.DEFAULT);

StarTreeValues starTreeValues = new StarTreeValues(expectedStarTreeMetadata, dataIn, compositeDocValuesProducer, readState);
assertEquals(expectedStarTreeMetadata.getStarTreeDocCount(), starTreeValues.getStarTreeDocumentCount());
List<StarTreeNumericType> starTreeNumericTypes = new ArrayList<>();
builder.metricAggregatorInfos.forEach(
metricAggregatorInfo -> starTreeNumericTypes.add(metricAggregatorInfo.getValueAggregators().getAggregatedValueType())
Expand Down Expand Up @@ -2527,7 +2528,8 @@ private StarTreeValues getStarTreeValues(
null,
dimDocIdSetIterators,
metricDocIdSetIterators,
Map.of(CompositeIndexConstants.SEGMENT_DOCS_COUNT, number)
Map.of(CompositeIndexConstants.SEGMENT_DOCS_COUNT, number),
null
);
return starTreeValues;
}
Expand Down Expand Up @@ -3678,7 +3680,14 @@ private StarTreeValues getStarTreeValues(
);
// metricDocIdSetIterators.put("field2", () -> m1sndv);
// metricDocIdSetIterators.put("_doc_count", () -> m2sndv);
StarTreeValues starTreeValues = new StarTreeValues(sf, null, dimDocIdSetIterators, metricDocIdSetIterators, getAttributes(500));
StarTreeValues starTreeValues = new StarTreeValues(
sf,
null,
dimDocIdSetIterators,
metricDocIdSetIterators,
getAttributes(500),
null
);
return starTreeValues;
}

Expand Down Expand Up @@ -4088,14 +4097,20 @@ public void testMergeFlow() throws IOException {
() -> d4sndv
);

Map<String, Supplier<DocIdSetIterator>> metricDocIdSetIterators = Map.of("field2", () -> m1sndv, "_doc_count", () -> m2sndv);
Map<String, Supplier<DocIdSetIterator>> metricDocIdSetIterators = Map.of(
"sf_field2_sum_metric",
() -> m1sndv,
"sf__doc_count_doc_count_metric",
() -> m2sndv
);

StarTreeValues starTreeValues = new StarTreeValues(
compositeField,
null,
dimDocIdSetIterators,
metricDocIdSetIterators,
getAttributes(1000)
getAttributes(1000),
null
);

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

Map<String, Supplier<DocIdSetIterator>> f2metricDocIdSetIterators = Map.of("field2", () -> f2m1sndv, "_doc_count", () -> f2m2sndv);
Map<String, Supplier<DocIdSetIterator>> f2metricDocIdSetIterators = Map.of(
"sf_field2_sum_metric",
() -> f2m1sndv,
"sf__doc_count_doc_count_metric",
() -> f2m2sndv
);
StarTreeValues starTreeValues2 = new StarTreeValues(
compositeField,
null,
f2dimDocIdSetIterators,
f2metricDocIdSetIterators,
getAttributes(1000)
getAttributes(1000),
null
);

this.docValuesConsumer = LuceneDocValuesConsumerFactory.getDocValuesConsumerForCompositeCodec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void testGetChildForNullNode() throws IOException {

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

public void testOnlyRootNodePresent() throws IOException {
Expand Down
Loading