Class FieldPath

Object
gudusoft.gsqlparser.resolver2.model.FieldPath

public class FieldPath extends Object
Represents a field path for deep/record field access in structured types.

In BigQuery, Snowflake, and other databases with STRUCT/RECORD types, column references can include field paths like customer.address.city. This class captures the field path portion (segments beyond the base column).

Design principles:

  • Immutable - once created, cannot be modified
  • Only stores segments beyond the base column (e.g., for customer.address.city, if base column is customer, fieldPath stores ["address", "city"])
  • Empty fieldPath means no field access (regular column reference)

Example:

 -- SQL: SELECT customer.address.city FROM orders
 -- base column: customer
 -- fieldPath: ["address", "city"]
 
See Also:
  • Field Details

    • EMPTY

      public static final FieldPath EMPTY
      Empty field path singleton for regular column references
  • Constructor Details

    • FieldPath

      public FieldPath(List<String> segments)
      Create a FieldPath from a list of segments.
      Parameters:
      segments - The field path segments (will be copied)
  • Method Details

    • of

      public static FieldPath of(String segment)
      Create a FieldPath from a single segment.
      Parameters:
      segment - The single field segment
      Returns:
      A new FieldPath with one segment
    • of

      public static FieldPath of(String... segments)
      Create a FieldPath from multiple segments.
      Parameters:
      segments - The field segments
      Returns:
      A new FieldPath
    • of

      public static FieldPath of(List<String> segments)
      Create a FieldPath from a list of segments.
      Parameters:
      segments - The field segments
      Returns:
      A new FieldPath, or EMPTY if null/empty
    • getSegments

      public List<String> getSegments()
      Get the field path segments.
      Returns:
      Unmodifiable list of segments
    • size

      public int size()
      Get the number of segments in this field path.
      Returns:
      Number of segments
    • isEmpty

      public boolean isEmpty()
      Check if this field path is empty (no field access).
      Returns:
      true if empty
    • getFirst

      public String getFirst()
      Get the first segment (immediate field).
      Returns:
      First segment, or null if empty
    • getLast

      public String getLast()
      Get the last segment (deepest field).
      Returns:
      Last segment, or null if empty
    • get

      public String get(int index)
      Get a segment by index.
      Parameters:
      index - The index
      Returns:
      The segment at that index
      Throws:
      IndexOutOfBoundsException - if index is invalid
    • append

      public FieldPath append(String segment)
      Create a new FieldPath with an additional segment appended.
      Parameters:
      segment - The segment to append
      Returns:
      New FieldPath with the segment appended
    • append

      public FieldPath append(FieldPath other)
      Create a new FieldPath with additional segments appended.
      Parameters:
      other - The FieldPath to append
      Returns:
      New FieldPath with all segments
    • subPath

      public FieldPath subPath(int fromIndex)
      Create a sub-path starting from the given index.
      Parameters:
      fromIndex - Start index (inclusive)
      Returns:
      New FieldPath with segments from fromIndex
    • toString

      public String toString()
      Convert to dot-separated string representation.
      Overrides:
      toString in class Object
      Returns:
      String like "address.city", or empty string if empty
    • toFullReference

      public String toFullReference(String baseColumn)
      Convert to full reference string with base column.
      Parameters:
      baseColumn - The base column name
      Returns:
      String like "customer.address.city"
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object