Skip to content

Commit 5d8a04b

Browse files
ES|QL: Fix ResolvedEnrichPolicy serialization (bwc) in v 8.15 (#112985)
1 parent 3deca9e commit 5d8a04b

File tree

7 files changed

+28
-8
lines changed

7 files changed

+28
-8
lines changed

docs/changelog/112985.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 112985
2+
summary: "ES|QL: Fix `ResolvedEnrichPolicy` serialization (bwc) in v 8.15"
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 112968

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected DateEsField(StreamInput in) throws IOException {
3030
}
3131

3232
@Override
33-
protected void writeContent(StreamOutput out) throws IOException {
33+
public void writeContent(StreamOutput out) throws IOException {
3434
out.writeString(getName());
3535
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
3636
out.writeBoolean(isAggregatable());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public EsField(String name, DataType esDataType, Map<String, EsField> properties
5858
this.isAlias = isAlias;
5959
}
6060

61-
protected EsField(StreamInput in) throws IOException {
61+
public EsField(StreamInput in) throws IOException {
6262
this.name = in.readString();
6363
this.esDataType = DataType.readFrom(in);
6464
this.properties = in.readImmutableMap(EsField::readFrom);
@@ -80,7 +80,7 @@ public void writeTo(StreamOutput out) throws IOException {
8080
/**
8181
* This needs to be overridden by subclasses for specific serialization
8282
*/
83-
protected void writeContent(StreamOutput out) throws IOException {
83+
public void writeContent(StreamOutput out) throws IOException {
8484
out.writeString(name);
8585
out.writeString(esDataType.typeName());
8686
out.writeMap(properties, (o, x) -> x.writeTo(out));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Set<DataType> types() {
6060
}
6161

6262
@Override
63-
protected void writeContent(StreamOutput out) throws IOException {
63+
public void writeContent(StreamOutput out) throws IOException {
6464
out.writeString(getName());
6565
out.writeString(errorMessage);
6666
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public KeywordEsField(StreamInput in) throws IOException {
7070
}
7171

7272
@Override
73-
protected void writeContent(StreamOutput out) throws IOException {
73+
public void writeContent(StreamOutput out) throws IOException {
7474
out.writeString(getName());
7575
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
7676
out.writeBoolean(isAggregatable());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected TextEsField(StreamInput in) throws IOException {
3636
}
3737

3838
@Override
39-
protected void writeContent(StreamOutput out) throws IOException {
39+
public void writeContent(StreamOutput out) throws IOException {
4040
out.writeString(getName());
4141
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
4242
out.writeBoolean(isAggregatable());

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/ResolvedEnrichPolicy.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.esql.enrich;
99

10+
import org.elasticsearch.TransportVersions;
1011
import org.elasticsearch.common.io.stream.StreamInput;
1112
import org.elasticsearch.common.io.stream.StreamOutput;
1213
import org.elasticsearch.common.io.stream.Writeable;
@@ -29,10 +30,17 @@ public ResolvedEnrichPolicy(StreamInput in) throws IOException {
2930
in.readString(),
3031
in.readStringCollectionAsList(),
3132
in.readMap(StreamInput::readString),
32-
in.readMap(EsField::readFrom)
33+
in.readMap(getEsFieldReader(in))
3334
);
3435
}
3536

37+
private static Reader<EsField> getEsFieldReader(StreamInput in) {
38+
if (in.getTransportVersion().isPatchFrom(TransportVersions.ESQL_ATTRIBUTE_CACHED_SERIALIZATION_8_15)) {
39+
return EsField::readFrom;
40+
}
41+
return EsField::new;
42+
}
43+
3644
@Override
3745
public void writeTo(StreamOutput out) throws IOException {
3846
out.writeString(matchField);
@@ -45,7 +53,13 @@ public void writeTo(StreamOutput out) throws IOException {
4553
* There are lots of subtypes of ESField, but we always write the field
4654
* as though it were the base class.
4755
*/
48-
(o, v) -> new EsField(v.getName(), v.getDataType(), v.getProperties(), v.isAggregatable(), v.isAlias()).writeTo(o)
56+
(o, v) -> {
57+
if (out.getTransportVersion().isPatchFrom(TransportVersions.ESQL_ATTRIBUTE_CACHED_SERIALIZATION_8_15)) {
58+
new EsField(v.getName(), v.getDataType(), v.getProperties(), v.isAggregatable(), v.isAlias()).writeTo(o);
59+
} else {
60+
new EsField(v.getName(), v.getDataType(), v.getProperties(), v.isAggregatable(), v.isAlias()).writeContent(o);
61+
}
62+
}
4963
);
5064
}
5165
}

0 commit comments

Comments
 (0)