From a0bc3c62cc38e608d056954d4d4d16ac6e5c2475 Mon Sep 17 00:00:00 2001 From: carlosdelest Date: Mon, 4 Nov 2024 17:13:32 +0100 Subject: [PATCH] Remove isOperator as a field provided at construction time, and derive it from source instead to avoid serialization --- .../org/elasticsearch/TransportVersions.java | 1 - .../expression/function/fulltext/Match.java | 38 +++++++------------ .../xpack/esql/parser/ExpressionBuilder.java | 2 +- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index 838e587df267c..2acf80e426c82 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -187,7 +187,6 @@ static TransportVersion def(int id) { public static final TransportVersion QUERY_RULES_RETRIEVER = def(8_782_00_0); public static final TransportVersion ESQL_CCS_EXEC_INFO_WITH_FAILURES = def(8_783_00_0); public static final TransportVersion LOGSDB_TELEMETRY = def(8_784_00_0); - public static final TransportVersion MATCH_OPERATOR_COLON = def(8_785_00_0); /* * STOP! READ THIS FIRST! No, really, diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java index 61bdcd76e185c..b17fc74e4236e 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.esql.expression.function.fulltext; -import org.elasticsearch.TransportVersions; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -27,6 +26,7 @@ import java.io.IOException; import java.util.List; +import java.util.Locale; import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST; import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND; @@ -41,7 +41,8 @@ public class Match extends FullTextFunction implements Validatable { public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Match", Match::readFrom); private final Expression field; - private final boolean isOperator; + + private transient Boolean isOperator; @FunctionInfo( returnType = "boolean", @@ -58,30 +59,15 @@ public Match( description = "Text you wish to find in the provided field." ) Expression matchQuery ) { - this(source, field, matchQuery, false); - } - - private Match(Source source, Expression field, Expression matchQuery, boolean isOperator) { super(source, matchQuery, List.of(field, matchQuery)); this.field = field; - this.isOperator = isOperator; - } - - public static Match operator(Source source, Expression field, Expression matchQuery) { - return new Match(source, field, matchQuery, true); } private static Match readFrom(StreamInput in) throws IOException { Source source = Source.readFrom((PlanStreamInput) in); Expression field = in.readNamedWriteable(Expression.class); Expression query = in.readNamedWriteable(Expression.class); - boolean isOperator = false; - Expression boost = null; - Expression fuzziness = null; - if (in.getTransportVersion().onOrAfter(TransportVersions.MATCH_OPERATOR_COLON)) { - isOperator = in.readBoolean(); - } - return new Match(source, field, query, isOperator); + return new Match(source, field, query); } @Override @@ -89,9 +75,6 @@ public void writeTo(StreamOutput out) throws IOException { source().writeTo(out); out.writeNamedWriteable(field()); out.writeNamedWriteable(query()); - if (out.getTransportVersion().onOrAfter(TransportVersions.MATCH_OPERATOR_COLON)) { - out.writeBoolean(isOperator); - } } @Override @@ -121,7 +104,7 @@ public void validate(Failures failures) { @Override public Expression replaceChildren(List newChildren) { - return new Match(source(), newChildren.get(0), newChildren.get(1), isOperator); + return new Match(source(), newChildren.get(0), newChildren.get(1)); } @Override @@ -139,11 +122,18 @@ public Expression field() { @Override public String functionType() { - return isOperator ? "operator" : super.functionType(); + return isOperator() ? "operator" : super.functionType(); } @Override public String functionName() { - return isOperator ? ":" : super.functionName(); + return isOperator() ? ":" : super.functionName(); + } + + private boolean isOperator() { + if (isOperator == null) { + isOperator = source().text().toUpperCase(Locale.ROOT).startsWith(super.functionName()) == false; + } + return isOperator; } } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java index 7d48ea692dab6..2c9090fe44190 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ExpressionBuilder.java @@ -923,6 +923,6 @@ String unresolvedAttributeNameInParam(ParserRuleContext ctx, Expression param) { @Override public Expression visitMatchBooleanExpression(EsqlBaseParser.MatchBooleanExpressionContext ctx) { - return Match.operator(source(ctx), expression(ctx.fieldExp), expression(ctx.queryString)); + return new Match(source(ctx), expression(ctx.fieldExp), expression(ctx.queryString)); } }