Class SqlIdentifier
- All Implemented Interfaces:
Cloneable
SqlIdentifier is an identifier, possibly compound.-
Field Summary
FieldsModifier 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 SqlIdentifierAn identifier for star, "*".Fields inherited from class org.apache.calcite.sql.SqlNode
EMPTY_ARRAY, pos -
Constructor Summary
ConstructorsConstructorDescriptionSqlIdentifier(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> Raccept(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.voidassignNamesFrom(SqlIdentifier other) Copies names and components from another identifier.clone(SqlParserPos pos) Clones a SqlNode with a different position.booleanequalsDeep(@Nullable SqlNode node, Litmus litmus) Returns whether this node is structurally equivalent to another node.@Nullable SqlCollationgetComponent(int ordinal) Creates an identifier which contains only theordinalth component of this compound identifier.getComponent(int from, int to) getComponentParserPosition(int i) Returns the position of theith 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.OTHERif it's nothing special.getMonotonicity(SqlValidatorScope scope) Returns whether expression is always ascending, descending or constant.static StringConverts a list of strings to a qualified identifier.booleanisComponentQuoted(int i) Returns whether theith component of a compound identifier is quoted.booleanisSimple()Returns whether this is a simple identifier.booleanisStar()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.voidsetNames(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 lastnname segments of this one.static SqlIdentifierstar(List<String> names, SqlParserPos pos, List<SqlParserPos> componentPositions) Creates an identifier that ends in a wildcard star.static SqlIdentifierstar(SqlParserPos pos) Creates an identifier that is a singleton wildcard star.Converts empty strings in a list of names to stars.toString()voidWrites a SQL representation of this node to a writer.voidvalidate(SqlValidator validator, SqlValidatorScope scope) Validates this node.voidvalidateExpr(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:SqlNodeReturns the type of node this is, orSqlKind.OTHERif it's nothing special. -
clone
Description copied from class:SqlNodeClones 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 theith 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 theordinalth 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 lastnname segments of this one. -
unparse
Description copied from class:SqlNodeWrites a SQL representation of this node to a writer.The
leftPrecandrightPrecparameters 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:SqlNodeValidates 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:SqlNodeValidates 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 aSqlIdentifiercan occur in expression and non-expression contexts.- Overrides:
validateExprin classSqlNode
-
equalsDeep
Description copied from class:SqlNodeReturns 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:
equalsDeepin classSqlNode
-
accept
Description copied from class:SqlNodeAccepts a generic visitor.Implementations of this method in subtypes simply call the appropriate
visitmethod on thevisitor object.The type parameter
Rmust 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 theith component of a compound identifier is quoted.- Parameters:
i- Ordinal of component- Returns:
- Whether i'th component is quoted
-
getMonotonicity
Description copied from class:SqlNodeReturns 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:
getMonotonicityin classSqlNode- Parameters:
scope- Scope
-