Class SqlDataTypeSpec
- All Implemented Interfaces:
Cloneable
A SqlDataTypeSpec
is immutable; once created, you cannot
change any of the fields.
We support the following data type expressions:
- Complex data type expression like:
Internally we useROW(
foo NUMBER(5, 2) NOT NULL,
rec ROW(b BOOLEAN, i MyUDT NOT NULL))SqlRowTypeNameSpec
to specify row data type name. - Simple data type expression like CHAR, VARCHAR and DOUBLE
with optional precision and scale;
Internally we use
SqlBasicTypeNameSpec
to specify basic sql data type name. - Collection data type expression like:
Internally we useINT ARRAY; VARCHAR(20) MULTISET; INT ARRAY MULTISET;
SqlCollectionTypeNameSpec
to specify collection data type name. - User defined data type expression like `My_UDT`;
Internally we use
SqlUserDefinedTypeNameSpec
to specify user defined data type name.
-
Field Summary
Fields inherited from class org.apache.calcite.sql.SqlNode
EMPTY_ARRAY, pos
-
Constructor Summary
ConstructorDescriptionSqlDataTypeSpec
(SqlTypeNameSpec typeNameSpec, @Nullable TimeZone timeZone, @Nullable Boolean nullable, SqlParserPos pos) Creates a type specification representing a type, with time zone, nullability and base type name specified.SqlDataTypeSpec
(SqlTypeNameSpec typeNameSpec, @Nullable TimeZone timeZone, SqlParserPos pos) Creates a type specification representing a type, with time zone specified.SqlDataTypeSpec
(SqlTypeNameSpec typeNameSpec, SqlParserPos pos) Creates a type specification representing a type. -
Method Summary
Modifier and TypeMethodDescription<R> R
accept
(SqlVisitor<R> visitor) Accepts a generic visitor.clone
(SqlParserPos pos) Clones a SqlNode with a different position.deriveType
(SqlValidator validator) Converts this type specification to aRelDataType
.deriveType
(SqlValidator validator, boolean nullable) Converts this type specification to aRelDataType
.boolean
equalsDeep
(@Nullable SqlNode node, Litmus litmus) Returns whether this node is structurally equivalent to another node.@Nullable SqlIdentifier
Returns a new SqlDataTypeSpec corresponding to the component type if the type spec is a collections type spec.
Collection types areARRAY
andMULTISET
.getMonotonicity
(SqlValidatorScope scope) Returns whether expression is always ascending, descending or constant.@Nullable Boolean
@Nullable TimeZone
void
Writes a SQL representation of this node to a writer.void
validate
(SqlValidator validator, SqlValidatorScope scope) Validates this node.withNullable
(Boolean nullable) Returns a copy of this data type specification with a given nullability.withNullable
(Boolean nullable, SqlParserPos pos) Returns a copy of this data type specification with a given nullability, extending the parser position.Methods inherited from class org.apache.calcite.sql.SqlNode
clone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, findValidOptions, getKind, getParserPosition, isA, toList, toList, toSqlString, toSqlString, toSqlString, toString, unparseWithParentheses, validateExpr
-
Constructor Details
-
SqlDataTypeSpec
Creates a type specification representing a type.- Parameters:
typeNameSpec
- The type name can be basic sql type, row type, collections type and user defined type
-
SqlDataTypeSpec
Creates a type specification representing a type, with time zone specified.- Parameters:
typeNameSpec
- The type name can be basic sql type, row type, collections type and user defined typetimeZone
- Specified time zone
-
SqlDataTypeSpec
public SqlDataTypeSpec(SqlTypeNameSpec typeNameSpec, @Nullable TimeZone timeZone, @Nullable Boolean nullable, SqlParserPos pos) Creates a type specification representing a type, with time zone, nullability and base type name specified.- Parameters:
typeNameSpec
- The type name can be basic sql type, row type, collections type and user defined typetimeZone
- Specified time zonenullable
- The nullability
-
-
Method Details
-
clone
Description copied from class:SqlNode
Clones a SqlNode with a different position. -
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
-
getCollectionsTypeName
-
getTypeName
-
getTypeNameSpec
-
getTimeZone
-
getNullable
-
withNullable
Returns a copy of this data type specification with a given nullability. -
withNullable
Returns a copy of this data type specification with a given nullability, extending the parser position. -
getComponentTypeSpec
Returns a new SqlDataTypeSpec corresponding to the component type if the type spec is a collections type spec.
Collection types areARRAY
andMULTISET
. -
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. -
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. -
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
-
deriveType
Converts this type specification to aRelDataType
.Throws an error if the type is not found.
-
deriveType
Converts this type specification to aRelDataType
.Throws an error if the type is not found.
- Parameters:
nullable
- Whether the type is nullable if the type specification does not explicitly state
-