Class SqlIdentifier

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class SqlIdentifier
    extends SqlNode
    A SqlIdentifier is an identifier, possibly compound.
    • Field Detail

      • names

        public com.google.common.collect.ImmutableList<java.lang.String> names
        Array of the components of this compound identifier.

        The empty string represents the wildcard "*", to distinguish it from a real "*" (presumably specified using quotes).

        It's convenient to have this member public, and it's convenient to have this member not-final, but it's a shame it's public and not-final. If you assign to this member, please use setNames(java.util.List, java.util.List). And yes, we'd like to make identifiers immutable one day.

      • collation

        final SqlCollation collation
        This identifier's collation (if any).
      • componentPositions

        protected com.google.common.collect.ImmutableList<SqlParserPos> componentPositions
        A list of the positions of the components of compound identifiers.
    • Constructor Detail

      • SqlIdentifier

        public SqlIdentifier​(java.util.List<java.lang.String> names,
                             SqlCollation collation,
                             SqlParserPos pos,
                             java.util.List<SqlParserPos> componentPositions)
        Creates a compound identifier, for example foo.bar.
        Parameters:
        names - Parts of the identifier, length ≥ 1
      • SqlIdentifier

        public SqlIdentifier​(java.util.List<java.lang.String> names,
                             SqlParserPos pos)
      • SqlIdentifier

        public SqlIdentifier​(java.lang.String name,
                             SqlCollation collation,
                             SqlParserPos pos)
        Creates a simple identifier, for example foo, with a collation.
      • SqlIdentifier

        public SqlIdentifier​(java.lang.String name,
                             SqlParserPos pos)
        Creates a simple identifier, for example foo.
    • Method Detail

      • star

        public static SqlIdentifier star​(java.util.List<java.lang.String> names,
                                         SqlParserPos pos,
                                         java.util.List<SqlParserPos> componentPositions)
        Creates an identifier that ends in a wildcard star.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class SqlNode
      • getString

        public static java.lang.String getString​(java.util.List<java.lang.String> names)
        Converts a list of strings to a qualified identifier.
      • toStar

        public static java.util.List<java.lang.String> toStar​(java.util.List<java.lang.String> names)
        Converts empty strings in a list of names to stars.
      • setNames

        public void setNames​(java.util.List<java.lang.String> names,
                             java.util.List<SqlParserPos> poses)
        Modifies the components of this identifier and their positions.
        Parameters:
        names - Names of components
        poses - Positions of components
      • setName

        public SqlIdentifier setName​(int i,
                                     java.lang.String name)
        Returns an identifier that is the same as this except one modified name. Does not modify this identifier.
      • add

        public SqlIdentifier add​(int i,
                                 java.lang.String name,
                                 SqlParserPos pos)
        Returns an identifier that is the same as this except with a component added at a given position. Does not modify this identifier.
      • getComponentParserPosition

        public SqlParserPos getComponentParserPosition​(int i)
        Returns the position of the ith component of a compound identifier, or the position of the whole identifier if that information is not present.
        Parameters:
        i - Ordinal of component.
        Returns:
        Position of i'th component
      • assignNamesFrom

        public void assignNamesFrom​(SqlIdentifier other)
        Copies names and components from another identifier. Does not modify the cross-component parser position.
        Parameters:
        other - identifier from which to copy
      • getComponent

        public SqlIdentifier getComponent​(int ordinal)
        Creates an identifier which contains only the ordinalth component of this compound identifier. It will have the correct SqlParserPos, provided that detailed position information is available.
      • getComponent

        public SqlIdentifier getComponent​(int from,
                                          int to)
      • plus

        public SqlIdentifier plus​(java.lang.String name,
                                  SqlParserPos pos)
        Creates an identifier that consists of this identifier plus a name segment. Does not modify this identifier.
      • plusStar

        public SqlIdentifier plusStar()
        Creates an identifier that consists of this identifier plus a wildcard star. Does not modify this identifier.
      • skipLast

        public SqlIdentifier skipLast​(int n)
        Creates an identifier that consists of all but the last n name segments of this one.
      • unparse

        public void unparse​(SqlWriter writer,
                            int leftPrec,
                            int rightPrec)
        Description copied from class: SqlNode
        Writes a SQL representation of this node to a writer.

        The leftPrec and rightPrec parameters give us enough context to decide whether we need to enclose the expression in parentheses. For example, we need parentheses around "2 + 3" if preceded by "5 *". This is because the precedence of the "*" operator is greater than the precedence of the "+" operator.

        The algorithm handles left- and right-associative operators by giving them slightly different left- and right-precedence.

        If SqlWriter.isAlwaysUseParentheses() is true, we use parentheses even when they are not required by the precedence rules.

        For the details of this algorithm, see SqlCall.unparse(org.apache.calcite.sql.SqlWriter, int, int).

        Specified by:
        unparse in class SqlNode
        Parameters:
        writer - Target writer
        leftPrec - The precedence of the SqlNode immediately preceding this node in a depth-first scan of the parse tree
        rightPrec - The precedence of the SqlNode immediately
      • equalsDeep

        public boolean equalsDeep​(SqlNode node,
                                  Litmus litmus)
        Description copied from class: SqlNode
        Returns whether this node is structurally equivalent to another node. Some examples:
        • 1 + 2 is structurally equivalent to 1 + 2
        • 1 + 2 + 3 is structurally equivalent to (1 + 2) + 3, but not to 1 + (2 + 3), because the '+' operator is left-associative
        Specified by:
        equalsDeep in class SqlNode
      • accept

        public <R> R accept​(SqlVisitor<R> visitor)
        Description copied from class: SqlNode
        Accepts a generic visitor.

        Implementations of this method in subtypes simply call the appropriate visit method on the visitor object.

        The type parameter R must be consistent with the type parameter of the visitor.

        Specified by:
        accept in class SqlNode
      • getSimple

        public java.lang.String getSimple()
      • isStar

        public boolean isStar()
        Returns whether this identifier is a star, such as "*" or "foo.bar.*".
      • isSimple

        public boolean isSimple()
        Returns whether this is a simple identifier. "FOO" is simple; "*", "FOO.*" and "FOO.BAR" are not.
      • isComponentQuoted

        public boolean isComponentQuoted​(int i)
        Returns whether the ith component of a compound identifier is quoted.
        Parameters:
        i - Ordinal of component
        Returns:
        Whether i'th component is quoted