77
88package org .elasticsearch .xpack .esql .expression .function .fulltext ;
99
10- import org .elasticsearch .TransportVersions ;
1110import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
1211import org .elasticsearch .common .io .stream .StreamInput ;
1312import org .elasticsearch .common .io .stream .StreamOutput ;
2726
2827import java .io .IOException ;
2928import java .util .List ;
29+ import java .util .Locale ;
3030
3131import static org .elasticsearch .xpack .esql .core .expression .TypeResolutions .ParamOrdinal .FIRST ;
3232import 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}
0 commit comments