Skip to content

Commit eb16853

Browse files
Address code review comments
1 parent db07c32 commit eb16853

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public Query asQuery(LucenePushdownPredicates pushdownPredicates, TranslatorHand
115115
* Pushes down string casing optimization for a single pattern using the provided predicate.
116116
* Returns a new RLike with case insensitivity or a Literal.FALSE if not matched.
117117
*/
118+
@Override
118119
public Expression optimizeStringCasingWithInsensitiveRegexMatch(Expression unwrappedField, Predicate<String> matchesCaseFn) {
119120
if (matchesCaseFn.test(pattern().pattern()) == false) {
120121
return Literal.of(this, Boolean.FALSE);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public org.apache.lucene.search.Query asLuceneQuery(
152152
* Pushes down string casing optimization by filtering patterns using the provided predicate.
153153
* Returns a new RegexMatch or a Literal.FALSE if none match.
154154
*/
155+
@Override
155156
public Expression optimizeStringCasingWithInsensitiveRegexMatch(Expression unwrappedField, Predicate<String> matchesCaseFn) {
156157
List<RLikePattern> filtered = pattern().patternList()
157158
.stream()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private Query translateField(String targetFieldName, boolean forceStringMatch) {
139139
* Pushes down string casing optimization for a single pattern using the provided predicate.
140140
* Returns a new WildcardLike with case insensitivity or a Literal.FALSE if not matched.
141141
*/
142+
@Override
142143
public Expression optimizeStringCasingWithInsensitiveRegexMatch(Expression unwrappedField, Predicate<String> matchesCaseFn) {
143144
if (matchesCaseFn.test(pattern().pattern()) == false) {
144145
return Literal.of(this, Boolean.FALSE);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private Query translateField(String targetFieldName) {
185185
* Pushes down string casing optimization by filtering patterns using the provided predicate.
186186
* Returns a new RegexMatch or a Literal.FALSE if none match.
187187
*/
188+
@Override
188189
public Expression optimizeStringCasingWithInsensitiveRegexMatch(Expression unwrappedField, Predicate<String> matchesCaseFn) {
189190
List<WildcardPattern> filtered = pattern().patternList()
190191
.stream()

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LocalLogicalPlanOptimizerTests.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,16 +781,16 @@ public void testReplaceUpperStringCasingWithInsensitiveLikeList() {
781781

782782
// same plan as above, but mixed case pattern and list of patterns
783783
public void testReplaceLowerStringCasingWithMixedCaseLikeList() {
784-
var plan = localPlan("FROM test | WHERE TO_LOWER(TO_UPPER(first_name)) RLIKE (\"TEST*\", \"valü*\", \"vaLü*\")");
784+
var plan = localPlan("FROM test | WHERE TO_LOWER(TO_UPPER(first_name)) LIKE (\"TEST*\", \"valü*\", \"vaLü*\")");
785785
var limit = as(plan, Limit.class);
786786
var filter = as(limit.child(), Filter.class);
787-
var rLikeList = as(filter.condition(), RLikeList.class);
788-
var field = as(rLikeList.field(), FieldAttribute.class);
787+
var likeList = as(filter.condition(), WildcardLikeList.class);
788+
var field = as(likeList.field(), FieldAttribute.class);
789789
assertThat(field.fieldName().string(), is("first_name"));
790790
// only the all lowercase pattern is kept, the mixed case and all uppercase patterns are ignored
791-
assertEquals(1, rLikeList.pattern().patternList().size());
792-
assertThat(rLikeList.pattern().patternList().get(0).pattern(), is("valü*"));
793-
assertThat(rLikeList.caseInsensitive(), is(true));
791+
assertEquals(1, likeList.pattern().patternList().size());
792+
assertThat(likeList.pattern().patternList().get(0).pattern(), is("valü*"));
793+
assertThat(likeList.caseInsensitive(), is(true));
794794
var source = as(filter.child(), EsRelation.class);
795795
}
796796

@@ -830,6 +830,17 @@ public void testReplaceStringCasingAndLikeListWithLocalRelation() {
830830
assertThat(local.supplier(), equalTo(EmptyLocalSupplier.EMPTY));
831831
}
832832

833+
/**
834+
* LocalRelation[[_meta_field{f}#9, emp_no{f}#3, first_name{f}#4, gender{f}#5, hire_date{f}#10, job{f}#11, job.raw{f}#12, langu
835+
* ages{f}#6, last_name{f}#7, long_noidx{f}#13, salary{f}#8],EMPTY]
836+
*/
837+
public void testReplaceStringCasingAndRLikeListWithLocalRelation() {
838+
var plan = localPlan("FROM test | WHERE TO_LOWER(TO_UPPER(first_name)) RLIKE (\"VALÜ*\", \"TEST*\")");
839+
840+
var local = as(plan, LocalRelation.class);
841+
assertThat(local.supplier(), equalTo(EmptyLocalSupplier.EMPTY));
842+
}
843+
833844
/**
834845
* Limit[1000[INTEGER],false]
835846
* \_Aggregate[[],[SUM($$integer_long_field$converted_to$long{f$}#5,true[BOOLEAN]) AS sum(integer_long_field::long)#3]]

0 commit comments

Comments
 (0)