Skip to content

Commit 78eb25f

Browse files
Address code review feedback
1 parent 59095ff commit 78eb25f

File tree

7 files changed

+36
-24
lines changed

7 files changed

+36
-24
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/WildcardPattern.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.lucene.util.automaton.RegExp;
1414
import org.elasticsearch.common.io.stream.StreamInput;
1515
import org.elasticsearch.common.io.stream.StreamOutput;
16+
import org.elasticsearch.common.io.stream.Writeable;
1617
import org.elasticsearch.xpack.esql.core.util.StringUtils;
1718

1819
import java.io.IOException;
@@ -27,7 +28,7 @@
2728
* Allows escaping based on a regular char
2829
*
2930
*/
30-
public class WildcardPattern extends AbstractStringPattern {
31+
public class WildcardPattern extends AbstractStringPattern implements Writeable {
3132

3233
private final String wildcard;
3334
private final String regex;
@@ -42,6 +43,11 @@ public WildcardPattern(StreamInput in) throws IOException {
4243
this(in.readString());
4344
}
4445

46+
@Override
47+
public void writeTo(StreamOutput out) throws IOException {
48+
out.writeString(wildcard);
49+
}
50+
4551
public String pattern() {
4652
return wildcard;
4753
}
@@ -95,11 +101,4 @@ public boolean equals(Object obj) {
95101
return Objects.equals(wildcard, other.wildcard);
96102
}
97103

98-
public void writeTo(StreamOutput out) throws IOException {
99-
out.writeString(wildcard);
100-
}
101-
102-
public static WildcardPattern readFrom(StreamInput out) throws IOException {
103-
return new WildcardPattern(out);
104-
}
105104
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/predicate/regex/WildcardPatternList.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import org.apache.lucene.util.automaton.Automaton;
1010
import org.apache.lucene.util.automaton.Operations;
11-
import org.elasticsearch.common.io.stream.NamedWriteable;
1211
import org.elasticsearch.common.io.stream.StreamInput;
1312
import org.elasticsearch.common.io.stream.StreamOutput;
13+
import org.elasticsearch.common.io.stream.Writeable;
1414

1515
import java.io.IOException;
1616
import java.util.List;
@@ -27,8 +27,7 @@
2727
* Allows escaping based on a regular char
2828
*
2929
*/
30-
public class WildcardPatternList extends AbstractStringPattern implements NamedWriteable {
31-
public static final Entry ENTRY = new Entry(WildcardPatternList.class, "WildcardPatternList", WildcardPatternList::new);
30+
public class WildcardPatternList extends AbstractStringPattern implements Writeable {
3231
public static final String NAME = "WildcardPatternList";
3332
private final List<WildcardPattern> patternList;
3433

@@ -45,13 +44,8 @@ public void writeTo(StreamOutput out) throws IOException {
4544
out.writeCollection(patternList, (o, pattern) -> pattern.writeTo(o));
4645
}
4746

48-
@Override
49-
public String getWriteableName() {
50-
return NAME;
51-
}
52-
5347
public static WildcardPatternList readFrom(StreamInput in) throws IOException {
54-
return new WildcardPatternList(in.readCollectionAsList(WildcardPattern::readFrom));
48+
return new WildcardPatternList(in);
5549
}
5650

5751
public List<WildcardPattern> patternList() {

x-pack/plugin/esql/qa/testFixtures/src/main/resources/where-like.csv-spec

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,24 @@ emp_no:integer | first_name:keyword
453453
10099 | Valter
454454
;
455455

456+
likeListWithUpperTurnedInsensitive
457+
required_capability: like_with_list_of_patterns
458+
FROM employees | WHERE TO_UPPER(first_name) LIKE ("GEOR*") | keep emp_no, first_name | sort emp_no;
459+
460+
emp_no:integer | first_name:keyword
461+
10001 | Georgi
462+
10055 | Georgy
463+
;
464+
465+
likeListWithUpperTurnedInsensitiveMult
466+
required_capability: like_with_list_of_patterns
467+
FROM employees | WHERE TO_UPPER(first_name) LIKE ("GEOR*", "WE*") | keep emp_no, first_name | sort emp_no;
468+
469+
emp_no:integer | first_name:keyword
470+
10001 | Georgi
471+
10040 | Weiyi
472+
10055 | Georgy
473+
;
456474

457475
likeAll
458476
from employees | where first_name like "*" and emp_no > 10028 | sort emp_no | keep emp_no, first_name | limit 2;

x-pack/plugin/esql/src/main/antlr/parser/Expression.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ booleanExpression
1919

2020
regexBooleanExpression
2121
: valueExpression (NOT)? LIKE string #likeExpression
22-
| valueExpression (NOT)? RLIKE string #rlikeExpression
23-
| valueExpression (NOT)? LIKE LP string (COMMA string )* RP #likeListExpression
22+
| valueExpression (NOT)? RLIKE string #rlikeExpression
23+
| valueExpression (NOT)? LIKE LP string (COMMA string )* RP #likeListExpression
2424
;
2525

2626
matchBooleanExpression

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ private static FunctionDefinition[][] functions() {
418418
// IP
419419
new FunctionDefinition[] { def(CIDRMatch.class, CIDRMatch::new, "cidr_match") },
420420
new FunctionDefinition[] { def(IpPrefix.class, IpPrefix::new, "ip_prefix") },
421-
// likelist
422-
// new FunctionDefinition[] { def(WildcardLikeList.class, WildcardLikeList::new, "like_list") },
423-
424421
// conversion functions
425422
new FunctionDefinition[] {
426423
def(FromBase64.class, FromBase64::new, "from_base64"),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class WildcardLikeList extends RegexMatch<WildcardPatternList> {
3030
"WildcardLikeList",
3131
WildcardLikeList::new
3232
);
33-
public static final String NAME = "LIKELIST";
3433

3534
/**
3635
* The documentation for this function is in WildcardLike, and shown to the users `LIKE` in the docs.
@@ -66,7 +65,7 @@ public void writeTo(StreamOutput out) throws IOException {
6665

6766
@Override
6867
public String name() {
69-
return NAME;
68+
return ENTRY.name;
7069
}
7170

7271
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceStringCasingWithInsensitiveRegexMatch.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.xpack.esql.core.expression.Literal;
1212
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RegexMatch;
1313
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.StringPattern;
14+
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardPatternList;
1415
import org.elasticsearch.xpack.esql.expression.function.scalar.string.ChangeCase;
1516
import org.elasticsearch.xpack.esql.expression.function.scalar.string.regex.RLike;
1617
import org.elasticsearch.xpack.esql.expression.function.scalar.string.regex.WildcardLike;
@@ -28,6 +29,10 @@ public ReplaceStringCasingWithInsensitiveRegexMatch() {
2829
@Override
2930
protected Expression rule(RegexMatch<? extends StringPattern> regexMatch, LogicalOptimizerContext unused) {
3031
Expression e = regexMatch;
32+
if(regexMatch.pattern() instanceof WildcardPatternList) {
33+
// This optimization is not supported for WildcardPatternList for now
34+
return e;
35+
}
3136
if (regexMatch.field() instanceof ChangeCase changeCase) {
3237
var pattern = regexMatch.pattern().pattern();
3338
e = changeCase.caseType().matchesCase(pattern) ? insensitiveRegexMatch(regexMatch) : Literal.of(regexMatch, Boolean.FALSE);

0 commit comments

Comments
 (0)