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
}
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
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).

x-pack/plugin/esql-core/src/test/java/org/elasticsearch/xpack/esql/core/util/StringUtilsTests.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
import org.elasticsearch.test.ESTestCase;
1111

12-
import static org.elasticsearch.xpack.esql.core.util.StringUtils.luceneWildcardToRegExp;
1312
import static org.elasticsearch.xpack.esql.core.util.StringUtils.wildcardToJavaPattern;
14-
import static org.hamcrest.Matchers.is;
1513

1614
public class StringUtilsTests extends ESTestCase {
1715

@@ -57,24 +55,4 @@ public void testWildcard() {
5755
public void testEscapedEscape() {
5856
assertEquals("^\\\\\\\\$", wildcardToJavaPattern("\\\\\\\\", '\\'));
5957
}
60-
61-
public void testLuceneWildcardToRegExp() {
62-
assertThat(luceneWildcardToRegExp(""), is(""));
63-
assertThat(luceneWildcardToRegExp("*"), is(".*"));
64-
assertThat(luceneWildcardToRegExp("?"), is("."));
65-
assertThat(luceneWildcardToRegExp("\\\\"), is("\\\\"));
66-
assertThat(luceneWildcardToRegExp("foo?bar"), is("foo.bar"));
67-
assertThat(luceneWildcardToRegExp("foo*bar"), is("foo.*bar"));
68-
assertThat(luceneWildcardToRegExp("foo\\\\bar"), is("foo\\\\bar"));
69-
assertThat(luceneWildcardToRegExp("foo*bar?baz"), is("foo.*bar.baz"));
70-
assertThat(luceneWildcardToRegExp("foo\\*bar"), is("foo\\*bar"));
71-
assertThat(luceneWildcardToRegExp("foo\\?bar\\?"), is("foo\\?bar\\?"));
72-
assertThat(luceneWildcardToRegExp("foo\\?bar\\"), is("foo\\?bar\\\\"));
73-
// reserved characters
74-
assertThat(luceneWildcardToRegExp("\"[](){}^$.|+"), is("\\\"\\[\\]\\(\\)\\{\\}\\^\\$\\.\\|\\+"));
75-
// reserved "optional" characters
76-
assertThat(luceneWildcardToRegExp("#&<>"), is("\\#\\&\\<\\>"));
77-
assertThat(luceneWildcardToRegExp("foo\\\uD83D\uDC14bar"), is("foo\uD83D\uDC14bar"));
78-
assertThat(luceneWildcardToRegExp("foo\uD83D\uDC14bar"), is("foo\uD83D\uDC14bar"));
79-
}
8058
}

x-pack/plugin/esql-core/src/test/java/org/elasticsearch/xpack/esql/core/util/TestUtils.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.xpack.esql.core.type.DataType;
1414
import org.elasticsearch.xpack.esql.core.type.EsField;
1515

16-
import java.util.Locale;
1716
import java.util.regex.Pattern;
1817

1918
import static java.util.Collections.emptyMap;
@@ -62,15 +61,4 @@ public static FieldAttribute getFieldAttribute(String name, DataType dataType) {
6261
public static String stripThrough(String input) {
6362
return WS_PATTERN.matcher(input).replaceAll(StringUtils.EMPTY);
6463
}
65-
66-
/** Returns the input string, but with parts of it having the letter casing changed. */
67-
public static String randomCasing(String input) {
68-
StringBuilder sb = new StringBuilder(input.length());
69-
for (int i = 0, inputLen = input.length(), step = (int) Math.sqrt(inputLen), chunkEnd; i < inputLen; i += step) {
70-
chunkEnd = Math.min(i + step, inputLen);
71-
var chunk = input.substring(i, chunkEnd);
72-
sb.append(randomBoolean() ? chunk.toLowerCase(Locale.ROOT) : chunk.toUpperCase(Locale.ROOT));
73-
}
74-
return sb.toString();
75-
}
7664
}

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,36 +1367,7 @@ public void testAsyncGetWithoutContentType() throws IOException {
13671367
.item(matchesMap().entry("name", "integer").entry("type", "integer")),
13681368
values
13691369
);
1370-
}
13711370

1372-
public void testReplaceStringCasingWithInsensitiveWildcardMatch() throws IOException {
1373-
createIndex(testIndexName(), Settings.EMPTY, """
1374-
{
1375-
"properties": {
1376-
"reserved": {
1377-
"type": "keyword"
1378-
},
1379-
"optional": {
1380-
"type": "keyword"
1381-
}
1382-
}
1383-
}
1384-
""");
1385-
Request doc = new Request("POST", testIndexName() + "/_doc?refresh=true");
1386-
doc.setJsonEntity("""
1387-
{
1388-
"reserved": "_\\"_$_(_)_+_._[_]_^_{_|_}___",
1389-
"optional": "_#_&_<_>___"
1390-
}
1391-
""");
1392-
client().performRequest(doc);
1393-
var query = "FROM " + testIndexName() + """
1394-
| WHERE TO_LOWER(reserved) LIKE "_\\"_$_(_)_+_._[_]_^_{_|_}*"
1395-
| WHERE TO_LOWER(optional) LIKE "_#_&_<_>*"
1396-
| KEEP reserved, optional
1397-
""";
1398-
var answer = runEsql(requestObjectBuilder().query(query));
1399-
assertThat(answer.get("values"), equalTo(List.of(List.of("_\"_$_(_)_+_._[_]_^_{_|_}___", "_#_&_<_>___"))));
14001371
}
14011372

14021373
protected static Request prepareRequestWithOptions(RequestObjectBuilder requestObject, Mode mode) throws IOException {

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
import org.elasticsearch.xpack.esql.core.util.DateUtils;
6262
import org.elasticsearch.xpack.esql.core.util.StringUtils;
6363
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
64-
import org.elasticsearch.xpack.esql.expression.function.scalar.string.regex.RLike;
65-
import org.elasticsearch.xpack.esql.expression.function.scalar.string.regex.WildcardLike;
64+
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
65+
import org.elasticsearch.xpack.esql.expression.function.scalar.string.WildcardLike;
6666
import org.elasticsearch.xpack.esql.expression.predicate.Range;
6767
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.Equals;
6868
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.GreaterThan;

0 commit comments

Comments
 (0)