Skip to content

Commit b3f65ed

Browse files
Fix more failing UTs
1 parent f31bbf4 commit b3f65ed

File tree

1 file changed

+34
-3
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/regex

1 file changed

+34
-3
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/regex/WildcardLikeList.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
package org.elasticsearch.xpack.esql.expression.function.scalar.string.regex;
99

1010
import org.apache.lucene.util.automaton.Automaton;
11+
import org.elasticsearch.TransportVersions;
1112
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1213
import org.elasticsearch.common.io.stream.StreamInput;
1314
import org.elasticsearch.common.io.stream.StreamOutput;
15+
import org.elasticsearch.core.Nullable;
1416
import org.elasticsearch.xpack.esql.core.expression.Expression;
1517
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
1618
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardPattern;
@@ -35,7 +37,8 @@ public class WildcardLikeList extends RegexMatch<WildcardPatternList> {
3537
"WildcardLikeList",
3638
WildcardLikeList::new
3739
);
38-
private Configuration configuration;
40+
@Nullable
41+
private final Configuration configuration;
3942

4043
/**
4144
* The documentation for this function is in WildcardLike, and shown to the users `LIKE` in the docs.
@@ -66,7 +69,7 @@ public WildcardLikeList(StreamInput in) throws IOException {
6669
in.readNamedWriteable(Expression.class),
6770
new WildcardPatternList(in),
6871
deserializeCaseInsensitivity(in),
69-
Configuration.readFrom(in)
72+
readConfiguration(in)
7073
);
7174
}
7275

@@ -76,7 +79,32 @@ public void writeTo(StreamOutput out) throws IOException {
7679
out.writeNamedWriteable(field());
7780
pattern().writeTo(out);
7881
serializeCaseInsensitivity(out);
79-
configuration.writeTo(out);
82+
writeConfiguration(out);
83+
84+
}
85+
86+
static Configuration readConfiguration(StreamInput in) throws IOException {
87+
if (in.getTransportVersion().onOrAfter(TransportVersions.ESQL_FIXED_INDEX_LIKE)) {
88+
boolean hasConfiguration = in.readBoolean();
89+
if (hasConfiguration) {
90+
return Configuration.readFrom(in);
91+
} else {
92+
return null; // For backward compatibility, configuration is not serialized before this version
93+
}
94+
} else {
95+
return null; // For backward compatibility, configuration is not serialized before this version
96+
}
97+
}
98+
99+
void writeConfiguration(StreamOutput out) throws IOException {
100+
if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_FIXED_INDEX_LIKE)) {
101+
boolean hasConfiguration = configuration != null;
102+
out.writeBoolean(hasConfiguration);
103+
if (hasConfiguration) {
104+
configuration.writeTo(out);
105+
}
106+
}
107+
// else don't write configuration for backward compatibility
80108
}
81109

82110
@Override
@@ -138,6 +166,9 @@ public String getLuceneQueryDescription() {
138166
* Throws an {@link IllegalArgumentException} if the pattern list contains more than one pattern.
139167
*/
140168
private Query translateField(String targetFieldName) {
169+
if (configuration == null) {
170+
throw new IllegalArgumentException("Configuration cannot be null for WildcardLikeList translation");
171+
}
141172
return new ExpressionQuery(source(), targetFieldName, this, configuration);
142173
}
143174
}

0 commit comments

Comments
 (0)