-
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
Merged
Merged
Add Support for LIKE (LIST) #129170
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
72e72e4
New Func Added
julian-elastic 0518bbc
Add more tests and fix bug
julian-elastic f39ef12
Switch to old function where possible, add more UTs
julian-elastic 495d6b8
[CI] Auto commit changes from spotless
561d325
Merge branch 'main' into first
julian-elastic c2c7274
Regenerate parse files after merge
julian-elastic 683da23
Fix merge error
julian-elastic d5e8071
Add more unit tests, fix bugs
julian-elastic 6c6760e
Change grammar to use string instead of valueExpression to pass unit …
julian-elastic 099d1cf
Code cleanup
julian-elastic 9d6a6b0
Documentation, More UT, Bugfix
julian-elastic 8020ce6
Add more comments
julian-elastic 9dcf413
Merge branch 'main' into first
julian-elastic 59095ff
Fix merge conflicts
julian-elastic 7a02bb7
Update docs/changelog/129170.yaml
julian-elastic 78eb25f
Address code review feedback
julian-elastic ea84211
Merge remote-tracking branch 'origin/first' into first
julian-elastic 4980b1b
[CI] Auto commit changes from spotless
931b7c6
Merge remote-tracking branch 'origin/main' into first
julian-elastic 408fba0
Merge remote-tracking branch 'origin/first' into first
julian-elastic dbc6f30
Address more code review feedback
julian-elastic 72d4531
Merge branch 'main' into first
julian-elastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...ava/org/elasticsearch/xpack/esql/core/expression/predicate/regex/WildcardPatternList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * 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.NamedWriteable; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry; | ||
|
|
||
| /** | ||
| * 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 | ||
julian-elastic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| */ | ||
| public class WildcardPatternList extends AbstractStringPattern implements NamedWriteable { | ||
julian-elastic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static final Entry ENTRY = new Entry(WildcardPatternList.class, "WildcardPatternList", WildcardPatternList::new); | ||
| 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)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getWriteableName() { | ||
| return NAME; | ||
| } | ||
|
|
||
| public static WildcardPatternList readFrom(StreamInput in) throws IOException { | ||
julian-elastic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return new WildcardPatternList(in.readCollectionAsList(WildcardPattern::readFrom)); | ||
| } | ||
|
|
||
| public List<WildcardPattern> patternList() { | ||
| return patternList; | ||
| } | ||
|
|
||
| @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); | ||
| } | ||
|
|
||
| @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 |
||
| } | ||
|
|
||
| @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 Objects.equals(patternList, other.patternList); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.