Skip to content

Commit

Permalink
star tree file formats
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 authored and sandeshkr419 committed Aug 19, 2024
1 parent 096c354 commit 91e1f2f
Show file tree
Hide file tree
Showing 65 changed files with 5,079 additions and 702 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.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 {

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 org.apache.lucene.index.SortedNumericDocValues;
import org.opensearch.index.codec.composite.DocValuesProvider;

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 DocValuesProvider {

private final Lucene90DocValuesProducer lucene90DocValuesProducer;
private final SegmentReadState state;

public Lucene90DocValuesProducerWrapper(
SegmentReadState state,
String dataCodec,
String dataExtension,
String metaCodec,
String metaExtension
) throws IOException {
lucene90DocValuesProducer = new Lucene90DocValuesProducer(state, dataCodec, dataExtension, metaCodec, metaExtension);
this.state = state;
}

// returns the field doc id set iterator based on field name
@Override
public SortedNumericDocValues getSortedNumeric(String fieldName) throws IOException {
return this.lucene90DocValuesProducer.getSortedNumeric(state.fieldInfos.fieldInfo(fieldName));
}

@Override
public DocValuesProducer getDocValuesProducer() {
return lucene90DocValuesProducer;
}

}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.index.codec.composite;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.index.compositeindex.datacube.startree.index.CompositeIndexValues;

import java.io.IOException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.index.SortedNumericDocValues;

import java.io.IOException;

/**
* An interface that provides access to document values for a specific field.
*
* @opensearch.experimental
*/
public interface DocValuesProvider {

/**
* Returns the sorted numeric document values for the specified field.
*
* @param fieldName The name of the field for which to retrieve the sorted numeric document values.
* @return The sorted numeric document values for the specified field.
* @throws IOException If an error occurs while retrieving the sorted numeric document values.
*/
SortedNumericDocValues getSortedNumeric(String fieldName) throws IOException;

/**
* Returns the DocValuesProducer instance.
*
* @return The DocValuesProducer instance.
*/
DocValuesProducer getDocValuesProducer();
}
Original file line number Diff line number Diff line change
@@ -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.opensearch.index.codec.composite;

import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesConsumerWrapper;
import org.apache.lucene.index.SegmentWriteState;

import java.io.IOException;

import static org.opensearch.index.codec.composite.composite99.Composite99Codec.COMPOSITE_INDEX_CODEC_NAME;

/**
* A factory class that provides a factory method for creating {@link DocValuesConsumer} instances
* based on the specified composite codec.
*
* @opensearch.experimental
*/
public class LuceneDocValuesConsumerFactory {

public static DocValuesConsumer getDocValuesConsumerForCompositeCodec(
String compositeCodec,
SegmentWriteState state,
String dataCodec,
String dataExtension,
String metaCodec,
String metaExtension
) throws IOException {

switch (compositeCodec) {
case COMPOSITE_INDEX_CODEC_NAME:
return new Lucene90DocValuesConsumerWrapper(state, dataCodec, dataExtension, metaCodec, metaExtension)
.getLucene90DocValuesConsumer();
default:
throw new IllegalStateException("Invalid composite codec " + "[" + compositeCodec + "]");
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.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 DocValuesConsumer} instances
* based on the specified composite codec.
*
* @opensearch.experimental
*/
public class LuceneDocValuesProducerFactory {

public static DocValuesProvider getDocValuesProducerForCompositeCodec(
String compositeCodec,
SegmentReadState state,
String dataCodec,
String dataExtension,
String metaCodec,
String metaExtension
) throws IOException {

switch (compositeCodec) {
case Composite99Codec.COMPOSITE_INDEX_CODEC_NAME:
return new Lucene90DocValuesProducerWrapper(state, dataCodec, dataExtension, metaCodec, metaExtension);
default:
throw new IllegalStateException("Invalid composite codec " + "[" + compositeCodec + "]");
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 91e1f2f

Please sign in to comment.