Skip to content

Commit

Permalink
ES|QL: Fix ResolvedEnrichPolicy serialization (bwc) in v 8.15 (elasti…
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila authored Sep 17, 2024
1 parent 3deca9e commit 5d8a04b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/112985.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 112985
summary: "ES|QL: Fix `ResolvedEnrichPolicy` serialization (bwc) in v 8.15"
area: ES|QL
type: bug
issues:
- 112968
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected DateEsField(StreamInput in) throws IOException {
}

@Override
protected void writeContent(StreamOutput out) throws IOException {
public void writeContent(StreamOutput out) throws IOException {
out.writeString(getName());
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
out.writeBoolean(isAggregatable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public EsField(String name, DataType esDataType, Map<String, EsField> properties
this.isAlias = isAlias;
}

protected EsField(StreamInput in) throws IOException {
public EsField(StreamInput in) throws IOException {
this.name = in.readString();
this.esDataType = DataType.readFrom(in);
this.properties = in.readImmutableMap(EsField::readFrom);
Expand All @@ -80,7 +80,7 @@ public void writeTo(StreamOutput out) throws IOException {
/**
* This needs to be overridden by subclasses for specific serialization
*/
protected void writeContent(StreamOutput out) throws IOException {
public void writeContent(StreamOutput out) throws IOException {
out.writeString(name);
out.writeString(esDataType.typeName());
out.writeMap(properties, (o, x) -> x.writeTo(out));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Set<DataType> types() {
}

@Override
protected void writeContent(StreamOutput out) throws IOException {
public void writeContent(StreamOutput out) throws IOException {
out.writeString(getName());
out.writeString(errorMessage);
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public KeywordEsField(StreamInput in) throws IOException {
}

@Override
protected void writeContent(StreamOutput out) throws IOException {
public void writeContent(StreamOutput out) throws IOException {
out.writeString(getName());
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
out.writeBoolean(isAggregatable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected TextEsField(StreamInput in) throws IOException {
}

@Override
protected void writeContent(StreamOutput out) throws IOException {
public void writeContent(StreamOutput out) throws IOException {
out.writeString(getName());
out.writeMap(getProperties(), (o, x) -> x.writeTo(out));
out.writeBoolean(isAggregatable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package org.elasticsearch.xpack.esql.enrich;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
Expand All @@ -29,10 +30,17 @@ public ResolvedEnrichPolicy(StreamInput in) throws IOException {
in.readString(),
in.readStringCollectionAsList(),
in.readMap(StreamInput::readString),
in.readMap(EsField::readFrom)
in.readMap(getEsFieldReader(in))
);
}

private static Reader<EsField> getEsFieldReader(StreamInput in) {
if (in.getTransportVersion().isPatchFrom(TransportVersions.ESQL_ATTRIBUTE_CACHED_SERIALIZATION_8_15)) {
return EsField::readFrom;
}
return EsField::new;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(matchField);
Expand All @@ -45,7 +53,13 @@ public void writeTo(StreamOutput out) throws IOException {
* There are lots of subtypes of ESField, but we always write the field
* as though it were the base class.
*/
(o, v) -> new EsField(v.getName(), v.getDataType(), v.getProperties(), v.isAggregatable(), v.isAlias()).writeTo(o)
(o, v) -> {
if (out.getTransportVersion().isPatchFrom(TransportVersions.ESQL_ATTRIBUTE_CACHED_SERIALIZATION_8_15)) {
new EsField(v.getName(), v.getDataType(), v.getProperties(), v.isAggregatable(), v.isAlias()).writeTo(o);
} else {
new EsField(v.getName(), v.getDataType(), v.getProperties(), v.isAggregatable(), v.isAlias()).writeContent(o);
}
}
);
}
}

0 comments on commit 5d8a04b

Please sign in to comment.