Class SqlIdentifier
- All Implemented Interfaces:
Cloneable
SqlIdentifier
is an identifier, possibly compound.-
Field Summary
Modifier and TypeFieldDescriptionprotected @Nullable com.google.common.collect.ImmutableList<SqlParserPos>
A list of the positions of the components of compound identifiers.com.google.common.collect.ImmutableList<String>
Array of the components of this compound identifier.static final SqlIdentifier
An identifier for star, "*".Fields inherited from class org.apache.calcite.sql.SqlNode
EMPTY_ARRAY, pos
-
Constructor Summary
ConstructorDescriptionSqlIdentifier
(String name, @Nullable SqlCollation collation, SqlParserPos pos) Creates a simple identifier, for examplefoo
, with a collation.SqlIdentifier
(String name, SqlParserPos pos) Creates a simple identifier, for examplefoo
.SqlIdentifier
(List<String> names, @Nullable SqlCollation collation, SqlParserPos pos, @Nullable List<SqlParserPos> componentPositions) Creates a compound identifier, for examplefoo.bar
.SqlIdentifier
(List<String> names, SqlParserPos pos) -
Method Summary
Modifier and TypeMethodDescription<R> R
accept
(SqlVisitor<R> visitor) Accepts a generic visitor.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.void
assignNamesFrom
(SqlIdentifier other) Copies names and components from another identifier.clone
(SqlParserPos pos) Clones a SqlNode with a different position.boolean
equalsDeep
(@Nullable SqlNode node, Litmus litmus) Returns whether this node is structurally equivalent to another node.@Nullable SqlCollation
getComponent
(int ordinal) Creates an identifier which contains only theordinal
th component of this compound identifier.getComponent
(int from, int to) getComponentParserPosition
(int i) Returns the position of thei
th component of a compound identifier, or the position of the whole identifier if that information is not present.getKind()
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special.getMonotonicity
(SqlValidatorScope scope) Returns whether expression is always ascending, descending or constant.static String
Converts a list of strings to a qualified identifier.boolean
isComponentQuoted
(int i) Returns whether thei
th component of a compound identifier is quoted.boolean
isSimple()
Returns whether this is a simple identifier.boolean
isStar()
Returns whether this identifier is a star, such as "*" or "foo.bar.*".plus
(String name, SqlParserPos pos) Creates an identifier that consists of this identifier plus a name segment.plusStar()
Creates an identifier that consists of this identifier plus a wildcard star.Returns an identifier that is the same as this except one modified name.void
setNames
(List<String> names, @Nullable List<SqlParserPos> poses) Modifies the components of this identifier and their positions.simpleNames
(Iterable<? extends SqlNode> list) Returns the simple names in a iterable of identifiers.simpleNames
(List<? extends SqlNode> list) Returns the simple names in a list of identifiers.skipLast
(int n) Creates an identifier that consists of all but the lastn
name segments of this one.static SqlIdentifier
star
(List<String> names, SqlParserPos pos, List<SqlParserPos> componentPositions) Creates an identifier that ends in a wildcard star.static SqlIdentifier
star
(SqlParserPos pos) Creates an identifier that is a singleton wildcard star.Converts empty strings in a list of names to stars.toString()
void
Writes a SQL representation of this node to a writer.void
validate
(SqlValidator validator, SqlValidatorScope scope) Validates this node.void
validateExpr
(SqlValidator validator, SqlValidatorScope scope) Validates this node in an expression context.Methods inherited from class org.apache.calcite.sql.SqlNode
clone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, findValidOptions, getParserPosition, isA, toList, toList, toSqlString, toSqlString, toSqlString, unparseWithParentheses
-
Field Details
-
STAR
An identifier for star, "*".- See Also:
-
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
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 examplefoo.bar
.- Parameters:
names
- Parts of the identifier, length ≥ 1
-
SqlIdentifier
-
SqlIdentifier
Creates a simple identifier, for examplefoo
, with a collation. -
SqlIdentifier
Creates a simple identifier, for examplefoo
.
-
-
Method Details
-
star
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
Description copied from class:SqlNode
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special. -
clone
Description copied from class:SqlNode
Clones a SqlNode with a different position. -
toString
-
getString
Converts a list of strings to a qualified identifier. -
toStar
Converts empty strings in a list of names to stars. -
setNames
Modifies the components of this identifier and their positions.- Parameters:
names
- Names of componentsposes
- Positions of components
-
setName
Returns an identifier that is the same as this except one modified name. Does not modify this identifier. -
add
Returns an identifier that is the same as this except with a component added at a given position. Does not modify this identifier. -
getComponentParserPosition
Returns the position of thei
th 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
Copies names and components from another identifier. Does not modify the cross-component parser position.- Parameters:
other
- identifier from which to copy
-
getComponent
Creates an identifier which contains only theordinal
th component of this compound identifier. It will have the correctSqlParserPos
, provided that detailed position information is available. -
getComponent
-
plus
Creates an identifier that consists of this identifier plus a name segment. Does not modify this identifier. -
plusStar
Creates an identifier that consists of this identifier plus a wildcard star. Does not modify this identifier. -
skipLast
Creates an identifier that consists of all but the lastn
name segments of this one. -
unparse
Description copied from class:SqlNode
Writes a SQL representation of this node to a writer.The
leftPrec
andrightPrec
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)
. -
validate
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. -
validateExpr
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 aSqlIdentifier
can occur in expression and non-expression contexts.- Overrides:
validateExpr
in classSqlNode
-
equalsDeep
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 classSqlNode
-
accept
Description copied from class:SqlNode
Accepts a generic visitor.Implementations of this method in subtypes simply call the appropriate
visit
method on thevisitor object
.The type parameter
R
must be consistent with the type parameter of the visitor. -
getCollation
-
getSimple
-
simpleNames
Returns the simple names in a list of identifiers. Assumes that the list consists of are not-null, simple identifiers. -
simpleNames
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 thei
th component of a compound identifier is quoted.- Parameters:
i
- Ordinal of component- Returns:
- Whether i'th component is quoted
-
getMonotonicity
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 classSqlNode
- Parameters:
scope
- Scope
-