Skip to content

Commit b2e0272

Browse files
committed
Revert "[8.19] ESQL: Pushdown constructs doing case-insensitive regexes (elastic#128393) (elastic#128750) (elastic#128753) (elastic#128919)"
This reverts commit 34e08fb.
1 parent 4dd371d commit b2e0272

File tree

35 files changed

+239
-829
lines changed

35 files changed

+239
-829
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/compute/operator/EvalBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
import org.elasticsearch.xpack.esql.expression.function.scalar.math.RoundTo;
4646
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvMin;
4747
import org.elasticsearch.xpack.esql.expression.function.scalar.nulls.Coalesce;
48+
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
4849
import org.elasticsearch.xpack.esql.expression.function.scalar.string.ToLower;
4950
import org.elasticsearch.xpack.esql.expression.function.scalar.string.ToUpper;
50-
import org.elasticsearch.xpack.esql.expression.function.scalar.string.regex.RLike;
5151
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Add;
5252
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.Equals;
5353
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.LessThan;

docs/changelog/128393.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/changelog/128750.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ static TransportVersion def(int id) {
234234
public static final TransportVersion DATA_STREAM_OPTIONS_API_REMOVE_INCLUDE_DEFAULTS_8_19 = def(8_841_0_41);
235235
public static final TransportVersion JOIN_ON_ALIASES_8_19 = def(8_841_0_42);
236236
public static final TransportVersion ILM_ADD_SKIP_SETTING_8_19 = def(8_841_0_43);
237-
public static final TransportVersion ESQL_REGEX_MATCH_WITH_CASE_INSENSITIVITY_8_19 = def(8_841_0_44);
238237
/*
239238
* STOP! READ THIS FIRST! No, really,
240239
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public abstract class AbstractStringPattern implements StringPattern {
1616

1717
private Automaton automaton;
1818

19-
public abstract Automaton createAutomaton(boolean ignoreCase);
19+
public abstract Automaton createAutomaton();
2020

2121
private Automaton automaton() {
2222
if (automaton == null) {
23-
automaton = createAutomaton(false);
23+
automaton = createAutomaton();
2424
}
2525
return automaton;
2626
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
package org.elasticsearch.xpack.esql.core.expression.predicate.regex;
8+
9+
import org.elasticsearch.common.io.stream.StreamOutput;
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
13+
import java.io.IOException;
14+
15+
public abstract class RLike extends RegexMatch<RLikePattern> {
16+
17+
public RLike(Source source, Expression value, RLikePattern pattern) {
18+
super(source, value, pattern, false);
19+
}
20+
21+
public RLike(Source source, Expression field, RLikePattern rLikePattern, boolean caseInsensitive) {
22+
super(source, field, rLikePattern, caseInsensitive);
23+
}
24+
25+
@Override
26+
public void writeTo(StreamOutput out) throws IOException {
27+
throw new UnsupportedOperationException();
28+
}
29+
30+
@Override
31+
public String getWriteableName() {
32+
throw new UnsupportedOperationException();
33+
}
34+
35+
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.elasticsearch.xpack.esql.core.expression.predicate.regex;
88

99
import org.apache.lucene.util.automaton.Automaton;
10-
import org.apache.lucene.util.automaton.Operations;
1110
import org.apache.lucene.util.automaton.RegExp;
1211

1312
import java.util.Objects;
@@ -21,12 +20,8 @@ public RLikePattern(String regexpPattern) {
2120
}
2221

2322
@Override
24-
public Automaton createAutomaton(boolean ignoreCase) {
25-
int matchFlags = ignoreCase ? RegExp.ASCII_CASE_INSENSITIVE : 0;
26-
return Operations.determinize(
27-
new RegExp(regexpPattern, RegExp.ALL, matchFlags).toAutomaton(),
28-
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT
29-
);
23+
public Automaton createAutomaton() {
24+
return new RegExp(regexpPattern).toAutomaton();
3025
}
3126

3227
@Override
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
package org.elasticsearch.xpack.esql.core.expression.predicate.regex;
8+
9+
import org.elasticsearch.common.io.stream.StreamOutput;
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
13+
import java.io.IOException;
14+
15+
public abstract class WildcardLike extends RegexMatch<WildcardPattern> {
16+
17+
public WildcardLike(Source source, Expression left, WildcardPattern pattern) {
18+
this(source, left, pattern, false);
19+
}
20+
21+
public WildcardLike(Source source, Expression left, WildcardPattern pattern, boolean caseInsensitive) {
22+
super(source, left, pattern, caseInsensitive);
23+
}
24+
25+
@Override
26+
public void writeTo(StreamOutput out) throws IOException {
27+
throw new UnsupportedOperationException();
28+
}
29+
30+
@Override
31+
public String getWriteableName() {
32+
throw new UnsupportedOperationException();
33+
}
34+
35+
}

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
import org.apache.lucene.util.automaton.Automaton;
1212
import org.apache.lucene.util.automaton.MinimizationOperations;
1313
import org.apache.lucene.util.automaton.Operations;
14-
import org.apache.lucene.util.automaton.RegExp;
1514
import org.elasticsearch.xpack.esql.core.util.StringUtils;
1615

1716
import java.util.Objects;
1817

19-
import static org.elasticsearch.xpack.esql.core.util.StringUtils.luceneWildcardToRegExp;
20-
2118
/**
2219
* Similar to basic regex, supporting '?' wildcard for single character (same as regex ".")
2320
* and '*' wildcard for multiple characters (same as regex ".*")
@@ -41,16 +38,9 @@ public String pattern() {
4138
}
4239

4340
@Override
44-
public Automaton createAutomaton(boolean ignoreCase) {
45-
return ignoreCase
46-
? Operations.determinize(
47-
new RegExp(luceneWildcardToRegExp(wildcard), RegExp.ALL, RegExp.ASCII_CASE_INSENSITIVE).toAutomaton(),
48-
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT
49-
)
50-
: MinimizationOperations.minimize(
51-
WildcardQuery.toAutomaton(new Term(null, wildcard)),
52-
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT
53-
);
41+
public Automaton createAutomaton() {
42+
Automaton automaton = WildcardQuery.toAutomaton(new Term(null, wildcard));
43+
return MinimizationOperations.minimize(automaton, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
5444
}
5545

5646
@Override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/util/StringUtils.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.elasticsearch.xpack.esql.core.util;
88

99
import org.apache.lucene.document.InetAddressPoint;
10-
import org.apache.lucene.search.WildcardQuery;
1110
import org.apache.lucene.search.spell.LevenshteinDistance;
1211
import org.apache.lucene.util.BytesRef;
1312
import org.apache.lucene.util.CollectionUtil;
@@ -179,48 +178,6 @@ public static String wildcardToJavaPattern(String pattern, char escape) {
179178
return regex.toString();
180179
}
181180

182-
/**
183-
* Translates a Lucene wildcard pattern to a Lucene RegExp one.
184-
* Note: all RegExp "optional" characters are escaped too (allowing the use of the {@code RegExp.ALL} flag).
185-
* @param wildcard Lucene wildcard pattern
186-
* @return Lucene RegExp pattern
187-
*/
188-
public static String luceneWildcardToRegExp(String wildcard) {
189-
StringBuilder regex = new StringBuilder();
190-
191-
for (int i = 0, wcLen = wildcard.length(); i < wcLen; i++) {
192-
char c = wildcard.charAt(i); // this will work chunking through Unicode as long as all values matched are ASCII
193-
switch (c) {
194-
case WildcardQuery.WILDCARD_STRING -> regex.append(".*");
195-
case WildcardQuery.WILDCARD_CHAR -> regex.append(".");
196-
case WildcardQuery.WILDCARD_ESCAPE -> {
197-
if (i + 1 < wcLen) {
198-
// consume the wildcard escaping, consider the next char
199-
char next = wildcard.charAt(i + 1);
200-
i++;
201-
switch (next) {
202-
case WildcardQuery.WILDCARD_STRING, WildcardQuery.WILDCARD_CHAR, WildcardQuery.WILDCARD_ESCAPE ->
203-
// escape `*`, `.`, `\`, since these are special chars in RegExp as well
204-
regex.append("\\");
205-
// default: unnecessary escaping -- just ignore the escaping
206-
}
207-
regex.append(next);
208-
} else {
209-
// "else fallthru, lenient parsing with a trailing \" -- according to WildcardQuery#toAutomaton
210-
regex.append("\\\\");
211-
}
212-
}
213-
// reserved RegExp characters
214-
case '"', '$', '(', ')', '+', '.', '[', ']', '^', '{', '|', '}' -> regex.append("\\").append(c);
215-
// reserved optional RegExp characters
216-
case '#', '&', '<', '>' -> regex.append("\\").append(c);
217-
default -> regex.append(c);
218-
}
219-
}
220-
221-
return regex.toString();
222-
}
223-
224181
/**
225182
* Translates a like pattern to a Lucene wildcard.
226183
* This methods pays attention to the custom escape char which gets converted into \ (used by Lucene).

0 commit comments

Comments
 (0)