Interface SqlValidatorNamespace
- All Known Implementing Classes:
AliasNamespace
,CollectNamespace
,DelegatingNamespace
,IdentifierNamespace
,LambdaNamespace
,MatchRecognizeNamespace
,PivotNamespace
,ProcedureNamespace
,SelectNamespace
,SetopNamespace
,SqlValidatorImpl.DmlNamespace
,TableConstructorNamespace
,UnpivotNamespace
,WithNamespace
For example, in the query SELECT emp.deptno, age FROM emp,
dept
, the FROM clause forms a namespace consisting of two tables EMP
and DEPT, and a row type consisting of the combined columns of those tables.
Other examples of namespaces include a table in the from list (the namespace contains the constituent columns) and a sub-query (the namespace contains the columns in the SELECT clause of the sub-query).
These various kinds of namespace are implemented by classes
IdentifierNamespace
for table names, SelectNamespace
for
SELECT queries, SetopNamespace
for UNION, EXCEPT and INTERSECT, and
so forth. But if you are looking at a SELECT query and call
SqlValidator.getNamespace(org.apache.calcite.sql.SqlNode)
, you may
not get a SelectNamespace. Why? Because the validator is allowed to wrap
namespaces in other objects which implement
SqlValidatorNamespace
. Your SelectNamespace will be there somewhere,
but might be one or two levels deep. Don't try to cast the namespace or use
instanceof
; use unwrap(Class)
and
isWrapperFor(Class)
instead.
- See Also:
-
Method Summary
Modifier and TypeMethodDescription@Nullable RelDataTypeField
Returns a field of a given name, or null.default boolean
fieldExists
(String name) Returns whether this namespace has a field of a given name.@Nullable SqlNode
Returns the parse tree node that at is at the root of this namespace and includes all decorations.Returns a list of expressions which are monotonic in this namespace.getMonotonicity
(String columnName) Returns whether and how a given column is sorted.default ImmutableBitSet
Returns the ordinals (in the row type) of the "must-filter" fields, fields that that must be filtered in a query.@Nullable SqlNode
getNode()
Returns the parse tree node at the root of this namespace.Returns the row type of this namespace, which comprises a list of names and types of the output columns.Returns the row type of this namespace, sans any system columns.@Nullable SqlValidatorTable
getTable()
Returns the underlying table, or null if there is none.getType()
Returns the type of this namespace.Returns the validator.boolean
isWrapperFor
(Class<?> clazz) Returns whether this namespace implements a given interface, or wraps a class which does.@Nullable SqlValidatorNamespace
lookupChild
(String name) Looks up a child namespace of a given name.void
Deprecated.resolve()
If this namespace resolves to another namespace, returns that namespace, following links to the end of the chain.void
setType
(RelDataType type) Sets the type of this namespace.boolean
supportsModality
(SqlModality modality) Returns whether this namespace is capable of giving results of the desired modality.<T> T
Returns this namespace, or a wrapped namespace, cast to a particular class.void
validate
(RelDataType targetRowType) Validates this namespace.
-
Method Details
-
getValidator
SqlValidator getValidator()Returns the validator.- Returns:
- validator
-
getTable
@Nullable SqlValidatorTable getTable()Returns the underlying table, or null if there is none. -
getRowType
RelDataType getRowType()Returns the row type of this namespace, which comprises a list of names and types of the output columns. If the scope's type has not yet been derived, derives it.- Returns:
- Row type of this namespace, never null, always a struct
-
getType
RelDataType getType()Returns the type of this namespace.- Returns:
- Row type converted to struct
-
setType
Sets the type of this namespace.Allows the type for the namespace to be explicitly set, but usually is called during
validate(RelDataType)
.Implicitly also sets the row type. If the type is not a struct, then the row type is the type wrapped as a struct with a single column, otherwise the type and row type are the same.
-
getRowTypeSansSystemColumns
RelDataType getRowTypeSansSystemColumns()Returns the row type of this namespace, sans any system columns.- Returns:
- Row type sans system columns
-
validate
Validates this namespace.If the scope has already been validated, does nothing.
Please call
SqlValidatorImpl.validateNamespace(org.apache.calcite.sql.validate.SqlValidatorNamespace, org.apache.calcite.rel.type.RelDataType)
rather than calling this method directly.- Parameters:
targetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
getNode
@Nullable SqlNode getNode()Returns the parse tree node at the root of this namespace.- Returns:
- parse tree node; null for
TableNamespace
-
getEnclosingNode
Returns the parse tree node that at is at the root of this namespace and includes all decorations. If there are no decorations, returns the same asgetNode()
. -
lookupChild
Looks up a child namespace of a given name.For example, in the query
select e.name from emps as e
,e
is anIdentifierNamespace
which has a childname
which is aFieldNamespace
.- Parameters:
name
- Name of namespace- Returns:
- Namespace
-
fieldExists
Returns whether this namespace has a field of a given name.- Parameters:
name
- Field name- Returns:
- Whether field exists
-
field
Returns a field of a given name, or null.- Parameters:
name
- Field name- Returns:
- Field, or null
-
getMonotonicExprs
List<Pair<SqlNode,SqlMonotonicity>> getMonotonicExprs()Returns a list of expressions which are monotonic in this namespace. For example, if the namespace represents a relation ordered by a column called "TIMESTAMP", then the list would contain aSqlIdentifier
called "TIMESTAMP". -
getMonotonicity
Returns whether and how a given column is sorted. -
makeNullable
Deprecated. -
unwrap
Returns this namespace, or a wrapped namespace, cast to a particular class.- Parameters:
clazz
- Desired type- Returns:
- This namespace cast to desired type
- Throws:
ClassCastException
- if no such interface is available
-
isWrapperFor
Returns whether this namespace implements a given interface, or wraps a class which does.- Parameters:
clazz
- Interface- Returns:
- Whether namespace implements given interface
-
resolve
SqlValidatorNamespace resolve()If this namespace resolves to another namespace, returns that namespace, following links to the end of the chain.A
WITH
) clause defines table names that resolve to queries (the body of the with-item). AnIdentifierNamespace
typically resolves to aTableNamespace
.You must not call this method before
validate(RelDataType)
has completed. -
supportsModality
Returns whether this namespace is capable of giving results of the desired modality.true
means streaming,false
means relational.- Parameters:
modality
- Modality
-
getMustFilterFields
Returns the ordinals (in the row type) of the "must-filter" fields, fields that that must be filtered in a query.
-