Skip to content

Commit 310503c

Browse files
refactoring packages and lucene consumer / producer classes wrapper
Signed-off-by: Sarthak Aggarwal <[email protected]>
1 parent b316279 commit 310503c

17 files changed

+528
-7
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.apache.lucene.codecs.lucene90;
10+
11+
import org.apache.lucene.codecs.DocValuesConsumer;
12+
import org.apache.lucene.index.SegmentWriteState;
13+
14+
import java.io.IOException;
15+
16+
/**
17+
* This class is an abstraction of the {@link DocValuesConsumer} for the Star Tree index structure.
18+
* It is responsible to consume various types of document values (numeric, binary, sorted, sorted numeric,
19+
* and sorted set) for fields in the Star Tree index.
20+
*
21+
* @opensearch.experimental
22+
*/
23+
public class Lucene90DocValuesConsumerWrapper {
24+
25+
private final Lucene90DocValuesConsumer lucene90DocValuesConsumer;
26+
27+
public Lucene90DocValuesConsumerWrapper(
28+
SegmentWriteState state,
29+
String dataCodec,
30+
String dataExtension,
31+
String metaCodec,
32+
String metaExtension
33+
) throws IOException {
34+
lucene90DocValuesConsumer = new Lucene90DocValuesConsumer(state, dataCodec, dataExtension, metaCodec, metaExtension);
35+
}
36+
37+
public Lucene90DocValuesConsumer getLucene90DocValuesConsumer() {
38+
return lucene90DocValuesConsumer;
39+
}
40+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.apache.lucene.codecs.lucene90;
10+
11+
import org.apache.lucene.codecs.DocValuesProducer;
12+
import org.apache.lucene.index.SegmentReadState;
13+
import org.apache.lucene.index.SortedNumericDocValues;
14+
import org.opensearch.index.codec.composite.DocValuesProvider;
15+
16+
import java.io.IOException;
17+
18+
/**
19+
* This class is a custom abstraction of the {@link DocValuesProducer} for the Star Tree index structure.
20+
* It is responsible for providing access to various types of document values (numeric, binary, sorted, sorted numeric,
21+
* and sorted set) for fields in the Star Tree index.
22+
*
23+
* @opensearch.experimental
24+
*/
25+
public class Lucene90DocValuesProducerWrapper implements DocValuesProvider {
26+
27+
private final Lucene90DocValuesProducer lucene90DocValuesProducer;
28+
private final SegmentReadState state;
29+
30+
public Lucene90DocValuesProducerWrapper(
31+
SegmentReadState state,
32+
String dataCodec,
33+
String dataExtension,
34+
String metaCodec,
35+
String metaExtension
36+
) throws IOException {
37+
lucene90DocValuesProducer = new Lucene90DocValuesProducer(state, dataCodec, dataExtension, metaCodec, metaExtension);
38+
this.state = state;
39+
}
40+
41+
// returns the field doc id set iterator based on field name
42+
@Override
43+
public SortedNumericDocValues getSortedNumeric(String fieldName) throws IOException {
44+
return this.lucene90DocValuesProducer.getSortedNumeric(state.fieldInfos.fieldInfo(fieldName));
45+
}
46+
47+
@Override
48+
public DocValuesProducer getDocValuesProducer() {
49+
return lucene90DocValuesProducer;
50+
}
51+
52+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.apache.lucene.index;
10+
11+
import org.apache.lucene.util.Counter;
12+
13+
/**
14+
* A wrapper class for writing sorted numeric doc values.
15+
* <p>
16+
* This class provides a convenient way to add sorted numeric doc values to a field
17+
* and retrieve the corresponding {@link SortedNumericDocValues} instance.
18+
*
19+
* @opensearch.experimental
20+
*/
21+
public class SortedNumericDocValuesWriterWrapper {
22+
23+
private final SortedNumericDocValuesWriter sortedNumericDocValuesWriter;
24+
25+
/**
26+
* Sole constructor. Constructs a new {@link SortedNumericDocValuesWriterWrapper} instance.
27+
*
28+
* @param fieldInfo the field information for the field being written
29+
* @param counter a counter for tracking memory usage
30+
*/
31+
public SortedNumericDocValuesWriterWrapper(FieldInfo fieldInfo, Counter counter) {
32+
sortedNumericDocValuesWriter = new SortedNumericDocValuesWriter(fieldInfo, counter);
33+
}
34+
35+
/**
36+
* Adds a value to the sorted numeric doc values for the specified document.
37+
*
38+
* @param docID the document ID
39+
* @param value the value to add
40+
*/
41+
public void addValue(int docID, long value) {
42+
sortedNumericDocValuesWriter.addValue(docID, value);
43+
}
44+
45+
/**
46+
* Returns the {@link SortedNumericDocValues} instance containing the sorted numeric doc values
47+
*
48+
* @return the {@link SortedNumericDocValues} instance
49+
*/
50+
public SortedNumericDocValues getDocValues() {
51+
return sortedNumericDocValuesWriter.getDocValues();
52+
}
53+
}

server/src/main/java/org/opensearch/index/codec/composite/CompositeCodecFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.lucene.codecs.Codec;
1313
import org.apache.lucene.codecs.lucene99.Lucene99Codec;
1414
import org.opensearch.common.annotation.ExperimentalApi;
15+
import org.opensearch.index.codec.composite.composite99.Composite99Codec;
1516
import org.opensearch.index.mapper.MapperService;
1617

1718
import java.util.HashMap;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.index.codec.composite;
10+
11+
import org.apache.lucene.codecs.DocValuesProducer;
12+
import org.apache.lucene.index.SortedNumericDocValues;
13+
14+
import java.io.IOException;
15+
16+
/**
17+
* An interface that provides access to document values for a specific field.
18+
*
19+
* @opensearch.experimental
20+
*/
21+
public interface DocValuesProvider {
22+
23+
/**
24+
* Returns the sorted numeric document values for the specified field.
25+
*
26+
* @param fieldName The name of the field for which to retrieve the sorted numeric document values.
27+
* @return The sorted numeric document values for the specified field.
28+
* @throws IOException If an error occurs while retrieving the sorted numeric document values.
29+
*/
30+
SortedNumericDocValues getSortedNumeric(String fieldName) throws IOException;
31+
32+
/**
33+
* Returns the DocValuesProducer instance.
34+
*
35+
* @return The DocValuesProducer instance.
36+
*/
37+
DocValuesProducer getDocValuesProducer();
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.index.codec.composite;
10+
11+
import org.apache.lucene.codecs.DocValuesConsumer;
12+
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesConsumerWrapper;
13+
import org.apache.lucene.index.SegmentWriteState;
14+
15+
import java.io.IOException;
16+
17+
import static org.opensearch.index.codec.composite.composite99.Composite99Codec.COMPOSITE_INDEX_CODEC_NAME;
18+
19+
/**
20+
* A factory class that provides a factory method for creating {@link DocValuesConsumer} instances
21+
* based on the specified composite codec.
22+
*
23+
* @opensearch.experimental
24+
*/
25+
public class LuceneDocValuesConsumerFactory {
26+
27+
public static DocValuesConsumer getDocValuesConsumerForCompositeCodec(
28+
String compositeCodec,
29+
SegmentWriteState state,
30+
String dataCodec,
31+
String dataExtension,
32+
String metaCodec,
33+
String metaExtension
34+
) throws IOException {
35+
36+
switch (compositeCodec) {
37+
case COMPOSITE_INDEX_CODEC_NAME:
38+
return new Lucene90DocValuesConsumerWrapper(state, dataCodec, dataExtension, metaCodec, metaExtension)
39+
.getLucene90DocValuesConsumer();
40+
default:
41+
throw new IllegalStateException("Invalid composite codec " + "[" + compositeCodec + "]");
42+
}
43+
44+
}
45+
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.index.codec.composite;
10+
11+
import org.apache.lucene.codecs.DocValuesProducer;
12+
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesProducerWrapper;
13+
import org.apache.lucene.index.SegmentReadState;
14+
import org.opensearch.index.codec.composite.composite99.Composite99Codec;
15+
16+
import java.io.IOException;
17+
18+
/**
19+
* A factory class that provides a factory method for creating {@link DocValuesProducer} instances
20+
* based on the specified composite codec.
21+
*
22+
* @opensearch.experimental
23+
*/
24+
public class LuceneDocValuesProducerFactory {
25+
26+
public static DocValuesProvider getDocValuesProducerForCompositeCodec(
27+
String compositeCodec,
28+
SegmentReadState state,
29+
String dataCodec,
30+
String dataExtension,
31+
String metaCodec,
32+
String metaExtension
33+
) throws IOException {
34+
35+
switch (compositeCodec) {
36+
case Composite99Codec.COMPOSITE_INDEX_CODEC_NAME:
37+
return new Lucene90DocValuesProducerWrapper(state, dataCodec, dataExtension, metaCodec, metaExtension);
38+
default:
39+
throw new IllegalStateException("Invalid composite codec " + "[" + compositeCodec + "]");
40+
}
41+
42+
}
43+
44+
}

server/src/main/java/org/opensearch/index/codec/composite/Composite99Codec.java renamed to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99Codec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.index.codec.composite;
9+
package org.opensearch.index.codec.composite.composite99;
1010

1111
import org.apache.logging.log4j.Logger;
1212
import org.apache.lucene.codecs.Codec;

server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesFormat.java renamed to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.index.codec.composite;
9+
package org.opensearch.index.codec.composite.composite99;
1010

1111
import org.apache.lucene.codecs.DocValuesConsumer;
1212
import org.apache.lucene.codecs.DocValuesFormat;

server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesReader.java renamed to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesReader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.index.codec.composite;
9+
package org.opensearch.index.codec.composite.composite99;
1010

1111
import org.apache.lucene.codecs.DocValuesProducer;
1212
import org.apache.lucene.index.BinaryDocValues;
@@ -17,6 +17,9 @@
1717
import org.apache.lucene.index.SortedNumericDocValues;
1818
import org.apache.lucene.index.SortedSetDocValues;
1919
import org.opensearch.common.annotation.ExperimentalApi;
20+
import org.opensearch.index.codec.composite.CompositeIndexFieldInfo;
21+
import org.opensearch.index.codec.composite.CompositeIndexReader;
22+
import org.opensearch.index.codec.composite.CompositeIndexValues;
2023

2124
import java.io.IOException;
2225
import java.util.ArrayList;

server/src/main/java/org/opensearch/index/codec/composite/Composite99DocValuesWriter.java renamed to server/src/main/java/org/opensearch/index/codec/composite/composite99/Composite99DocValuesWriter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.index.codec.composite;
9+
package org.opensearch.index.codec.composite.composite99;
1010

1111
import org.apache.lucene.codecs.DocValuesConsumer;
1212
import org.apache.lucene.codecs.DocValuesProducer;
@@ -18,6 +18,9 @@
1818
import org.apache.lucene.index.SegmentWriteState;
1919
import org.apache.lucene.index.SortedNumericDocValues;
2020
import org.opensearch.common.annotation.ExperimentalApi;
21+
import org.opensearch.index.codec.composite.CompositeIndexFieldInfo;
22+
import org.opensearch.index.codec.composite.CompositeIndexReader;
23+
import org.opensearch.index.codec.composite.CompositeIndexValues;
2124
import org.opensearch.index.codec.composite.datacube.startree.StarTreeValues;
2225
import org.opensearch.index.compositeindex.datacube.startree.StarTreeField;
2326
import org.opensearch.index.compositeindex.datacube.startree.builder.StarTreesBuilder;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/**
10+
* Responsible for handling all composite index codecs and operations associated with Composite99 codec
11+
*/
12+
package org.opensearch.index.codec.composite.composite99;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
org.opensearch.index.codec.composite.Composite99Codec
1+
org.opensearch.index.codec.composite.composite99.Composite99Codec

server/src/test/java/org/opensearch/index/codec/CodecTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.opensearch.env.Environment;
4949
import org.opensearch.index.IndexSettings;
5050
import org.opensearch.index.analysis.IndexAnalyzers;
51-
import org.opensearch.index.codec.composite.Composite99Codec;
51+
import org.opensearch.index.codec.composite.composite99.Composite99Codec;
5252
import org.opensearch.index.engine.EngineConfig;
5353
import org.opensearch.index.mapper.MapperService;
5454
import org.opensearch.index.similarity.SimilarityService;

0 commit comments

Comments
 (0)