Skip to content

Commit fdb9628

Browse files
committed
checkpoint
1 parent 75c602d commit fdb9628

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static TransportVersion def(int id) {
302302
public static final TransportVersion SECURITY_CLOUD_API_KEY_REALM_AND_TYPE = def(9_099_0_00);
303303
public static final TransportVersion STATE_PARAM_GET_SNAPSHOT = def(9_100_0_00);
304304
public static final TransportVersion PROJECT_ID_IN_SNAPSHOTS_DELETIONS_AND_REPO_CLEANUP = def(9_101_0_00);
305-
305+
public static final TransportVersion ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE = def(9_102_0_00);
306306
/*
307307
* STOP! READ THIS FIRST! No, really,
308308
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DateEsField.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.elasticsearch.xpack.esql.core.type;
88

9+
import org.elasticsearch.TransportVersions;
910
import org.elasticsearch.common.io.stream.StreamInput;
1011
import org.elasticsearch.common.io.stream.StreamOutput;
1112

@@ -30,13 +31,21 @@ private DateEsField(String name, DataType dataType, Map<String, EsField> propert
3031

3132
protected DateEsField(StreamInput in) throws IOException {
3233
this(readCachedStringWithVersionCheck(in), DataType.DATETIME, in.readImmutableMap(EsField::readFrom), in.readBoolean());
34+
if (in.getTransportVersion().onOrAfter(TransportVersions.ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE)) {
35+
this.timeSeriesFieldType = TimeSeriesFieldType.readFromStream(in);
36+
} else {
37+
this.timeSeriesFieldType = TimeSeriesFieldType.UNKNOWN;
38+
}
3339
}
3440

3541
@Override
3642
public void writeContent(StreamOutput out) throws IOException {
3743
writeCachedStringWithVersionCheck(out, getName());
3844
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
3945
out.writeBoolean(isAggregatable());
46+
if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE)) {
47+
this.timeSeriesFieldType.writeTo(out);
48+
}
4049
}
4150

4251
public String getWriteableName() {

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/EsField.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,40 @@
2626
*/
2727
public class EsField implements Writeable {
2828

29-
private static Map<String, Writeable.Reader<? extends EsField>> readers = Map.ofEntries(
29+
/**
30+
* Fields in a TSDB can be either dimensions or metrics. This enum provides a way to store, serialize, and operate on those field
31+
* roles within the ESQL query processing pipeline.
32+
*/
33+
public enum TimeSeriesFieldType implements Writeable {
34+
UNKNOWN(0),
35+
NONE(1),
36+
METRIC(2),
37+
DIMENSION(3);
38+
39+
private final int id;
40+
41+
TimeSeriesFieldType(int id) {
42+
this.id = id;
43+
}
44+
45+
@Override
46+
public void writeTo(StreamOutput out) throws IOException {
47+
out.writeVInt(id);
48+
}
49+
50+
public static TimeSeriesFieldType readFromStream(StreamInput in) throws IOException {
51+
int id = in.readVInt();
52+
return switch (id) {
53+
case 0 -> UNKNOWN;
54+
case 1 -> NONE;
55+
case 2 -> METRIC;
56+
case 3 -> DIMENSION;
57+
default -> throw new IOException("Unexpected value for TimeSeriesFieldType: " + id);
58+
};
59+
}
60+
}
61+
62+
private static Map<String, Reader<? extends EsField>> readers = Map.ofEntries(
3063
Map.entry("DateEsField", DateEsField::new),
3164
Map.entry("EsField", EsField::new),
3265
Map.entry("InvalidMappedField", InvalidMappedField::new),
@@ -37,7 +70,7 @@ public class EsField implements Writeable {
3770
Map.entry("UnsupportedEsField", UnsupportedEsField::new)
3871
);
3972

40-
public static Writeable.Reader<? extends EsField> getReader(String name) {
73+
public static Reader<? extends EsField> getReader(String name) {
4174
Reader<? extends EsField> result = readers.get(name);
4275
if (result == null) {
4376
throw new IllegalArgumentException("Invalid EsField type [" + name + "]");
@@ -50,6 +83,8 @@ public static Writeable.Reader<? extends EsField> getReader(String name) {
5083
private final Map<String, EsField> properties;
5184
private final String name;
5285
private final boolean isAlias;
86+
// Because the subclasses all reimplement serialization, this needs to be writeable from subclass constructors
87+
protected TimeSeriesFieldType timeSeriesFieldType;
5388

5489
public EsField(String name, DataType esDataType, Map<String, EsField> properties, boolean aggregatable) {
5590
this(name, esDataType, properties, aggregatable, false);
@@ -61,6 +96,7 @@ public EsField(String name, DataType esDataType, Map<String, EsField> properties
6196
this.aggregatable = aggregatable;
6297
this.properties = properties;
6398
this.isAlias = isAlias;
99+
this.timeSeriesFieldType = TimeSeriesFieldType.UNKNOWN;
64100
}
65101

66102
public EsField(StreamInput in) throws IOException {
@@ -69,6 +105,11 @@ public EsField(StreamInput in) throws IOException {
69105
this.properties = in.readImmutableMap(EsField::readFrom);
70106
this.aggregatable = in.readBoolean();
71107
this.isAlias = in.readBoolean();
108+
if (in.getTransportVersion().onOrAfter(TransportVersions.ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE)) {
109+
this.timeSeriesFieldType = TimeSeriesFieldType.readFromStream(in);
110+
} else {
111+
this.timeSeriesFieldType = TimeSeriesFieldType.UNKNOWN;
112+
}
72113
}
73114

74115
private DataType readDataType(StreamInput in) throws IOException {
@@ -107,6 +148,9 @@ public void writeContent(StreamOutput out) throws IOException {
107148
out.writeMap(properties, (o, x) -> x.writeTo(out));
108149
out.writeBoolean(aggregatable);
109150
out.writeBoolean(isAlias);
151+
if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE)) {
152+
this.timeSeriesFieldType.writeTo(out);
153+
}
110154
}
111155

112156
/**

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/TextEsField.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.elasticsearch.xpack.esql.core.type;
88

9+
import org.elasticsearch.TransportVersions;
910
import org.elasticsearch.common.io.stream.StreamInput;
1011
import org.elasticsearch.common.io.stream.StreamOutput;
1112
import org.elasticsearch.core.Tuple;
@@ -35,6 +36,11 @@ public TextEsField(String name, Map<String, EsField> properties, boolean hasDocV
3536

3637
protected TextEsField(StreamInput in) throws IOException {
3738
this(readCachedStringWithVersionCheck(in), in.readImmutableMap(EsField::readFrom), in.readBoolean(), in.readBoolean());
39+
if (in.getTransportVersion().onOrAfter(TransportVersions.ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE)) {
40+
this.timeSeriesFieldType = TimeSeriesFieldType.readFromStream(in);
41+
} else {
42+
this.timeSeriesFieldType = TimeSeriesFieldType.UNKNOWN;
43+
}
3844
}
3945

4046
@Override
@@ -43,6 +49,9 @@ public void writeContent(StreamOutput out) throws IOException {
4349
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
4450
out.writeBoolean(isAggregatable());
4551
out.writeBoolean(isAlias());
52+
if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE)) {
53+
this.timeSeriesFieldType.writeTo(out);
54+
}
4655
}
4756

4857
public String getWriteableName() {

0 commit comments

Comments
 (0)