Class AutomatonUtils
java.lang.Object
org.elasticsearch.xpack.esql.optimizer.rules.logical.promql.AutomatonUtils
Utility class for analyzing Lucene Automaton patterns to extract optimization opportunities.
This class provides methods to detect common patterns in regex automatons that can be
optimized into simpler query predicates like equality, prefix matching, or IN clauses.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a pattern fragment that can be optimized. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<AutomatonUtils.PatternFragment> extractFragments(String pattern) Extracts potentially mixed disjoint pattern within the given regex.static booleanmatchesAll(org.apache.lucene.util.automaton.Automaton automaton) Checks if the automaton matches all possible strings.static booleanmatchesEmpty(org.apache.lucene.util.automaton.Automaton automaton) Checks if the automaton matches the empty string.static StringmatchesExact(org.apache.lucene.util.automaton.Automaton automaton) Extracts an exact match if the automaton matches only a single string.static booleanmatchesNone(org.apache.lucene.util.automaton.Automaton automaton) Checks if the automaton matches no strings.
-
Method Details
-
matchesAll
public static boolean matchesAll(org.apache.lucene.util.automaton.Automaton automaton) Checks if the automaton matches all possible strings.- Parameters:
automaton- the automaton to check- Returns:
- true if it matches everything
-
matchesNone
public static boolean matchesNone(org.apache.lucene.util.automaton.Automaton automaton) Checks if the automaton matches no strings.- Parameters:
automaton- the automaton to check- Returns:
- true if it matches nothing
-
matchesEmpty
public static boolean matchesEmpty(org.apache.lucene.util.automaton.Automaton automaton) Checks if the automaton matches the empty string.- Parameters:
automaton- the automaton to check- Returns:
- true if it matches the empty string
-
matchesExact
Extracts an exact match if the automaton matches only a single string.- Parameters:
automaton- the automaton to analyze- Returns:
- the single matched string, or null if it matches zero or multiple strings
-
extractFragments
Extracts potentially mixed disjoint pattern within the given regex. Handles disjunctions if specified with | operator. This handles mixed patterns like: - prod-.*|staging|.*-dev|.*test.* - mix of prefix, exact, suffix, contains - http://.*|https://.*|ftp - mix of prefixes and exact - *.txt|*.csv|readme - mix of suffixes and exact Each part is classified and can be optimized independently, then combined with OR.- Parameters:
pattern- the regex pattern string- Returns:
- list of pattern fragments, or null if any part cannot be optimized
-