java.lang.Object
com.darkcollective.relix.ast.internal.AttributeNames

public final class AttributeNames extends Object
Utilities for working with possibly relation-qualified attribute names.

An attribute name may carry a relation qualifier separated by a ., for example Users.id. The qualifier is everything up to and including the last .; the column name is everything after it.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isPathInto(String name, String column)
    Whether name is a path into column — dotted, with column as its head: skills.years is a path into skills, while skills and Orders.skills are not.
    static String
    Returns the head of an attribute name — everything before the first ., or the whole name when it has none: location.city and location.geo.lat both yield location.
    static String
    Returns the relation qualifier of an attribute name, or null if it carries none: rooms.name yields rooms, and a bare name yields null.
    static String
    Strips any relation qualifier from an attribute name, returning the bare column name: Users.id yields id, and a bare id is returned unchanged.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • stripQualifier

      public static String stripQualifier(String name)
      Strips any relation qualifier from an attribute name, returning the bare column name: Users.id yields id, and a bare id is returned unchanged. The qualifier is everything up to and including the last ..
      Parameters:
      name - a possibly-qualified attribute name; must not be null
      Returns:
      the unqualified column name
    • qualifierOf

      public static String qualifierOf(String name)
      Returns the relation qualifier of an attribute name, or null if it carries none: rooms.name yields rooms, and a bare name yields null. The qualifier is everything up to (but not including) the last ..
      Parameters:
      name - a possibly-qualified attribute name; must not be null
      Returns:
      the relation qualifier, or null if the name is unqualified
    • pathHead

      public static String pathHead(String name)
      Returns the head of an attribute name — everything before the first ., or the whole name when it has none: location.city and location.geo.lat both yield location.

      This is the column a name denotes under the struct-path reading, and it is the other half of a genuine ambiguity. A dotted name may be a relation-qualified reference (Orders.amount — the column amount coming from Orders, whose column part is the tail, see stripQualifier(java.lang.String)) or a path into a nested column (location.city — the field city of the column location, whose column part is the head). The two readings are told apart against a schema, by Schema.resolvePath, and never by the spelling alone.

      Reach for this wherever a decision is about which column a reference touches — a rewrite that moves an operator past the column, say. Using the qualifier reading alone there is the mistake it exists to prevent: the head of skills.years is skills, and a rule that only inspected the tail years would conclude the reference has nothing to do with a skills column.

      Parameters:
      name - a possibly-qualified or dotted attribute name; must not be null
      Returns:
      the name's head — the column it names as a path
    • isPathInto

      public static boolean isPathInto(String name, String column)
      Whether name is a path into column — dotted, with column as its head: skills.years is a path into skills, while skills and Orders.skills are not.
      Parameters:
      name - a possibly-qualified or dotted attribute name; must not be null
      column - the column to test against; must not be null
      Returns:
      whether the name reads a field beneath that column