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 28, 2024
1 parent 11895f1 commit 7d5a389
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void build(Iterator<StarTreeDocument> starTreeDocumentIterator) throws IOExcepti
int numAggregatedStarTreeDocument = numStarTreeDocs - numStarTreeDocument - numStarTreeDocumentUnderStarNode;
logger.debug("Finished creating aggregated documents : {}", numAggregatedStarTreeDocument);

// TODO: When StarTree Codec is ready
// TODO: When StarTreeFactory Codec is ready
// Create doc values indices in disk
// Serialize and save in disk
// Write star tree metadata for off heap implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface StarTreeBuilder extends Closeable {
void build(Map<String, DocValuesProducer> fieldProducerMap) throws IOException;

/**
* Builds the star tree using StarTree values from multiple segments
* Builds the star tree using StarTreeFactory values from multiple segments
*
* @param starTreeValuesSubs contains the star tree values from multiple segments
* @throws IOException when we are unable to build star-tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public static void writeStarTreeMetadata(
long initialMetaFilePointer = metaOut.getFilePointer();

writeMetaHeader(metaOut);

// TODO: Replace the parameters with StarTreeMetadata class object
writeMeta(metaOut, metricAggregatorInfos, starTreeField, numNodes, segmentAggregatedCount, dataFilePointer, dataFileLength);

logger.debug(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.node;

import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.RandomAccessInput;
import org.opensearch.index.compositeindex.datacube.startree.fileformats.meta.StarTreeMetadata;
import org.opensearch.index.compositeindex.datacube.startree.fileformats.node.FixedLengthStarTreeNode;

import java.io.IOException;

/**
* A factory class for creating off-heap implementations of star-tree nodes.
*
* <p>This class provides a static factory method to create instances of {@link StarTreeNode}
* from an {@link IndexInput} and {@link StarTreeMetadata}. The implementation uses an
* off-heap data structure to store and access the star-tree data efficiently using random access.
*
* @opensearch.experimental
*/
public class StarTreeFactory {

Check warning on line 26 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/node/StarTreeFactory.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/node/StarTreeFactory.java#L26

Added line #L26 was not covered by tests

/**
* Creates a new instance of {@link StarTreeNode} from the provided {@link IndexInput} and
* {@link StarTreeMetadata}.
*
* @param data The {@link IndexInput} containing the star-tree data.
* @param starTreeMetadata The {@link StarTreeMetadata} containing metadata about the star-tree.
* @return A new instance of {@link StarTreeNode} representing the root of the star-tree.
* @throws IOException If an error occurs while reading the star-tree data.
*/
public static StarTreeNode createStarTree(IndexInput data, StarTreeMetadata starTreeMetadata) throws IOException {
RandomAccessInput in = data.randomAccessSlice(0, starTreeMetadata.getDataLength());
return new FixedLengthStarTreeNode(in, 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package org.opensearch.index.compositeindex.datacube.startree.node;

/**
* Represents the different types of nodes in a StarTree data structure.
* Represents the different types of nodes in a StarTreeFactory data structure.
*
* <p>
* In order to handle different node types, we use a byte value to represent the node type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opensearch.index.compositeindex.datacube.startree.fileformats.StarTreeWriter;
import org.opensearch.index.compositeindex.datacube.startree.fileformats.meta.StarTreeMetadata;
import org.opensearch.index.compositeindex.datacube.startree.node.InMemoryTreeNode;
import org.opensearch.index.compositeindex.datacube.startree.node.StarTree;
import org.opensearch.index.compositeindex.datacube.startree.node.StarTreeFactory;
import org.opensearch.index.compositeindex.datacube.startree.node.StarTreeNode;
import org.opensearch.index.compositeindex.datacube.startree.node.StarTreeNodeType;
import org.opensearch.test.OpenSearchTestCase;
Expand Down Expand Up @@ -64,9 +64,8 @@ public void test_StarTreeNode() throws IOException {
StarTreeMetadata starTreeMetadata = mock(StarTreeMetadata.class);
when(starTreeMetadata.getDataLength()).thenReturn(starTreeDataLength);
when(starTreeMetadata.getDataStartFilePointer()).thenReturn(0L);
StarTree starTree = new StarTree(dataIn, starTreeMetadata);

StarTreeNode starTreeNode = starTree.getRoot();
StarTreeNode starTreeNode = StarTreeFactory.createStarTree(dataIn, starTreeMetadata);
Queue<StarTreeNode> queue = new ArrayDeque<>();
queue.add(starTreeNode);

Expand Down Expand Up @@ -116,9 +115,8 @@ public void test_starTreeSearch() throws IOException {
StarTreeMetadata starTreeMetadata = mock(StarTreeMetadata.class);
when(starTreeMetadata.getDataLength()).thenReturn(starTreeDataLength);
when(starTreeMetadata.getDataStartFilePointer()).thenReturn(0L);
StarTree starTree = new StarTree(dataIn, starTreeMetadata);

StarTreeNode starTreeNode = starTree.getRoot();
StarTreeNode starTreeNode = StarTreeFactory.createStarTree(dataIn, starTreeMetadata);
InMemoryTreeNode inMemoryTreeNode = inMemoryTreeNodeMap.get(starTreeNode.getDimensionValue());
assertNotNull(inMemoryTreeNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opensearch.index.compositeindex.datacube.startree.fileformats.StarTreeWriter;
import org.opensearch.index.compositeindex.datacube.startree.fileformats.meta.StarTreeMetadata;
import org.opensearch.index.compositeindex.datacube.startree.node.InMemoryTreeNode;
import org.opensearch.index.compositeindex.datacube.startree.node.StarTree;
import org.opensearch.index.compositeindex.datacube.startree.node.StarTreeFactory;
import org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeUtils;
import org.opensearch.test.OpenSearchTestCase;
import org.junit.Before;
Expand Down Expand Up @@ -98,9 +98,8 @@ public void setup() throws IOException {
StarTreeMetadata starTreeMetadata = mock(StarTreeMetadata.class);
when(starTreeMetadata.getDataLength()).thenReturn(starTreeDataLength);
when(starTreeMetadata.getDataStartFilePointer()).thenReturn(0L);
StarTree starTree = new StarTree(dataIn, starTreeMetadata);

starTreeNode = (FixedLengthStarTreeNode) starTree.getRoot();
starTreeNode = (FixedLengthStarTreeNode) StarTreeFactory.createStarTree(dataIn, starTreeMetadata);

}

Expand Down

0 comments on commit 7d5a389

Please sign in to comment.