2626 */
2727public 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 /**
0 commit comments