Skip to content

Commit

Permalink
addressing nits
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Aug 25, 2024
1 parent e82715c commit b154979
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ public static DocValuesConsumer getDocValuesConsumerForCompositeCodec(
String metaCodec,
String metaExtension
) throws IOException {
try (
Lucene90DocValuesConsumerWrapper lucene90DocValuesConsumerWrapper = new Lucene90DocValuesConsumerWrapper(
state,
dataCodec,
dataExtension,
metaCodec,
metaExtension
)
) {
return lucene90DocValuesConsumerWrapper.getLucene90DocValuesConsumer();
}
Lucene90DocValuesConsumerWrapper lucene90DocValuesConsumerWrapper = new Lucene90DocValuesConsumerWrapper(
state,
dataCodec,
dataExtension,
metaCodec,
metaExtension
);
return lucene90DocValuesConsumerWrapper.getLucene90DocValuesConsumer();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ public static DocValuesProducer getDocValuesProducerForCompositeCodec(

switch (compositeCodec) {
case Composite99Codec.COMPOSITE_INDEX_CODEC_NAME:
try (
Lucene90DocValuesProducerWrapper lucene90DocValuesProducerWrapper = new Lucene90DocValuesProducerWrapper(
state,
dataCodec,
dataExtension,
metaCodec,
metaExtension
)
) {
return lucene90DocValuesProducerWrapper.getLucene90DocValuesProducer();
}
Lucene90DocValuesProducerWrapper lucene90DocValuesProducerWrapper = new Lucene90DocValuesProducerWrapper(
state,
dataCodec,
dataExtension,
metaCodec,
metaExtension
);
return lucene90DocValuesProducerWrapper.getLucene90DocValuesProducer();
default:
throw new IllegalStateException("Invalid composite codec " + "[" + compositeCodec + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
@ExperimentalApi
public enum MetricStat {
VALUE_COUNT("value_count", 0),
AVG("avg", 1),
SUM("sum", 2),
MIN("min", 3),
MAX("max", 4),
AVG("avg", VALUE_COUNT, SUM);
SUM("sum", 1),
MIN("min", 2),
MAX("max", 3),
AVG("avg", 4, VALUE_COUNT, SUM);

private final String typeName;
private final MetricStat[] baseMetrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class StarTreeWriter {
/** Current version for the star tree writer */
public static final int VERSION_CURRENT = VERSION_START;

private StarTreeWriter() {}
public StarTreeWriter() {}

/**
* Write star tree to index output stream
Expand All @@ -42,7 +42,7 @@ private StarTreeWriter() {}
* @return total size of the three
* @throws IOException when star-tree data serialization fails
*/
public static long writeStarTree(IndexOutput dataOut, InMemoryTreeNode rootNode, int numNodes, String name) throws IOException {
public long writeStarTree(IndexOutput dataOut, InMemoryTreeNode rootNode, int numNodes, String name) throws IOException {
return StarTreeDataWriter.writeStarTree(dataOut, rootNode, numNodes, name);
}

Expand All @@ -57,7 +57,7 @@ public static long writeStarTree(IndexOutput dataOut, InMemoryTreeNode rootNode,
* @param dataFileLength data file length
* @throws IOException when star-tree data serialization fails
*/
public static void writeStarTreeMetadata(
public void writeStarTreeMetadata(
IndexOutput metaOut,
StarTreeField starTreeField,
List<MetricAggregatorInfo> metricAggregatorInfos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* - Support for star nodes, null nodes and other default nodes
* - Iteration over child nodes
* <p>
*
* The class uses specific byte offsets for each field in the serialized format,
* enabling direct access to node properties without parsing the entire node structure.
*
Expand Down Expand Up @@ -199,7 +198,9 @@ public StarTreeNode getChildForDimensionValue(long dimensionValue, boolean isSta
return handleStarNode();
}

return binarySearchChild(dimensionValue);
StarTreeNode resultStarTreeNode = binarySearchChild(dimensionValue);
assert null != resultStarTreeNode;
return resultStarTreeNode;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void test_StarTreeNode() throws IOException {
dataOut = directory.createOutput("star-tree-data", IOContext.DEFAULT);
Map<Long, InMemoryTreeNode> levelOrderStarTreeNodeMap = new LinkedHashMap<>();
InMemoryTreeNode root = generateSampleTree(levelOrderStarTreeNodeMap);
long starTreeDataLength = StarTreeWriter.writeStarTree(dataOut, root, 7, "star-tree");
StarTreeWriter starTreeWriter = new StarTreeWriter();
long starTreeDataLength = starTreeWriter.writeStarTree(dataOut, root, 7, "star-tree");

// asserting on the actual length of the star tree data file
assertEquals(starTreeDataLength, 247);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public void test_starTreeMetadata() throws IOException {
dataFilePointer = randomNonNegativeLong();
segmentDocumentCount = randomNonNegativeInt();
metaOut = directory.createOutput("star-tree-metadata", IOContext.DEFAULT);
StarTreeWriter.writeStarTreeMetadata(
StarTreeWriter starTreeWriter = new StarTreeWriter();
starTreeWriter.writeStarTreeMetadata(
metaOut,
starTreeField,
metricAggregatorInfos,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.index.compositeindex.datacube.startree.utils;

import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.index.VectorSimilarityFunction;
import org.opensearch.test.OpenSearchTestCase;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

public class StarTreeUtilsTest extends OpenSearchTestCase {

public void testFullyQualifiedFieldNameForStarTreeDimensionsDocValues() {
String starTreeFieldName = "myStarTreeField";
String dimensionName = "dimension1";
String expectedFieldName = "myStarTreeField_dimension1_dim";

String actualFieldName = StarTreeUtils.fullyQualifiedFieldNameForStarTreeDimensionsDocValues(starTreeFieldName, dimensionName);
assertEquals(expectedFieldName, actualFieldName);
}

public void testFullyQualifiedFieldNameForStarTreeMetricsDocValues() {
String starTreeFieldName = "myStarTreeField";
String fieldName = "myField";
String metricName = "metric1";
String expectedFieldName = "myStarTreeField_myField_metric1_metric";

String actualFieldName = StarTreeUtils.fullyQualifiedFieldNameForStarTreeMetricsDocValues(starTreeFieldName, fieldName, metricName);
assertEquals(expectedFieldName, actualFieldName);
}

public void testGetFieldInfoList() {
List<String> fieldNames = Arrays.asList("field1", "field2", "field3");
FieldInfo[] actualFieldInfos = StarTreeUtils.getFieldInfoList(fieldNames);
for (int i = 0; i < fieldNames.size(); i++) {
assertFieldInfos(actualFieldInfos[i], fieldNames.get(i), i);
}
}

public void testGetFieldInfo() {
String fieldName = UUID.randomUUID().toString();
int fieldNumber = randomInt();
assertFieldInfos(StarTreeUtils.getFieldInfo(fieldName, fieldNumber), fieldName, fieldNumber);

}

private void assertFieldInfos(FieldInfo actualFieldInfo, String fieldName, Integer fieldNumber){
assertEquals(fieldName, actualFieldInfo.name);
assertEquals(fieldNumber, actualFieldInfo.number, 0);
assertFalse(actualFieldInfo.hasVectorValues());
assertTrue(actualFieldInfo.hasNorms());
assertFalse(actualFieldInfo.hasVectors());
assertEquals(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, actualFieldInfo.getIndexOptions());
assertEquals(DocValuesType.SORTED_NUMERIC, actualFieldInfo.getDocValuesType());
assertEquals(-1, actualFieldInfo.getDocValuesGen());
assertEquals(Collections.emptyMap(), actualFieldInfo.attributes());
assertEquals(0, actualFieldInfo.getPointDimensionCount());
assertEquals(0, actualFieldInfo.getPointIndexDimensionCount());
assertEquals(0, actualFieldInfo.getPointNumBytes());
assertEquals(0, actualFieldInfo.getVectorDimension());
assertEquals(VectorEncoding.FLOAT32, actualFieldInfo.getVectorEncoding());
assertEquals(VectorSimilarityFunction.EUCLIDEAN, actualFieldInfo.getVectorSimilarityFunction());
assertFalse(actualFieldInfo.isSoftDeletesField());
}


}

0 comments on commit b154979

Please sign in to comment.