Class AbstractNamespace
- java.lang.Object
-
- org.apache.calcite.sql.validate.AbstractNamespace
-
- All Implemented Interfaces:
SqlValidatorNamespace
- Direct Known Subclasses:
AliasNamespace
,CollectNamespace
,FieldNamespace
,IdentifierNamespace
,JoinNamespace
,MatchRecognizeNamespace
,ParameterNamespace
,ProcedureNamespace
,SchemaNamespace
,SelectNamespace
,SetopNamespace
,TableConstructorNamespace
,TableNamespace
,UnnestNamespace
,WithItemNamespace
,WithNamespace
abstract class AbstractNamespace extends java.lang.Object implements SqlValidatorNamespace
Abstract implementation ofSqlValidatorNamespace
.
-
-
Field Summary
Fields Modifier and Type Field Description protected SqlNode
enclosingNode
protected RelDataType
rowType
Type of the output row, which comprises the name and type of each output column.private SqlValidatorImpl.Status
status
Whether this scope is currently being validated.protected RelDataType
type
AsrowType
, but not necessarily a struct.protected SqlValidatorImpl
validator
-
Constructor Summary
Constructors Constructor Description AbstractNamespace(SqlValidatorImpl validator, SqlNode enclosingNode)
Creates an AbstractNamespace.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected RelDataType
convertToStruct(RelDataType type)
boolean
fieldExists(java.lang.String name)
Returns whether this namespace has a field of a given name.SqlNode
getEnclosingNode()
Returns the parse tree node that at is at the root of this namespace and includes all decorations.java.util.List<Pair<SqlNode,SqlMonotonicity>>
getMonotonicExprs()
Returns a list of expressions which are monotonic in this namespace.SqlMonotonicity
getMonotonicity(java.lang.String columnName)
Returns whether and how a given column is sorted.RelDataType
getRowType()
Returns the row type of this namespace, which comprises a list of names and types of the output columns.RelDataType
getRowTypeSansSystemColumns()
Returns the row type of this namespace, sans any system columns.SqlValidatorTable
getTable()
Returns the underlying table, or null if there is none.RelDataType
getType()
Returns the type of this namespace.SqlValidator
getValidator()
Returns the validator.boolean
isWrapperFor(java.lang.Class<?> clazz)
Returns whether this namespace implements a given interface, or wraps a class which does.SqlValidatorNamespace
lookupChild(java.lang.String name)
Looks up a child namespace of a given name.void
makeNullable()
SqlValidatorNamespace
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.protected RelDataType
toStruct(RelDataType type, SqlNode unnest)
Converts a type to a struct if it is not already.java.lang.String
translate(java.lang.String name)
<T> T
unwrap(java.lang.Class<T> clazz)
Returns this namespace, or a wrapped namespace, cast to a particular class.void
validate(RelDataType targetRowType)
Validates this namespace.protected abstract RelDataType
validateImpl(RelDataType targetRowType)
Validates this scope and returns the type of the records it returns.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.calcite.sql.validate.SqlValidatorNamespace
getNode
-
-
-
-
Field Detail
-
validator
protected final SqlValidatorImpl validator
-
status
private SqlValidatorImpl.Status status
Whether this scope is currently being validated. Used to check for cycles.
-
rowType
protected RelDataType rowType
Type of the output row, which comprises the name and type of each output column. Set on validate.
-
type
protected RelDataType type
AsrowType
, but not necessarily a struct.
-
enclosingNode
protected final SqlNode enclosingNode
-
-
Constructor Detail
-
AbstractNamespace
AbstractNamespace(SqlValidatorImpl validator, SqlNode enclosingNode)
Creates an AbstractNamespace.- Parameters:
validator
- ValidatorenclosingNode
- Enclosing node
-
-
Method Detail
-
getValidator
public SqlValidator getValidator()
Description copied from interface:SqlValidatorNamespace
Returns the validator.- Specified by:
getValidator
in interfaceSqlValidatorNamespace
- Returns:
- validator
-
validate
public final void validate(RelDataType targetRowType)
Description copied from interface:SqlValidatorNamespace
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.- Specified by:
validate
in interfaceSqlValidatorNamespace
- Parameters:
targetRowType
- Desired row type, must not be null, may be the data type 'unknown'.
-
validateImpl
protected abstract RelDataType validateImpl(RelDataType targetRowType)
Validates this scope and returns the type of the records it returns. External users should callvalidate(org.apache.calcite.rel.type.RelDataType)
, which uses thestatus
field to protect against cycles.- Parameters:
targetRowType
- Desired row type, must not be null, may be the data type 'unknown'.- Returns:
- record data type, never null
-
getRowType
public RelDataType getRowType()
Description copied from interface:SqlValidatorNamespace
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.- Specified by:
getRowType
in interfaceSqlValidatorNamespace
- Returns:
- Row type of this namespace, never null, always a struct
-
getRowTypeSansSystemColumns
public RelDataType getRowTypeSansSystemColumns()
Description copied from interface:SqlValidatorNamespace
Returns the row type of this namespace, sans any system columns.- Specified by:
getRowTypeSansSystemColumns
in interfaceSqlValidatorNamespace
- Returns:
- Row type sans system columns
-
getType
public RelDataType getType()
Description copied from interface:SqlValidatorNamespace
Returns the type of this namespace.- Specified by:
getType
in interfaceSqlValidatorNamespace
- Returns:
- Row type converted to struct
-
setType
public void setType(RelDataType type)
Description copied from interface:SqlValidatorNamespace
Sets the type of this namespace.Allows the type for the namespace to be explicitly set, but usually is called during
SqlValidatorNamespace.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.
- Specified by:
setType
in interfaceSqlValidatorNamespace
-
getEnclosingNode
public SqlNode getEnclosingNode()
Description copied from interface:SqlValidatorNamespace
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 asSqlValidatorNamespace.getNode()
.- Specified by:
getEnclosingNode
in interfaceSqlValidatorNamespace
-
getTable
public SqlValidatorTable getTable()
Description copied from interface:SqlValidatorNamespace
Returns the underlying table, or null if there is none.- Specified by:
getTable
in interfaceSqlValidatorNamespace
-
lookupChild
public SqlValidatorNamespace lookupChild(java.lang.String name)
Description copied from interface:SqlValidatorNamespace
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
.- Specified by:
lookupChild
in interfaceSqlValidatorNamespace
- Parameters:
name
- Name of namespace- Returns:
- Namespace
-
fieldExists
public boolean fieldExists(java.lang.String name)
Description copied from interface:SqlValidatorNamespace
Returns whether this namespace has a field of a given name.- Specified by:
fieldExists
in interfaceSqlValidatorNamespace
- Parameters:
name
- Field name- Returns:
- Whether field exists
-
getMonotonicExprs
public java.util.List<Pair<SqlNode,SqlMonotonicity>> getMonotonicExprs()
Description copied from interface:SqlValidatorNamespace
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".- Specified by:
getMonotonicExprs
in interfaceSqlValidatorNamespace
-
getMonotonicity
public SqlMonotonicity getMonotonicity(java.lang.String columnName)
Description copied from interface:SqlValidatorNamespace
Returns whether and how a given column is sorted.- Specified by:
getMonotonicity
in interfaceSqlValidatorNamespace
-
makeNullable
public void makeNullable()
- Specified by:
makeNullable
in interfaceSqlValidatorNamespace
-
translate
public java.lang.String translate(java.lang.String name)
-
resolve
public SqlValidatorNamespace resolve()
Description copied from interface:SqlValidatorNamespace
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
SqlValidatorNamespace.validate(RelDataType)
has completed.- Specified by:
resolve
in interfaceSqlValidatorNamespace
-
supportsModality
public boolean supportsModality(SqlModality modality)
Description copied from interface:SqlValidatorNamespace
Returns whether this namespace is capable of giving results of the desired modality.true
means streaming,false
means relational.- Specified by:
supportsModality
in interfaceSqlValidatorNamespace
- Parameters:
modality
- Modality
-
unwrap
public <T> T unwrap(java.lang.Class<T> clazz)
Description copied from interface:SqlValidatorNamespace
Returns this namespace, or a wrapped namespace, cast to a particular class.- Specified by:
unwrap
in interfaceSqlValidatorNamespace
- Parameters:
clazz
- Desired type- Returns:
- This namespace cast to desired type
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> clazz)
Description copied from interface:SqlValidatorNamespace
Returns whether this namespace implements a given interface, or wraps a class which does.- Specified by:
isWrapperFor
in interfaceSqlValidatorNamespace
- Parameters:
clazz
- Interface- Returns:
- Whether namespace implements given interface
-
convertToStruct
protected RelDataType convertToStruct(RelDataType type)
-
toStruct
protected RelDataType toStruct(RelDataType type, SqlNode unnest)
Converts a type to a struct if it is not already.
-
-