Skip to content

Commit

Permalink
Remove isOperator as a field provided at construction time, and deriv…
Browse files Browse the repository at this point in the history
…e it from source instead to avoid serialization
  • Loading branch information
carlosdelest committed Nov 4, 2024
1 parent 35e8d95 commit a0bc3c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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",
Expand All @@ -58,40 +59,22 @@ 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
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
Expand Down Expand Up @@ -121,7 +104,7 @@ public void validate(Failures failures) {

@Override
public Expression replaceChildren(List<Expression> newChildren) {
return new Match(source(), newChildren.get(0), newChildren.get(1), isOperator);
return new Match(source(), newChildren.get(0), newChildren.get(1));
}

@Override
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit a0bc3c6

Please sign in to comment.