Skip to content

Commit 8629279

Browse files
Star Tree Meta and Data Writers (opensearch-project#15295)
--------- Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
1 parent 5663b4a commit 8629279

30 files changed

+2418
-92
lines changed

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ public static DocValuesConsumer getDocValuesConsumerForCompositeCodec(
3434
String metaCodec,
3535
String metaExtension
3636
) throws IOException {
37-
try (
38-
Lucene90DocValuesConsumerWrapper lucene90DocValuesConsumerWrapper = new Lucene90DocValuesConsumerWrapper(
39-
state,
40-
dataCodec,
41-
dataExtension,
42-
metaCodec,
43-
metaExtension
44-
)
45-
) {
46-
return lucene90DocValuesConsumerWrapper.getLucene90DocValuesConsumer();
47-
}
37+
Lucene90DocValuesConsumerWrapper lucene90DocValuesConsumerWrapper = new Lucene90DocValuesConsumerWrapper(
38+
state,
39+
dataCodec,
40+
dataExtension,
41+
metaCodec,
42+
metaExtension
43+
);
44+
return lucene90DocValuesConsumerWrapper.getLucene90DocValuesConsumer();
45+
4846
}
4947

5048
}

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,14 @@ public static DocValuesProducer getDocValuesProducerForCompositeCodec(
4040

4141
switch (compositeCodec) {
4242
case Composite99Codec.COMPOSITE_INDEX_CODEC_NAME:
43-
try (
44-
Lucene90DocValuesProducerWrapper lucene90DocValuesProducerWrapper = new Lucene90DocValuesProducerWrapper(
45-
state,
46-
dataCodec,
47-
dataExtension,
48-
metaCodec,
49-
metaExtension
50-
)
51-
) {
52-
return lucene90DocValuesProducerWrapper.getLucene90DocValuesProducer();
53-
}
43+
Lucene90DocValuesProducerWrapper lucene90DocValuesProducerWrapper = new Lucene90DocValuesProducerWrapper(
44+
state,
45+
dataCodec,
46+
dataExtension,
47+
metaCodec,
48+
metaExtension
49+
);
50+
return lucene90DocValuesProducerWrapper.getLucene90DocValuesProducer();
5451
default:
5552
throw new IllegalStateException("Invalid composite codec " + "[" + compositeCodec + "]");
5653
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.compositeindex;
10+
11+
/**
12+
* This class contains constants used in the Composite Index implementation.
13+
*/
14+
public class CompositeIndexConstants {
15+
16+
/**
17+
* The magic marker value used for sanity checks in the Composite Index implementation.
18+
*/
19+
public static final long COMPOSITE_FIELD_MARKER = 0xC0950513F1E1DL; // Composite Field
20+
21+
/**
22+
* Represents the key to fetch number of non-star aggregated segment documents.
23+
*/
24+
public static final String SEGMENT_DOCS_COUNT = "segmentDocsCount";
25+
26+
}
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.opensearch.index.compositeindex;
10+
11+
import org.opensearch.index.mapper.CompositeMappedFieldType;
12+
13+
/**
14+
* This class represents the metadata of a Composite Index, which includes information about
15+
* the composite field name, type, and the specific metadata for the type of composite field
16+
* (e.g., Star Tree metadata).
17+
*
18+
* @opensearch.experimental
19+
*/
20+
public class CompositeIndexMetadata {
21+
22+
private final String compositeFieldName;
23+
private final CompositeMappedFieldType.CompositeFieldType compositeFieldType;
24+
25+
/**
26+
* Constructs a CompositeIndexMetadata object with the provided composite field name and type.
27+
*
28+
* @param compositeFieldName the name of the composite field
29+
* @param compositeFieldType the type of the composite field
30+
*/
31+
public CompositeIndexMetadata(String compositeFieldName, CompositeMappedFieldType.CompositeFieldType compositeFieldType) {
32+
this.compositeFieldName = compositeFieldName;
33+
this.compositeFieldType = compositeFieldType;
34+
}
35+
36+
/**
37+
* Returns the name of the composite field.
38+
*
39+
* @return the composite field name
40+
*/
41+
public String getCompositeFieldName() {
42+
return compositeFieldName;
43+
}
44+
45+
/**
46+
* Returns the type of the composite field.
47+
*
48+
* @return the composite field type
49+
*/
50+
public CompositeMappedFieldType.CompositeFieldType getCompositeFieldType() {
51+
return compositeFieldType;
52+
}
53+
}

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

+26-11
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,43 @@
2020
*/
2121
@ExperimentalApi
2222
public enum MetricStat {
23-
VALUE_COUNT("value_count"),
24-
SUM("sum"),
25-
MIN("min"),
26-
MAX("max"),
27-
AVG("avg", VALUE_COUNT, SUM),
28-
DOC_COUNT("doc_count", true);
23+
VALUE_COUNT("value_count", 0),
24+
SUM("sum", 1),
25+
MIN("min", 2),
26+
MAX("max", 3),
27+
AVG("avg", 4, VALUE_COUNT, SUM),
28+
DOC_COUNT("doc_count", true, 5);
2929

3030
private final String typeName;
3131
private final MetricStat[] baseMetrics;
32+
private final int metricOrdinal;
3233

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

36-
MetricStat(String typeName) {
37-
this(typeName, false);
37+
MetricStat(String typeName, int metricOrdinal) {
38+
this(typeName, false, metricOrdinal);
3839
}
3940

40-
MetricStat(String typeName, MetricStat... baseMetrics) {
41-
this(typeName, false, baseMetrics);
41+
MetricStat(String typeName, int metricOrdinal, MetricStat... baseMetrics) {
42+
this(typeName, false, metricOrdinal, baseMetrics);
4243
}
4344

44-
MetricStat(String typeName, boolean isSystemFieldStat, MetricStat... baseMetrics) {
45+
MetricStat(String typeName, boolean isSystemFieldStat, int metricOrdinal, MetricStat... baseMetrics) {
4546
this.typeName = typeName;
4647
this.isSystemFieldStat = isSystemFieldStat;
4748
this.baseMetrics = baseMetrics;
49+
this.metricOrdinal = metricOrdinal;
4850
}
4951

5052
public String getTypeName() {
5153
return typeName;
5254
}
5355

56+
public int getMetricOrdinal() {
57+
return metricOrdinal;
58+
}
59+
5460
/**
5561
* Return the list of metrics that this metric is derived from
5662
* For example, AVG is derived from COUNT and SUM
@@ -76,4 +82,13 @@ public static MetricStat fromTypeName(String typeName) {
7682
}
7783
throw new IllegalArgumentException("Invalid metric stat: " + typeName);
7884
}
85+
86+
public static MetricStat fromMetricOrdinal(int metricOrdinal) {
87+
for (MetricStat metric : MetricStat.values()) {
88+
if (metric.getMetricOrdinal() == metricOrdinal) {
89+
return metric;
90+
}
91+
}
92+
throw new IllegalArgumentException("Invalid metric stat: " + metricOrdinal);
93+
}
7994
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.compositeindex.datacube;
10+
11+
import org.opensearch.core.xcontent.XContentBuilder;
12+
import org.opensearch.index.mapper.CompositeDataCubeFieldType;
13+
14+
import java.io.IOException;
15+
import java.util.Objects;
16+
17+
/**
18+
* Represents a dimension for reconstructing StarTreeField from file formats during searches and merges.
19+
*
20+
* @opensearch.experimental
21+
*/
22+
public class ReadDimension implements Dimension {
23+
public static final String READ = "read";
24+
private final String field;
25+
26+
public ReadDimension(String field) {
27+
this.field = field;
28+
}
29+
30+
public String getField() {
31+
return field;
32+
}
33+
34+
@Override
35+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
36+
builder.startObject();
37+
builder.field(CompositeDataCubeFieldType.NAME, field);
38+
builder.field(CompositeDataCubeFieldType.TYPE, READ);
39+
builder.endObject();
40+
return builder;
41+
}
42+
43+
@Override
44+
public boolean equals(Object o) {
45+
if (this == o) return true;
46+
if (o == null || getClass() != o.getClass()) return false;
47+
ReadDimension dimension = (ReadDimension) o;
48+
return Objects.equals(field, dimension.getField());
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(field);
54+
}
55+
}

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

+19-3
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,25 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
5656
@ExperimentalApi
5757
public enum StarTreeBuildMode {
5858
// TODO : remove onheap support unless this proves useful
59-
ON_HEAP("onheap"),
60-
OFF_HEAP("offheap");
59+
ON_HEAP("onheap", (byte) 0),
60+
OFF_HEAP("offheap", (byte) 1);
6161

6262
private final String typeName;
63+
private final byte buildModeOrdinal;
6364

64-
StarTreeBuildMode(String typeName) {
65+
StarTreeBuildMode(String typeName, byte buildModeOrdinal) {
6566
this.typeName = typeName;
67+
this.buildModeOrdinal = buildModeOrdinal;
6668
}
6769

6870
public String getTypeName() {
6971
return typeName;
7072
}
7173

74+
public byte getBuildModeOrdinal() {
75+
return buildModeOrdinal;
76+
}
77+
7278
public static StarTreeBuildMode fromTypeName(String typeName) {
7379
for (StarTreeBuildMode starTreeBuildMode : StarTreeBuildMode.values()) {
7480
if (starTreeBuildMode.getTypeName().equalsIgnoreCase(typeName)) {
@@ -77,6 +83,16 @@ public static StarTreeBuildMode fromTypeName(String typeName) {
7783
}
7884
throw new IllegalArgumentException(String.format(Locale.ROOT, "Invalid star tree build mode: [%s] ", typeName));
7985
}
86+
87+
public static StarTreeBuildMode fromBuildModeOrdinal(byte buildModeOrdinal) {
88+
for (StarTreeBuildMode starTreeBuildMode : StarTreeBuildMode.values()) {
89+
if (starTreeBuildMode.getBuildModeOrdinal() == buildModeOrdinal) {
90+
return starTreeBuildMode;
91+
}
92+
}
93+
throw new IllegalArgumentException(String.format(Locale.ROOT, "Invalid star tree build mode: [%s] ", buildModeOrdinal));
94+
}
95+
8096
}
8197

8298
public int maxLeafDocs() {

0 commit comments

Comments
 (0)