java.lang.Object
org.elasticsearch.xpack.esql.optimizer.rules.logical.promql.AutomatonUtils

public final class AutomatonUtils extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Represents a pattern fragment that can be optimized.
  • Method Summary

    Modifier and Type
    Method
    Description
    Extracts potentially mixed disjoint pattern within the given regex.
    static boolean
    matchesAll(org.apache.lucene.util.automaton.Automaton automaton)
    Checks if the automaton matches all possible strings.
    static boolean
    matchesEmpty(org.apache.lucene.util.automaton.Automaton automaton)
    Checks if the automaton matches the empty string.
    static String
    matchesExact(org.apache.lucene.util.automaton.Automaton automaton)
    Extracts an exact match if the automaton matches only a single string.
    static boolean
    matchesNone(org.apache.lucene.util.automaton.Automaton automaton)
    Checks if the automaton matches no strings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static String matchesExact(org.apache.lucene.util.automaton.Automaton automaton)
      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

      public static List<AutomatonUtils.PatternFragment> extractFragments(String pattern)
      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