Skip to content

Commit a0bc3c6

Browse files
committed
Remove isOperator as a field provided at construction time, and derive it from source instead to avoid serialization
1 parent 35e8d95 commit a0bc3c6

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ static TransportVersion def(int id) {
187187
public static final TransportVersion QUERY_RULES_RETRIEVER = def(8_782_00_0);
188188
public static final TransportVersion ESQL_CCS_EXEC_INFO_WITH_FAILURES = def(8_783_00_0);
189189
public static final TransportVersion LOGSDB_TELEMETRY = def(8_784_00_0);
190-
public static final TransportVersion MATCH_OPERATOR_COLON = def(8_785_00_0);
191190

192191
/*
193192
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java

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

88
package org.elasticsearch.xpack.esql.expression.function.fulltext;
99

10-
import org.elasticsearch.TransportVersions;
1110
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1211
import org.elasticsearch.common.io.stream.StreamInput;
1312
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -27,6 +26,7 @@
2726

2827
import java.io.IOException;
2928
import java.util.List;
29+
import java.util.Locale;
3030

3131
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
3232
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
@@ -41,7 +41,8 @@ public class Match extends FullTextFunction implements Validatable {
4141
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Match", Match::readFrom);
4242

4343
private final Expression field;
44-
private final boolean isOperator;
44+
45+
private transient Boolean isOperator;
4546

4647
@FunctionInfo(
4748
returnType = "boolean",
@@ -58,40 +59,22 @@ public Match(
5859
description = "Text you wish to find in the provided field."
5960
) Expression matchQuery
6061
) {
61-
this(source, field, matchQuery, false);
62-
}
63-
64-
private Match(Source source, Expression field, Expression matchQuery, boolean isOperator) {
6562
super(source, matchQuery, List.of(field, matchQuery));
6663
this.field = field;
67-
this.isOperator = isOperator;
68-
}
69-
70-
public static Match operator(Source source, Expression field, Expression matchQuery) {
71-
return new Match(source, field, matchQuery, true);
7264
}
7365

7466
private static Match readFrom(StreamInput in) throws IOException {
7567
Source source = Source.readFrom((PlanStreamInput) in);
7668
Expression field = in.readNamedWriteable(Expression.class);
7769
Expression query = in.readNamedWriteable(Expression.class);
78-
boolean isOperator = false;
79-
Expression boost = null;
80-
Expression fuzziness = null;
81-
if (in.getTransportVersion().onOrAfter(TransportVersions.MATCH_OPERATOR_COLON)) {
82-
isOperator = in.readBoolean();
83-
}
84-
return new Match(source, field, query, isOperator);
70+
return new Match(source, field, query);
8571
}
8672

8773
@Override
8874
public void writeTo(StreamOutput out) throws IOException {
8975
source().writeTo(out);
9076
out.writeNamedWriteable(field());
9177
out.writeNamedWriteable(query());
92-
if (out.getTransportVersion().onOrAfter(TransportVersions.MATCH_OPERATOR_COLON)) {
93-
out.writeBoolean(isOperator);
94-
}
9578
}
9679

9780
@Override
@@ -121,7 +104,7 @@ public void validate(Failures failures) {
121104

122105
@Override
123106
public Expression replaceChildren(List<Expression> newChildren) {
124-
return new Match(source(), newChildren.get(0), newChildren.get(1), isOperator);
107+
return new Match(source(), newChildren.get(0), newChildren.get(1));
125108
}
126109

127110
@Override
@@ -139,11 +122,18 @@ public Expression field() {
139122

140123
@Override
141124
public String functionType() {
142-
return isOperator ? "operator" : super.functionType();
125+
return isOperator() ? "operator" : super.functionType();
143126
}
144127

145128
@Override
146129
public String functionName() {
147-
return isOperator ? ":" : super.functionName();
130+
return isOperator() ? ":" : super.functionName();
131+
}
132+
133+
private boolean isOperator() {
134+
if (isOperator == null) {
135+
isOperator = source().text().toUpperCase(Locale.ROOT).startsWith(super.functionName()) == false;
136+
}
137+
return isOperator;
148138
}
149139
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,6 @@ String unresolvedAttributeNameInParam(ParserRuleContext ctx, Expression param) {
923923

924924
@Override
925925
public Expression visitMatchBooleanExpression(EsqlBaseParser.MatchBooleanExpressionContext ctx) {
926-
return Match.operator(source(ctx), expression(ctx.fieldExp), expression(ctx.queryString));
926+
return new Match(source(ctx), expression(ctx.fieldExp), expression(ctx.queryString));
927927
}
928928
}

0 commit comments

Comments
 (0)