Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Star Tree Meta and Data Writers #15295

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
@@ -0,0 +1,26 @@
/*
* 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;

/**
* This class contains constants used in the Composite Index implementation.
*/
public class CompositeIndexConstants {

Check warning on line 14 in server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexConstants.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/CompositeIndexConstants.java#L14

Added line #L14 was not covered by tests

/**
* The magic marker value used for sanity checks in the Composite Index implementation.
*/
public static final long COMPOSITE_FIELD_MARKER = 0xC0950513F1E1DL; // Composite Field

/**
* Represents the key to fetch number of non-star aggregated segment documents.
*/
public static final String SEGMENT_DOCS_COUNT = "segmentDocsCount";

}
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.opensearch.index.compositeindex;

import org.opensearch.index.mapper.CompositeMappedFieldType;

/**
* This class represents the metadata of a Composite Index, which includes information about
* the composite field name, type, and the specific metadata for the type of composite field
sarthakaggarwal97 marked this conversation as resolved.
Show resolved Hide resolved
* (e.g., Star Tree metadata).
*
* @opensearch.experimental
*/
public class CompositeIndexMetadata {

private final String compositeFieldName;
private final CompositeMappedFieldType.CompositeFieldType compositeFieldType;

/**
* Constructs a CompositeIndexMetadata object with the provided composite field name and type.
*
* @param compositeFieldName the name of the composite field
* @param compositeFieldType the type of the composite field
*/
public CompositeIndexMetadata(String compositeFieldName, CompositeMappedFieldType.CompositeFieldType compositeFieldType) {
this.compositeFieldName = compositeFieldName;
this.compositeFieldType = compositeFieldType;
}

/**
* Returns the name of the composite field.
*
* @return the composite field name
*/
public String getCompositeFieldName() {
return compositeFieldName;
}

/**
* Returns the type of the composite field.
*
* @return the composite field type
*/
public CompositeMappedFieldType.CompositeFieldType getCompositeFieldType() {
return compositeFieldType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,43 @@
*/
@ExperimentalApi
public enum MetricStat {
VALUE_COUNT("value_count"),
SUM("sum"),
MIN("min"),
MAX("max"),
AVG("avg", VALUE_COUNT, SUM),
DOC_COUNT("doc_count", true);
VALUE_COUNT("value_count", 0),
SUM("sum", 1),
MIN("min", 2),
MAX("max", 3),
AVG("avg", 4, VALUE_COUNT, SUM),
DOC_COUNT("doc_count", true, 5);

private final String typeName;
private final MetricStat[] baseMetrics;
private final int metricOrdinal;

// System field stats cannot be used as input for user metric types
private final boolean isSystemFieldStat;

MetricStat(String typeName) {
this(typeName, false);
MetricStat(String typeName, int metricOrdinal) {
this(typeName, false, metricOrdinal);
}

MetricStat(String typeName, MetricStat... baseMetrics) {
this(typeName, false, baseMetrics);
MetricStat(String typeName, int metricOrdinal, MetricStat... baseMetrics) {
this(typeName, false, metricOrdinal, baseMetrics);
}

MetricStat(String typeName, boolean isSystemFieldStat, MetricStat... baseMetrics) {
MetricStat(String typeName, boolean isSystemFieldStat, int metricOrdinal, MetricStat... baseMetrics) {
this.typeName = typeName;
this.isSystemFieldStat = isSystemFieldStat;
this.baseMetrics = baseMetrics;
this.metricOrdinal = metricOrdinal;
}

public String getTypeName() {
return typeName;
}

public int getMetricOrdinal() {
return metricOrdinal;
}

/**
* Return the list of metrics that this metric is derived from
* For example, AVG is derived from COUNT and SUM
Expand All @@ -76,4 +82,13 @@
}
throw new IllegalArgumentException("Invalid metric stat: " + typeName);
}

public static MetricStat fromMetricOrdinal(int metricOrdinal) {
for (MetricStat metric : MetricStat.values()) {
if (metric.getMetricOrdinal() == metricOrdinal) {
return metric;
}
}
throw new IllegalArgumentException("Invalid metric stat: " + metricOrdinal);

Check warning on line 92 in server/src/main/java/org/opensearch/index/compositeindex/datacube/MetricStat.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/MetricStat.java#L92

Added line #L92 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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;

import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.mapper.CompositeDataCubeFieldType;

import java.io.IOException;
import java.util.Objects;

/**
* Represents a dimension for reconstructing StarTreeField from file formats during searches and merges.
*
* @opensearch.experimental
*/
public class ReadDimension implements Dimension {
sarthakaggarwal97 marked this conversation as resolved.
Show resolved Hide resolved
public static final String READ = "read";
private final String field;

public ReadDimension(String field) {
this.field = field;
}

public String getField() {
return field;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(CompositeDataCubeFieldType.NAME, field);
builder.field(CompositeDataCubeFieldType.TYPE, READ);
builder.endObject();
return builder;

Check warning on line 40 in server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java#L36-L40

Added lines #L36 - L40 were not covered by tests
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ReadDimension dimension = (ReadDimension) o;
return Objects.equals(field, dimension.getField());
}

@Override
public int hashCode() {
return Objects.hash(field);

Check warning on line 53 in server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java#L53

Added line #L53 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,25 @@
@ExperimentalApi
public enum StarTreeBuildMode {
// TODO : remove onheap support unless this proves useful
ON_HEAP("onheap"),
OFF_HEAP("offheap");
ON_HEAP("onheap", (byte) 0),
OFF_HEAP("offheap", (byte) 1);

private final String typeName;
private final byte buildModeOrdinal;

StarTreeBuildMode(String typeName) {
StarTreeBuildMode(String typeName, byte buildModeOrdinal) {
this.typeName = typeName;
this.buildModeOrdinal = buildModeOrdinal;
}

public String getTypeName() {
return typeName;
}

public byte getBuildModeOrdinal() {
return buildModeOrdinal;
}

public static StarTreeBuildMode fromTypeName(String typeName) {
for (StarTreeBuildMode starTreeBuildMode : StarTreeBuildMode.values()) {
if (starTreeBuildMode.getTypeName().equalsIgnoreCase(typeName)) {
Expand All @@ -77,6 +83,16 @@
}
throw new IllegalArgumentException(String.format(Locale.ROOT, "Invalid star tree build mode: [%s] ", typeName));
}

public static StarTreeBuildMode fromBuildModeOrdinal(byte buildModeOrdinal) {
for (StarTreeBuildMode starTreeBuildMode : StarTreeBuildMode.values()) {
if (starTreeBuildMode.getBuildModeOrdinal() == buildModeOrdinal) {
return starTreeBuildMode;
}
}
throw new IllegalArgumentException(String.format(Locale.ROOT, "Invalid star tree build mode: [%s] ", buildModeOrdinal));

Check warning on line 93 in server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/StarTreeFieldConfiguration.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/StarTreeFieldConfiguration.java#L93

Added line #L93 was not covered by tests
}

}

public int maxLeafDocs() {
Expand Down
Loading
Loading