-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add Support for LIKE (LIST) #129170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for LIKE (LIST) #129170
Changes from 20 commits
72e72e4
0518bbc
f39ef12
495d6b8
561d325
c2c7274
683da23
d5e8071
6c6760e
099d1cf
9d6a6b0
8020ce6
9dcf413
59095ff
7a02bb7
78eb25f
ea84211
4980b1b
931b7c6
408fba0
dbc6f30
72d4531
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 129170 | ||
| summary: Add Support for LIKE (LIST) | ||
| area: ES|QL | ||
| type: enhancement | ||
| issues: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.esql.core.expression.predicate.regex; | ||
|
|
||
| import org.apache.lucene.util.automaton.Automaton; | ||
| import org.apache.lucene.util.automaton.Operations; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * A list of wildcard patterns. Each pattern is a {@link WildcardPattern} that can be used to match strings and is | ||
| * similar to basic regex, supporting '?' wildcard for single character (same as regex ".") | ||
| * and '*' wildcard for multiple characters (same as regex ".*") | ||
| * <p> | ||
| * Allows escaping based on a regular char | ||
| * | ||
| */ | ||
| public class WildcardPatternList extends AbstractStringPattern implements Writeable { | ||
| public static final String NAME = "WildcardPatternList"; | ||
| private final List<WildcardPattern> patternList; | ||
|
|
||
| public WildcardPatternList(List<WildcardPattern> patterns) { | ||
| this.patternList = patterns; | ||
| } | ||
|
|
||
| public WildcardPatternList(StreamInput in) throws IOException { | ||
| this(in.readCollectionAsList(WildcardPattern::new)); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeCollection(patternList, (o, pattern) -> pattern.writeTo(o)); | ||
| } | ||
|
|
||
| public static WildcardPatternList readFrom(StreamInput in) throws IOException { | ||
julian-elastic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return new WildcardPatternList(in); | ||
| } | ||
|
|
||
| public List<WildcardPattern> patternList() { | ||
| return patternList; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an automaton that matches any of the patterns in the list. | ||
| * We create a single automaton that is the union of all individual automata to improve performance | ||
| */ | ||
| @Override | ||
| public Automaton createAutomaton(boolean ignoreCase) { | ||
| List<Automaton> automatonList = patternList.stream().map(x -> x.createAutomaton(ignoreCase)).toList(); | ||
| Automaton result = Operations.union(automatonList); | ||
| return Operations.determinize(result, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a Java regex that matches any of the patterns in the list. | ||
| * The patterns are joined with the '|' operator to create a single regex. | ||
| */ | ||
| @Override | ||
| public String asJavaRegex() { | ||
| return patternList.stream().map(WildcardPattern::asJavaRegex).collect(Collectors.joining("|")); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we never us Java's regex pattern with this - it's just a description string. In a follow up, can you rename this to, like |
||
| } | ||
|
|
||
| /** | ||
| * Returns a string that matches any of the patterns in the list. | ||
| * The patterns are joined with the '|' operator to create a single wildcard string. | ||
| */ | ||
| @Override | ||
| public String pattern() { | ||
| if (patternList.isEmpty()) { | ||
| return ""; | ||
| } | ||
| if (patternList.size() == 1) { | ||
| return patternList.getFirst().pattern(); | ||
| } | ||
| return "(\"" + patternList.stream().map(WildcardPattern::pattern).collect(Collectors.joining("\", \"")) + "\")"; | ||
julian-elastic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(patternList); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
|
|
||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| WildcardPatternList other = (WildcardPatternList) obj; | ||
| return patternList.equals(other.patternList); | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.