Record Class WildcardLikeShape

java.lang.Object
java.lang.Record
org.elasticsearch.xpack.esql.datasources.pushdown.WildcardLikeShape
Record Components:
prefix - the literal prefix, or null if the pattern starts with *
literal - the literal middle substring, or null if the pattern has fewer than two * runs or the middle segment is empty
suffix - the literal suffix, or null if the pattern ends with *

public record WildcardLikeShape(org.apache.lucene.util.BytesRef prefix, org.apache.lucene.util.BytesRef literal, org.apache.lucene.util.BytesRef suffix) extends Record
Shape decomposition for WildcardLike patterns of the affix-contains family: an optional literal prefix, an optional literal substring in the middle, and an optional literal suffix. The pattern is represented as
prefix * literal * suffix
where any of the three literal segments may be empty (rendered as null on the result).

Recognized shapes — adjacent *s are collapsed during parsing, so **foo**bar* is treated as *foo*bar* (and rejected; see below):

  • prefix* — one wildcard, only a prefix
  • *suffix — one wildcard, only a suffix
  • prefix*suffix — one wildcard, both affixes
  • *literal* — two wildcards, only a middle literal
  • prefix*literal* — two wildcards, prefix + middle
  • *literal*suffix — two wildcards, middle + suffix
  • prefix*literal*suffix — two wildcards, all three segments

Patterns that fall outside the family stay on the automaton path and produce null from of(String):

  • any ? — single-codepoint wildcard, awkward on UTF-8 byte boundaries
  • any \\ backslash anywhere in the pattern — escape handling would need to be consistent with Lucene's wildcard un-escaping per segment; rejecting outright keeps the parser bit-identical with ByteRunAutomaton and avoids divergence risk
  • three or more unescaped, non-adjacent * — would require multi-segment ordered contains, more complex than the affix-contains shape can express
  • an empty pattern — degenerate; WildcardPattern guards against it upstream
  • a pattern with no * — equivalent to Equals, which the logical optimizer already decomposes; not the responsibility of this parser

Bytes are committed to UTF-8 by way of BytesRef(CharSequence), matching what KEYWORD values are encoded as on the read path.

  • Constructor Summary

    Constructors
    Constructor
    Description
    WildcardLikeShape(org.apache.lucene.util.BytesRef prefix, org.apache.lucene.util.BytesRef literal, org.apache.lucene.util.BytesRef suffix)
    Creates an instance of a WildcardLikeShape record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    org.apache.lucene.util.BytesRef
    Returns the value of the literal record component.
    boolean
    Returns true when this shape selects every value (every component is absent).
    of(String pattern)
    Returns the shape of the given case-sensitive WildcardLike pattern, or null if the pattern is outside the affix-contains family (see the class-level docs).
    org.apache.lucene.util.BytesRef
    Returns the value of the prefix record component.
    org.apache.lucene.util.BytesRef
    Returns the value of the suffix record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • WildcardLikeShape

      public WildcardLikeShape(@Nullable org.apache.lucene.util.BytesRef prefix, @Nullable org.apache.lucene.util.BytesRef literal, @Nullable org.apache.lucene.util.BytesRef suffix)
      Creates an instance of a WildcardLikeShape record class.
      Parameters:
      prefix - the value for the prefix record component
      literal - the value for the literal record component
      suffix - the value for the suffix record component
  • Method Details

    • of

      @Nullable public static WildcardLikeShape of(String pattern)
      Returns the shape of the given case-sensitive WildcardLike pattern, or null if the pattern is outside the affix-contains family (see the class-level docs).

      Caller is responsible for the case-sensitivity check — this parser is intentionally blind to it so the rule is local.

    • matchesAll

      public boolean matchesAll()
      Returns true when this shape selects every value (every component is absent). Equivalent to a LIKE * pattern; callers typically have an upstream matchesAll fast path that handles this without dispatching to ByteMatchers.affixContains(org.apache.lucene.util.BytesRef, org.apache.lucene.util.BytesRef, org.apache.lucene.util.BytesRef, org.apache.lucene.util.BytesRef).
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • prefix

      @Nullable public org.apache.lucene.util.BytesRef prefix()
      Returns the value of the prefix record component.
      Returns:
      the value of the prefix record component
    • literal

      @Nullable public org.apache.lucene.util.BytesRef literal()
      Returns the value of the literal record component.
      Returns:
      the value of the literal record component
    • suffix

      @Nullable public org.apache.lucene.util.BytesRef suffix()
      Returns the value of the suffix record component.
      Returns:
      the value of the suffix record component