Skip to content

Commit

Permalink
Refactoring, cleanup and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed Dec 11, 2024
1 parent 7faa1d7 commit dd9df2e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;

import java.io.IOException;

public class RLike extends RegexMatch<RLikePattern> {
public abstract class RLike extends RegexMatch<RLikePattern> {

public RLike(Source source, Expression value, RLikePattern pattern) {
super(source, value, pattern, false);
Expand All @@ -33,13 +32,4 @@ public String getWriteableName() {
throw new UnsupportedOperationException();
}

@Override
protected NodeInfo<RLike> info() {
return NodeInfo.create(this, RLike::new, field(), pattern(), caseInsensitive());
}

@Override
protected RLike replaceChild(Expression newChild) {
return new RLike(source(), newChild, pattern(), caseInsensitive());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;

import java.io.IOException;

public class WildcardLike extends RegexMatch<WildcardPattern> {
public abstract class WildcardLike extends RegexMatch<WildcardPattern> {

public WildcardLike(Source source, Expression left, WildcardPattern pattern) {
this(source, left, pattern, false);
Expand All @@ -33,14 +32,4 @@ public String getWriteableName() {
throw new UnsupportedOperationException();
}

@Override
protected NodeInfo<WildcardLike> info() {
return NodeInfo.create(this, WildcardLike::new, field(), pattern(), caseInsensitive());
}

@Override
protected WildcardLike replaceChild(Expression newLeft) {
return new WildcardLike(source(), newLeft, pattern(), caseInsensitive());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
import org.elasticsearch.xpack.esql.core.expression.Literal;
import org.elasticsearch.xpack.esql.core.expression.predicate.Range;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLikePattern;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.core.type.EsField;
Expand Down Expand Up @@ -46,10 +44,6 @@ public static Range rangeOf(Expression value, Expression lower, boolean includeL
return new Range(EMPTY, value, lower, includeLower, upper, includeUpper, randomZone());
}

public static RLike rlike(Expression left, String exp) {
return new RLike(EMPTY, left, new RLikePattern(exp));
}

public static FieldAttribute fieldAttribute() {
return fieldAttribute(randomAlphaOfLength(10), randomFrom(DataType.types()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,39 @@ Mokhtar |Bernatsky |38992 |BM
Parto |Bamford |61805 |BP
Premal |Baek |52833 |BP
;


caseInsensitiveRegex
from employees | where first_name RLIKE "(?i)geor.*" | keep first_name
;

first_name:keyword
;


caseInsensitiveRegex2
from employees | where first_name RLIKE "(?i)Geor.*" | keep first_name
;

first_name:keyword
;


caseInsensitiveRegexFold
required_capability: fixed_regex_fold
row foo = "Bar" | where foo rlike "(?i)ba.*"
;

foo:keyword
;


caseInsensitiveRegexFold2
required_capability: fixed_regex_fold
row foo = "Bar" | where foo rlike "(?i)Ba.*"
;

foo:keyword
;


Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,12 @@ public enum Cap {
/**
* Additional types for match function and operator
*/
MATCH_ADDITIONAL_TYPES;
MATCH_ADDITIONAL_TYPES,

/**
* Fix for regex folding with case-insensitive pattern https://github.com/elastic/elasticsearch/issues/118371
*/
FIXED_REGEX_FOLD;

private final boolean enabled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String getWriteableName() {
}

@Override
protected NodeInfo<org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike> info() {
protected NodeInfo<RLike> info() {
return NodeInfo.create(this, RLike::new, field(), pattern(), caseInsensitive());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.And;
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Not;
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLikePattern;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardLike;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardPattern;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
import org.elasticsearch.xpack.esql.expression.function.scalar.string.WildcardLike;
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Add;
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Div;
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Mod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void testPushDownFilterOnAliasInEval() {

public void testPushDownLikeRlikeFilter() {
EsRelation relation = relation();
org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike conditionA = rlike(getFieldAttribute("a"), "foo");
RLike conditionA = rlike(getFieldAttribute("a"), "foo");
WildcardLike conditionB = wildcardLike(getFieldAttribute("b"), "bar");

Filter fa = new Filter(EMPTY, relation, conditionA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNotNull;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLikePattern;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardLike;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardPattern;
import org.elasticsearch.xpack.esql.core.util.StringUtils;
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
import org.elasticsearch.xpack.esql.expression.function.scalar.string.WildcardLike;
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.Equals;

import static java.util.Arrays.asList;
Expand Down

0 comments on commit dd9df2e

Please sign in to comment.