diff --git a/server/src/main/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesConsumerWrapper.java b/server/src/main/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesConsumerWrapper.java new file mode 100644 index 0000000000000..67ee45f4c9306 --- /dev/null +++ b/server/src/main/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesConsumerWrapper.java @@ -0,0 +1,46 @@ +/* + * 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.apache.lucene.codecs.lucene90; + +import org.apache.lucene.codecs.DocValuesConsumer; +import org.apache.lucene.index.SegmentWriteState; + +import java.io.Closeable; +import java.io.IOException; + +/** + * This class is an abstraction of the {@link DocValuesConsumer} for the Star Tree index structure. + * It is responsible to consume various types of document values (numeric, binary, sorted, sorted numeric, + * and sorted set) for fields in the Star Tree index. + * + * @opensearch.experimental + */ +public class Lucene90DocValuesConsumerWrapper implements Closeable { + + private final Lucene90DocValuesConsumer lucene90DocValuesConsumer; + + public Lucene90DocValuesConsumerWrapper( + SegmentWriteState state, + String dataCodec, + String dataExtension, + String metaCodec, + String metaExtension + ) throws IOException { + lucene90DocValuesConsumer = new Lucene90DocValuesConsumer(state, dataCodec, dataExtension, metaCodec, metaExtension); + } + + public Lucene90DocValuesConsumer getLucene90DocValuesConsumer() { + return lucene90DocValuesConsumer; + } + + @Override + public void close() throws IOException { + lucene90DocValuesConsumer.close(); + } +} diff --git a/server/src/main/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesProducerWrapper.java b/server/src/main/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesProducerWrapper.java new file mode 100644 index 0000000000000..a213852c59094 --- /dev/null +++ b/server/src/main/java/org/apache/lucene/codecs/lucene90/Lucene90DocValuesProducerWrapper.java @@ -0,0 +1,46 @@ +/* + * 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.apache.lucene.codecs.lucene90; + +import org.apache.lucene.codecs.DocValuesProducer; +import org.apache.lucene.index.SegmentReadState; + +import java.io.Closeable; +import java.io.IOException; + +/** + * This class is a custom abstraction of the {@link DocValuesProducer} for the Star Tree index structure. + * It is responsible for providing access to various types of document values (numeric, binary, sorted, sorted numeric, + * and sorted set) for fields in the Star Tree index. + * + * @opensearch.experimental + */ +public class Lucene90DocValuesProducerWrapper implements Closeable { + + private final Lucene90DocValuesProducer lucene90DocValuesProducer; + + public Lucene90DocValuesProducerWrapper( + SegmentReadState state, + String dataCodec, + String dataExtension, + String metaCodec, + String metaExtension + ) throws IOException { + lucene90DocValuesProducer = new Lucene90DocValuesProducer(state, dataCodec, dataExtension, metaCodec, metaExtension); + } + + public DocValuesProducer getLucene90DocValuesProducer() { + return lucene90DocValuesProducer; + } + + @Override + public void close() throws IOException { + lucene90DocValuesProducer.close(); + } +} diff --git a/server/src/main/java/org/apache/lucene/index/SortedNumericDocValuesWriterWrapper.java b/server/src/main/java/org/apache/lucene/index/SortedNumericDocValuesWriterWrapper.java new file mode 100644 index 0000000000000..f7759fcced284 --- /dev/null +++ b/server/src/main/java/org/apache/lucene/index/SortedNumericDocValuesWriterWrapper.java @@ -0,0 +1,53 @@ +/* + * 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.apache.lucene.index; + +import org.apache.lucene.util.Counter; + +/** + * A wrapper class for writing sorted numeric doc values. + *
+ * This class provides a convenient way to add sorted numeric doc values to a field
+ * and retrieve the corresponding {@link SortedNumericDocValues} instance.
+ *
+ * @opensearch.experimental
+ */
+public class SortedNumericDocValuesWriterWrapper {
+
+ private final SortedNumericDocValuesWriter sortedNumericDocValuesWriter;
+
+ /**
+ * Sole constructor. Constructs a new {@link SortedNumericDocValuesWriterWrapper} instance.
+ *
+ * @param fieldInfo the field information for the field being written
+ * @param counter a counter for tracking memory usage
+ */
+ public SortedNumericDocValuesWriterWrapper(FieldInfo fieldInfo, Counter counter) {
+ sortedNumericDocValuesWriter = new SortedNumericDocValuesWriter(fieldInfo, counter);
+ }
+
+ /**
+ * Adds a value to the sorted numeric doc values for the specified document.
+ *
+ * @param docID the document ID
+ * @param value the value to add
+ */
+ public void addValue(int docID, long value) {
+ sortedNumericDocValuesWriter.addValue(docID, value);
+ }
+
+ /**
+ * Returns the {@link SortedNumericDocValues} instance containing the sorted numeric doc values
+ *
+ * @return the {@link SortedNumericDocValues} instance
+ */
+ public SortedNumericDocValues getDocValues() {
+ return sortedNumericDocValuesWriter.getDocValues();
+ }
+}
diff --git a/server/src/main/java/org/opensearch/index/codec/composite/CompositeCodecFactory.java b/server/src/main/java/org/opensearch/index/codec/composite/CompositeCodecFactory.java
index 3acedc6a27d7f..99691d7061ac9 100644
--- a/server/src/main/java/org/opensearch/index/codec/composite/CompositeCodecFactory.java
+++ b/server/src/main/java/org/opensearch/index/codec/composite/CompositeCodecFactory.java
@@ -12,6 +12,7 @@
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.lucene99.Lucene99Codec;
import org.opensearch.common.annotation.ExperimentalApi;
+import org.opensearch.index.codec.composite.composite99.Composite99Codec;
import org.opensearch.index.mapper.MapperService;
import java.util.HashMap;
@@ -29,6 +30,10 @@
*/
@ExperimentalApi
public class CompositeCodecFactory {
+
+ // we can use this to track the latest composite codec
+ public static final String COMPOSITE_CODEC = Composite99Codec.COMPOSITE_INDEX_CODEC_NAME;
+
public CompositeCodecFactory() {}
public Map
+ * The segments are written using the latest composite codec. The codec
+ * internally manages calling the appropriate consumer factory for its abstractions.
+ *
+ * This design ensures forward compatibility for writing operations
+ *
+ * @opensearch.experimental
+ */
+public class LuceneDocValuesConsumerFactory {
+
+ public static DocValuesConsumer getDocValuesConsumerForCompositeCodec(
+ SegmentWriteState state,
+ String dataCodec,
+ String dataExtension,
+ String metaCodec,
+ String metaExtension
+ ) throws IOException {
+ try (
+ Lucene90DocValuesConsumerWrapper lucene90DocValuesConsumerWrapper = new Lucene90DocValuesConsumerWrapper(
+ state,
+ dataCodec,
+ dataExtension,
+ metaCodec,
+ metaExtension
+ )
+ ) {
+ return lucene90DocValuesConsumerWrapper.getLucene90DocValuesConsumer();
+ }
+ }
+
+}
diff --git a/server/src/main/java/org/opensearch/index/codec/composite/LuceneDocValuesProducerFactory.java b/server/src/main/java/org/opensearch/index/codec/composite/LuceneDocValuesProducerFactory.java
new file mode 100644
index 0000000000000..611a97ffeb834
--- /dev/null
+++ b/server/src/main/java/org/opensearch/index/codec/composite/LuceneDocValuesProducerFactory.java
@@ -0,0 +1,60 @@
+/*
+ * 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.codec.composite;
+
+import org.apache.lucene.codecs.DocValuesProducer;
+import org.apache.lucene.codecs.lucene90.Lucene90DocValuesProducerWrapper;
+import org.apache.lucene.index.SegmentReadState;
+import org.opensearch.index.codec.composite.composite99.Composite99Codec;
+
+import java.io.IOException;
+
+/**
+ * A factory class that provides a factory method for creating {@link DocValuesProducer} instances
+ * based on the specified composite codec.
+ *
+ * In producers, we want to ensure compatibility with older codec versions during the segment reads.
+ * This approach allows for writing with only the latest codec while maintaining
+ * the ability to read data encoded with any codec version present in the segment.
+ *
+ * This design ensures backward compatibility for reads across different codec versions.
+ *
+ * @opensearch.experimental
+ */
+public class LuceneDocValuesProducerFactory {
+
+ public static DocValuesProducer getDocValuesProducerForCompositeCodec(
+ String compositeCodec,
+ SegmentReadState state,
+ String dataCodec,
+ String dataExtension,
+ String metaCodec,
+ String metaExtension
+ ) throws IOException {
+
+ switch (compositeCodec) {
+ case Composite99Codec.COMPOSITE_INDEX_CODEC_NAME:
+ try (
+ Lucene90DocValuesProducerWrapper lucene90DocValuesProducerWrapper = new Lucene90DocValuesProducerWrapper(
+ state,
+ dataCodec,
+ dataExtension,
+ metaCodec,
+ metaExtension
+ )
+ ) {
+ return lucene90DocValuesProducerWrapper.getLucene90DocValuesProducer();
+ }
+ default:
+ throw new IllegalStateException("Invalid composite codec " + "[" + compositeCodec + "]");
+ }
+
+ }
+
+}
diff --git a/server/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99Codec.java
similarity index 97%
rename from server/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java
rename to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99Codec.java
index de04944e67cd2..8422932e937c2 100644
--- a/server/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java
+++ b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99Codec.java
@@ -6,7 +6,7 @@
* compatible open source license.
*/
-package org.opensearch.index.codec.composite;
+package org.opensearch.index.codec.composite.composite99;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.codecs.Codec;
diff --git a/server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesFormat.java b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesFormat.java
similarity index 97%
rename from server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesFormat.java
rename to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesFormat.java
index 216ed4f68f333..e8c69b11b7c88 100644
--- a/server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesFormat.java
+++ b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesFormat.java
@@ -6,7 +6,7 @@
* compatible open source license.
*/
-package org.opensearch.index.codec.composite;
+package org.opensearch.index.codec.composite.composite99;
import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.DocValuesFormat;
diff --git a/server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesReader.java b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesReader.java
similarity index 91%
rename from server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesReader.java
rename to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesReader.java
index df5008a7f294e..e3bfe01cfa2d5 100644
--- a/server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesReader.java
+++ b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesReader.java
@@ -6,7 +6,7 @@
* compatible open source license.
*/
-package org.opensearch.index.codec.composite;
+package org.opensearch.index.codec.composite.composite99;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BinaryDocValues;
@@ -17,6 +17,9 @@
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.opensearch.common.annotation.ExperimentalApi;
+import org.opensearch.index.codec.composite.CompositeIndexFieldInfo;
+import org.opensearch.index.codec.composite.CompositeIndexReader;
+import org.opensearch.index.codec.composite.CompositeIndexValues;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesWriter.java b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesWriter.java
similarity index 97%
rename from server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesWriter.java
rename to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesWriter.java
index 6ed1a8c42e380..da784e1232800 100644
--- a/server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesWriter.java
+++ b/server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesWriter.java
@@ -6,7 +6,7 @@
* compatible open source license.
*/
-package org.opensearch.index.codec.composite;
+package org.opensearch.index.codec.composite.composite99;
import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.DocValuesProducer;
@@ -18,6 +18,9 @@
import org.apache.lucene.index.SegmentWriteState;
import org.apache.lucene.index.SortedNumericDocValues;
import org.opensearch.common.annotation.ExperimentalApi;
+import org.opensearch.index.codec.composite.CompositeIndexFieldInfo;
+import org.opensearch.index.codec.composite.CompositeIndexReader;
+import org.opensearch.index.codec.composite.CompositeIndexValues;
import org.opensearch.index.codec.composite.datacube.startree.StarTreeValues;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeField;
import org.opensearch.index.compositeindex.datacube.startree.builder.StarTreesBuilder;
diff --git a/server/src/main/java/org/opensearch/index/codec/composite/composite99/package-info.java b/server/src/main/java/org/opensearch/index/codec/composite/composite99/package-info.java
new file mode 100644
index 0000000000000..3d6f130b9a7c8
--- /dev/null
+++ b/server/src/main/java/org/opensearch/index/codec/composite/composite99/package-info.java
@@ -0,0 +1,12 @@
+/*
+ * 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.
+ */
+
+/**
+ * Responsible for handling all composite index codecs and operations associated with Composite99 codec
+ */
+package org.opensearch.index.codec.composite.composite99;
diff --git a/server/src/main/resources/META-INF/services/org.apache.lucene.codecs.Codec b/server/src/main/resources/META-INF/services/org.apache.lucene.codecs.Codec
index e030a813373c1..f51452c57f975 100644
--- a/server/src/main/resources/META-INF/services/org.apache.lucene.codecs.Codec
+++ b/server/src/main/resources/META-INF/services/org.apache.lucene.codecs.Codec
@@ -1 +1 @@
-org.opensearch.index.codec.composite.Composite99Codec
+org.opensearch.index.codec.composite.composite99.Composite99Codec
diff --git a/server/src/test/java/org/opensearch/index/codec/CodecTests.java b/server/src/test/java/org/opensearch/index/codec/CodecTests.java
index f19a95bae3832..353b6920f5568 100644
--- a/server/src/test/java/org/opensearch/index/codec/CodecTests.java
+++ b/server/src/test/java/org/opensearch/index/codec/CodecTests.java
@@ -48,7 +48,7 @@
import org.opensearch.env.Environment;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.analysis.IndexAnalyzers;
-import org.opensearch.index.codec.composite.Composite99Codec;
+import org.opensearch.index.codec.composite.composite99.Composite99Codec;
import org.opensearch.index.engine.EngineConfig;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.similarity.SimilarityService;
diff --git a/server/src/test/java/org/opensearch/index/codec/composite/LuceneDocValuesConsumerFactoryTests.java b/server/src/test/java/org/opensearch/index/codec/composite/LuceneDocValuesConsumerFactoryTests.java
new file mode 100644
index 0000000000000..7fb8fe7f68f45
--- /dev/null
+++ b/server/src/test/java/org/opensearch/index/codec/composite/LuceneDocValuesConsumerFactoryTests.java
@@ -0,0 +1,85 @@
+/*
+ * 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.codec.composite;
+
+import org.apache.lucene.codecs.DocValuesConsumer;
+import org.apache.lucene.codecs.lucene99.Lucene99Codec;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.SegmentInfo;
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.InfoStream;
+import org.apache.lucene.util.Version;
+import org.opensearch.index.codec.composite.composite99.Composite99Codec;
+import org.opensearch.test.OpenSearchTestCase;
+import org.junit.After;
+import org.junit.Before;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.UUID;
+
+public class LuceneDocValuesConsumerFactoryTests extends OpenSearchTestCase {
+
+ private Directory directory;
+ private final String dataCodec = "data_codec";
+ private final String dataExtension = "data_extension";
+ private final String metaCodec = "meta_codec";
+ private final String metaExtension = "meta_extension";
+
+ @Before
+ public void setup() {
+ directory = newDirectory();
+ }
+
+ public void testGetDocValuesConsumerForCompositeCodec() throws IOException {
+ SegmentInfo segmentInfo = new SegmentInfo(
+ directory,
+ Version.LATEST,
+ Version.LUCENE_9_11_0,
+ "test_segment",
+ randomInt(),
+ false,
+ false,
+ new Lucene99Codec(),
+ new HashMap<>(),
+ UUID.randomUUID().toString().substring(0, 16).getBytes(StandardCharsets.UTF_8),
+ new HashMap<>(),
+ null
+ );
+ SegmentWriteState state = new SegmentWriteState(
+ InfoStream.getDefault(),
+ segmentInfo.dir,
+ segmentInfo,
+ new FieldInfos(new FieldInfo[0]),
+ null,
+ newIOContext(random())
+ );
+
+ DocValuesConsumer consumer = LuceneDocValuesConsumerFactory.getDocValuesConsumerForCompositeCodec(
+ state,
+ dataCodec,
+ dataExtension,
+ metaCodec,
+ metaExtension
+ );
+
+ assertEquals("org.apache.lucene.codecs.lucene90.Lucene90DocValuesConsumer", consumer.getClass().getName());
+ assertEquals(CompositeCodecFactory.COMPOSITE_CODEC, Composite99Codec.COMPOSITE_INDEX_CODEC_NAME);
+ consumer.close();
+ }
+
+ @After
+ public void teardown() throws Exception {
+ super.tearDown();
+ directory.close();
+ }
+}
diff --git a/server/src/test/java/org/opensearch/index/codec/composite/LuceneDocValuesProducerFactoryTests.java b/server/src/test/java/org/opensearch/index/codec/composite/LuceneDocValuesProducerFactoryTests.java
new file mode 100644
index 0000000000000..55d637dfb9cae
--- /dev/null
+++ b/server/src/test/java/org/opensearch/index/codec/composite/LuceneDocValuesProducerFactoryTests.java
@@ -0,0 +1,124 @@
+/*
+ * 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.codec.composite;
+
+import org.apache.lucene.codecs.DocValuesConsumer;
+import org.apache.lucene.codecs.DocValuesProducer;
+import org.apache.lucene.codecs.lucene99.Lucene99Codec;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.SegmentInfo;
+import org.apache.lucene.index.SegmentReadState;
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.InfoStream;
+import org.apache.lucene.util.Version;
+import org.opensearch.index.codec.composite.composite99.Composite99Codec;
+import org.opensearch.test.OpenSearchTestCase;
+import org.junit.After;
+import org.junit.Before;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.UUID;
+
+import static org.mockito.Mockito.mock;
+
+public class LuceneDocValuesProducerFactoryTests extends OpenSearchTestCase {
+
+ private Directory directory;
+ private final String dataCodec = "data_codec";
+ private final String dataExtension = "data_extension";
+ private final String metaCodec = "meta_codec";
+ private final String metaExtension = "meta_extension";
+
+ @Before
+ public void setup() {
+ directory = newDirectory();
+ }
+
+ public void testGetDocValuesProducerForCompositeCodec99() throws IOException {
+ SegmentInfo segmentInfo = new SegmentInfo(
+ directory,
+ Version.LATEST,
+ Version.LUCENE_9_11_0,
+ "test_segment",
+ randomInt(),
+ false,
+ false,
+ new Lucene99Codec(),
+ new HashMap<>(),
+ UUID.randomUUID().toString().substring(0, 16).getBytes(StandardCharsets.UTF_8),
+ new HashMap<>(),
+ null
+ );
+
+ // open an consumer first in order for the producer to find the file
+ SegmentWriteState state = new SegmentWriteState(
+ InfoStream.getDefault(),
+ segmentInfo.dir,
+ segmentInfo,
+ new FieldInfos(new FieldInfo[0]),
+ null,
+ newIOContext(random())
+ );
+ DocValuesConsumer consumer = LuceneDocValuesConsumerFactory.getDocValuesConsumerForCompositeCodec(
+ state,
+ dataCodec,
+ dataExtension,
+ metaCodec,
+ metaExtension
+ );
+ consumer.close();
+
+ SegmentReadState segmentReadState = new SegmentReadState(
+ segmentInfo.dir,
+ segmentInfo,
+ new FieldInfos(new FieldInfo[0]),
+ newIOContext(random())
+ );
+ DocValuesProducer producer = LuceneDocValuesProducerFactory.getDocValuesProducerForCompositeCodec(
+ Composite99Codec.COMPOSITE_INDEX_CODEC_NAME,
+ segmentReadState,
+ dataCodec,
+ dataExtension,
+ metaCodec,
+ metaExtension
+ );
+
+ assertNotNull(producer);
+ assertEquals("org.apache.lucene.codecs.lucene90.Lucene90DocValuesProducer", producer.getClass().getName());
+ producer.close();
+ }
+
+ public void testGetDocValuesProducerForCompositeCodec_InvalidCodec() {
+ SegmentReadState mockSegmentReadState = mock(SegmentReadState.class);
+
+ IllegalStateException exception = expectThrows(IllegalStateException.class, () -> {
+ LuceneDocValuesProducerFactory.getDocValuesProducerForCompositeCodec(
+ "invalid_codec",
+ mockSegmentReadState,
+ dataCodec,
+ dataExtension,
+ metaCodec,
+ metaExtension
+ );
+ });
+
+ assertNotNull(exception);
+ assertTrue(exception.getMessage().contains("Invalid composite codec"));
+ }
+
+ @After
+ public void teardown() throws Exception {
+ super.tearDown();
+ directory.close();
+ }
+}
diff --git a/server/src/test/java/org/opensearch/index/codec/composite/SortedNumericDocValuesWriterWrapperTests.java b/server/src/test/java/org/opensearch/index/codec/composite/SortedNumericDocValuesWriterWrapperTests.java
new file mode 100644
index 0000000000000..54eead20ef354
--- /dev/null
+++ b/server/src/test/java/org/opensearch/index/codec/composite/SortedNumericDocValuesWriterWrapperTests.java
@@ -0,0 +1,94 @@
+/*
+ * 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.codec.composite;
+
+import org.apache.lucene.index.DocValuesType;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.IndexOptions;
+import org.apache.lucene.index.SortedNumericDocValues;
+import org.apache.lucene.index.SortedNumericDocValuesWriterWrapper;
+import org.apache.lucene.index.VectorEncoding;
+import org.apache.lucene.index.VectorSimilarityFunction;
+import org.apache.lucene.util.Counter;
+import org.opensearch.test.OpenSearchTestCase;
+
+import java.io.IOException;
+import java.util.Collections;
+
+public class SortedNumericDocValuesWriterWrapperTests extends OpenSearchTestCase {
+
+ private SortedNumericDocValuesWriterWrapper wrapper;
+ private FieldInfo fieldInfo;
+ private Counter counter;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ fieldInfo = new FieldInfo(
+ "field",
+ 1,
+ false,
+ false,
+ true,
+ IndexOptions.NONE,
+ DocValuesType.NONE,
+ -1,
+ Collections.emptyMap(),
+ 0,
+ 0,
+ 0,
+ 0,
+ VectorEncoding.FLOAT32,
+ VectorSimilarityFunction.EUCLIDEAN,
+ false,
+ false
+ );
+ counter = Counter.newCounter();
+ wrapper = new SortedNumericDocValuesWriterWrapper(fieldInfo, counter);
+ }
+
+ public void testAddValue() throws IOException {
+ wrapper.addValue(0, 10);
+ wrapper.addValue(1, 20);
+ wrapper.addValue(2, 30);
+
+ SortedNumericDocValues docValues = wrapper.getDocValues();
+ assertNotNull(docValues);
+
+ assertEquals(0, docValues.nextDoc());
+ assertEquals(10, docValues.nextValue());
+ assertEquals(1, docValues.nextDoc());
+ assertEquals(20, docValues.nextValue());
+ assertEquals(2, docValues.nextDoc());
+ assertEquals(30, docValues.nextValue());
+ }
+
+ public void testGetDocValues() {
+ SortedNumericDocValues docValues = wrapper.getDocValues();
+ assertNotNull(docValues);
+ }
+
+ public void testMultipleValues() throws IOException {
+ wrapper.addValue(0, 10);
+ wrapper.addValue(0, 20);
+ wrapper.addValue(1, 30);
+
+ SortedNumericDocValues docValues = wrapper.getDocValues();
+ assertNotNull(docValues);
+
+ assertEquals(0, docValues.nextDoc());
+ assertEquals(10, docValues.nextValue());
+ assertEquals(20, docValues.nextValue());
+ assertThrows(IllegalStateException.class, docValues::nextValue);
+
+ assertEquals(1, docValues.nextDoc());
+ assertEquals(30, docValues.nextValue());
+ assertThrows(IllegalStateException.class, docValues::nextValue);
+ }
+}
diff --git a/server/src/test/java/org/opensearch/index/codec/composite/datacube/startree/StarTreeDocValuesFormatTests.java b/server/src/test/java/org/opensearch/index/codec/composite/datacube/startree/StarTreeDocValuesFormatTests.java
index 6fa88215cad48..54a9cc035d7a9 100644
--- a/server/src/test/java/org/opensearch/index/codec/composite/datacube/startree/StarTreeDocValuesFormatTests.java
+++ b/server/src/test/java/org/opensearch/index/codec/composite/datacube/startree/StarTreeDocValuesFormatTests.java
@@ -29,7 +29,7 @@
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.MapperTestUtils;
-import org.opensearch.index.codec.composite.Composite99Codec;
+import org.opensearch.index.codec.composite.composite99.Composite99Codec;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.indices.IndicesModule;
import org.junit.After;