Class SqlIdentifier

java.lang.Object
org.apache.calcite.sql.SqlNode
org.apache.calcite.sql.SqlIdentifier
All Implemented Interfaces:
Cloneable

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

    • STAR

      public static final SqlIdentifier STAR
      An identifier for star, "*".
      See Also:
    • names

      public com.google.common.collect.ImmutableList<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.

    • componentPositions

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

    • SqlIdentifier

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

      public SqlIdentifier(List<String> names, SqlParserPos pos)
    • SqlIdentifier

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

      public SqlIdentifier(String name, SqlParserPos pos)
      Creates a simple identifier, for example foo.
  • Method Details

    • star

      public static SqlIdentifier star(SqlParserPos pos)
      Creates an identifier that is a singleton wildcard star.
    • star

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

      public SqlKind getKind()
      Description copied from class: SqlNode
      Returns the type of node this is, or SqlKind.OTHER if it's nothing special.
      Overrides:
      getKind in class SqlNode
      Returns:
      a SqlKind value, never null
      See Also:
    • clone

      public SqlNode clone(SqlParserPos pos)
      Description copied from class: SqlNode
      Clones a SqlNode with a different position.
      Specified by:
      clone in class SqlNode
    • toString

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

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

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

      public void setNames(List<String> names, @Nullable 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, 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, 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(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
    • validate

      public void validate(SqlValidator validator, SqlValidatorScope scope)
      Description copied from class: SqlNode
      Validates this node.

      The typical implementation of this method will make a callback to the validator appropriate to the node type and context. The validator has methods such as SqlValidator.validateLiteral(org.apache.calcite.sql.SqlLiteral) for these purposes.

      Specified by:
      validate in class SqlNode
      Parameters:
      scope - Validator
    • validateExpr

      public void validateExpr(SqlValidator validator, SqlValidatorScope scope)
      Description copied from class: SqlNode
      Validates this node in an expression context.

      Usually, this method does much the same as SqlNode.validate(org.apache.calcite.sql.validate.SqlValidator, org.apache.calcite.sql.validate.SqlValidatorScope), but a SqlIdentifier can occur in expression and non-expression contexts.

      Overrides:
      validateExpr in class SqlNode
    • equalsDeep

      public boolean equalsDeep(@Nullable 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
    • getCollation

      @Pure public @Nullable SqlCollation getCollation()
    • getSimple

      public String getSimple()
    • simpleNames

      public static List<String> simpleNames(List<? extends SqlNode> list)
      Returns the simple names in a list of identifiers. Assumes that the list consists of are not-null, simple identifiers.
    • simpleNames

      public static Iterable<String> simpleNames(Iterable<? extends SqlNode> list)
      Returns the simple names in a iterable of identifiers. Assumes that the iterable consists of not-null, simple identifiers.
    • 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
    • getMonotonicity

      public SqlMonotonicity getMonotonicity(SqlValidatorScope scope)
      Description copied from class: SqlNode
      Returns whether expression is always ascending, descending or constant. This property is useful because it allows to safely aggregate infinite streams of values.

      The default implementation returns SqlMonotonicity.NOT_MONOTONIC.

      Overrides:
      getMonotonicity in class SqlNode
      Parameters:
      scope - Scope