Skip to content

Commit a9b9172

Browse files
ES|QL: Add support for cached strings in plan serialization (#112929)
1 parent bebcaf9 commit a9b9172

File tree

18 files changed

+163
-46
lines changed

18 files changed

+163
-46
lines changed

docs/changelog/112929.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 112929
2+
summary: "ES|QL: Add support for cached strings in plan serialization"
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static TransportVersion def(int id) {
239239
public static final TransportVersion TEXT_SIMILARITY_RERANKER_QUERY_REWRITE = def(8_763_00_0);
240240
public static final TransportVersion SIMULATE_INDEX_TEMPLATES_SUBSTITUTIONS = def(8_764_00_0);
241241
public static final TransportVersion RETRIEVERS_TELEMETRY_ADDED = def(8_765_00_0);
242+
public static final TransportVersion ESQL_CACHED_STRING_SERIALIZATION = def(8_766_00_0);
242243

243244
/*
244245
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/FieldAttribute.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private FieldAttribute(StreamInput in) throws IOException {
115115
this(
116116
Source.readFrom((StreamInput & PlanStreamInput) in),
117117
in.readOptionalWriteable(FieldAttribute::readFrom),
118-
in.readString(),
118+
((PlanStreamInput) in).readCachedString(),
119119
DataType.readFrom(in),
120120
EsField.readFrom(in),
121121
in.readOptionalString(),
@@ -130,7 +130,7 @@ public void writeTo(StreamOutput out) throws IOException {
130130
if (((PlanStreamOutput) out).writeAttributeCacheHeader(this)) {
131131
Source.EMPTY.writeTo(out);
132132
out.writeOptionalWriteable(parent);
133-
out.writeString(name());
133+
((PlanStreamOutput) out).writeCachedString(name());
134134
dataType().writeTo(out);
135135
field.writeTo(out);
136136
// We used to write the qualifier here. We can still do if needed in the future.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.elasticsearch.index.mapper.SourceFieldMapper;
1515
import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper;
1616
import org.elasticsearch.xpack.esql.core.plugin.EsqlCorePlugin;
17+
import org.elasticsearch.xpack.esql.core.util.PlanStreamInput;
18+
import org.elasticsearch.xpack.esql.core.util.PlanStreamOutput;
1719

1820
import java.io.IOException;
1921
import java.math.BigInteger;
@@ -519,12 +521,12 @@ public DataType counter() {
519521
}
520522

521523
public void writeTo(StreamOutput out) throws IOException {
522-
out.writeString(typeName);
524+
((PlanStreamOutput) out).writeCachedString(typeName);
523525
}
524526

525527
public static DataType readFrom(StreamInput in) throws IOException {
526528
// TODO: Use our normal enum serialization pattern
527-
return readFrom(in.readString());
529+
return readFrom(((PlanStreamInput) in).readCachedString());
528530
}
529531

530532
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import org.elasticsearch.common.io.stream.StreamInput;
1010
import org.elasticsearch.common.io.stream.StreamOutput;
11+
import org.elasticsearch.xpack.esql.core.util.PlanStreamInput;
12+
import org.elasticsearch.xpack.esql.core.util.PlanStreamOutput;
1113

1214
import java.io.IOException;
1315
import java.util.Map;
@@ -26,12 +28,12 @@ private DateEsField(String name, DataType dataType, Map<String, EsField> propert
2628
}
2729

2830
protected DateEsField(StreamInput in) throws IOException {
29-
this(in.readString(), DataType.DATETIME, in.readImmutableMap(EsField::readFrom), in.readBoolean());
31+
this(((PlanStreamInput) in).readCachedString(), DataType.DATETIME, in.readImmutableMap(EsField::readFrom), in.readBoolean());
3032
}
3133

3234
@Override
3335
public void writeContent(StreamOutput out) throws IOException {
34-
out.writeString(getName());
36+
((PlanStreamOutput) out).writeCachedString(getName());
3537
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
3638
out.writeBoolean(isAggregatable());
3739
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public EsField(String name, DataType esDataType, Map<String, EsField> properties
6060
}
6161

6262
public EsField(StreamInput in) throws IOException {
63-
this.name = in.readString();
63+
this.name = ((PlanStreamInput) in).readCachedString();
6464
this.esDataType = readDataType(in);
6565
this.properties = in.readImmutableMap(EsField::readFrom);
6666
this.aggregatable = in.readBoolean();
6767
this.isAlias = in.readBoolean();
6868
}
6969

7070
private DataType readDataType(StreamInput in) throws IOException {
71-
String name = in.readString();
71+
String name = ((PlanStreamInput) in).readCachedString();
7272
if (in.getTransportVersion().before(TransportVersions.ESQL_NESTED_UNSUPPORTED) && name.equalsIgnoreCase("NESTED")) {
7373
/*
7474
* The "nested" data type existed in older versions of ESQL but was
@@ -98,7 +98,7 @@ public void writeTo(StreamOutput out) throws IOException {
9898
* This needs to be overridden by subclasses for specific serialization
9999
*/
100100
public void writeContent(StreamOutput out) throws IOException {
101-
out.writeString(name);
101+
((PlanStreamOutput) out).writeCachedString(name);
102102
esDataType.writeTo(out);
103103
out.writeMap(properties, (o, x) -> x.writeTo(out));
104104
out.writeBoolean(aggregatable);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.elasticsearch.common.io.stream.StreamInput;
1111
import org.elasticsearch.common.io.stream.StreamOutput;
1212
import org.elasticsearch.xpack.esql.core.QlIllegalArgumentException;
13+
import org.elasticsearch.xpack.esql.core.util.PlanStreamInput;
14+
import org.elasticsearch.xpack.esql.core.util.PlanStreamOutput;
1315

1416
import java.io.IOException;
1517
import java.util.Map;
@@ -52,7 +54,7 @@ private InvalidMappedField(String name, String errorMessage, Map<String, EsField
5254
}
5355

5456
protected InvalidMappedField(StreamInput in) throws IOException {
55-
this(in.readString(), in.readString(), in.readImmutableMap(StreamInput::readString, EsField::readFrom));
57+
this(((PlanStreamInput) in).readCachedString(), in.readString(), in.readImmutableMap(StreamInput::readString, EsField::readFrom));
5658
}
5759

5860
public Set<DataType> types() {
@@ -61,7 +63,7 @@ public Set<DataType> types() {
6163

6264
@Override
6365
public void writeContent(StreamOutput out) throws IOException {
64-
out.writeString(getName());
66+
((PlanStreamOutput) out).writeCachedString(getName());
6567
out.writeString(errorMessage);
6668
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
6769
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import org.elasticsearch.common.io.stream.StreamInput;
1010
import org.elasticsearch.common.io.stream.StreamOutput;
11+
import org.elasticsearch.xpack.esql.core.util.PlanStreamInput;
12+
import org.elasticsearch.xpack.esql.core.util.PlanStreamOutput;
1113

1214
import java.io.IOException;
1315
import java.util.Collections;
@@ -59,7 +61,7 @@ protected KeywordEsField(
5961

6062
public KeywordEsField(StreamInput in) throws IOException {
6163
this(
62-
in.readString(),
64+
((PlanStreamInput) in).readCachedString(),
6365
KEYWORD,
6466
in.readImmutableMap(EsField::readFrom),
6567
in.readBoolean(),
@@ -71,7 +73,7 @@ public KeywordEsField(StreamInput in) throws IOException {
7173

7274
@Override
7375
public void writeContent(StreamOutput out) throws IOException {
74-
out.writeString(getName());
76+
((PlanStreamOutput) out).writeCachedString(getName());
7577
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
7678
out.writeBoolean(isAggregatable());
7779
out.writeInt(precision);

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.elasticsearch.common.io.stream.StreamInput;
1111
import org.elasticsearch.common.io.stream.StreamOutput;
1212
import org.elasticsearch.xpack.esql.core.expression.Expression;
13+
import org.elasticsearch.xpack.esql.core.util.PlanStreamInput;
14+
import org.elasticsearch.xpack.esql.core.util.PlanStreamOutput;
1315

1416
import java.io.IOException;
1517
import java.util.HashMap;
@@ -36,13 +38,18 @@ public MultiTypeEsField(String name, DataType dataType, boolean aggregatable, Ma
3638
}
3739

3840
protected MultiTypeEsField(StreamInput in) throws IOException {
39-
this(in.readString(), DataType.readFrom(in), in.readBoolean(), in.readImmutableMap(i -> i.readNamedWriteable(Expression.class)));
41+
this(
42+
((PlanStreamInput) in).readCachedString(),
43+
DataType.readFrom(in),
44+
in.readBoolean(),
45+
in.readImmutableMap(i -> i.readNamedWriteable(Expression.class))
46+
);
4047
}
4148

4249
@Override
4350
public void writeContent(StreamOutput out) throws IOException {
44-
out.writeString(getName());
45-
out.writeString(getDataType().typeName());
51+
((PlanStreamOutput) out).writeCachedString(getName());
52+
getDataType().writeTo(out);
4653
out.writeBoolean(isAggregatable());
4754
out.writeMap(getIndexToConversionExpressions(), (o, v) -> out.writeNamedWriteable(v));
4855
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.elasticsearch.common.io.stream.StreamOutput;
1111
import org.elasticsearch.core.Tuple;
1212
import org.elasticsearch.xpack.esql.core.QlIllegalArgumentException;
13+
import org.elasticsearch.xpack.esql.core.util.PlanStreamInput;
14+
import org.elasticsearch.xpack.esql.core.util.PlanStreamOutput;
1315

1416
import java.io.IOException;
1517
import java.util.Map;
@@ -32,12 +34,12 @@ public TextEsField(String name, Map<String, EsField> properties, boolean hasDocV
3234
}
3335

3436
protected TextEsField(StreamInput in) throws IOException {
35-
this(in.readString(), in.readImmutableMap(EsField::readFrom), in.readBoolean(), in.readBoolean());
37+
this(((PlanStreamInput) in).readCachedString(), in.readImmutableMap(EsField::readFrom), in.readBoolean(), in.readBoolean());
3638
}
3739

3840
@Override
3941
public void writeContent(StreamOutput out) throws IOException {
40-
out.writeString(getName());
42+
((PlanStreamOutput) out).writeCachedString(getName());
4143
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
4244
out.writeBoolean(isAggregatable());
4345
out.writeBoolean(isAlias());

0 commit comments

Comments
 (0)