Package org.apache.calcite.sql.validate
Class SelectScope
- java.lang.Object
-
- org.apache.calcite.sql.validate.DelegatingScope
-
- org.apache.calcite.sql.validate.ListScope
-
- org.apache.calcite.sql.validate.SelectScope
-
- All Implemented Interfaces:
SqlValidatorScope
public class SelectScope extends ListScope
The name-resolution scope of a SELECT clause. The objects visible are those in the FROM clause, and objects inherited from the parent scope.This object is both a
SqlValidatorScope
and aSqlValidatorNamespace
. In the querySELECT name FROM ( SELECT * FROM emp WHERE gender = 'F')
we need to use the
SelectScope
as aSqlValidatorNamespace
when resolving 'name', and as aSqlValidatorScope
when resolving 'gender'.Scopes
In the query
SELECT expr1 FROM t1, t2, (SELECT expr2 FROM t3) AS q3 WHERE c1 IN (SELECT expr3 FROM t4) ORDER BY expr4
The scopes available at various points of the query are as follows:
- expr1 can see t1, t2, q3
- expr2 can see t3
- expr3 can see t4, t1, t2
- expr4 can see t1, t2, q3, plus (depending upon the dialect) any aliases defined in the SELECT clause
Namespaces
In the above query, there are 4 namespaces:
- t1
- t2
- (SELECT expr2 FROM t3) AS q3
- (SELECT expr3 FROM t4)
- See Also:
SelectNamespace
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.calcite.sql.validate.SqlValidatorScope
SqlValidatorScope.EmptyPath, SqlValidatorScope.Path, SqlValidatorScope.Resolve, SqlValidatorScope.Resolved, SqlValidatorScope.ResolvedImpl, SqlValidatorScope.Step
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<SqlNode>
expandedSelectList
private SqlNodeList
orderList
List of column names which sort this scope.private SqlSelect
select
protected java.util.List<java.lang.String>
windowNames
private SqlValidatorScope
windowParent
Scope to use to resolve windows-
Fields inherited from class org.apache.calcite.sql.validate.DelegatingScope
parent, validator
-
-
Constructor Summary
Constructors Constructor Description SelectScope(SqlValidatorScope parent, SqlValidatorScope winParent, SqlSelect select)
Creates a scope corresponding to a SELECT clause.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addWindowName(java.lang.String winName)
boolean
existingWindowName(java.lang.String winName)
java.util.List<SqlNode>
getExpandedSelectList()
SqlMonotonicity
getMonotonicity(SqlNode expr)
Returns whether an expression is monotonic in this scope.SqlSelect
getNode()
Returns the root node of this scope.SqlNodeList
getOrderList()
Returns the expressions by which the rows in this scope are sorted.SqlValidatorTable
getTable()
SqlWindow
lookupWindow(java.lang.String name)
Finds a window with a given name.void
setExpandedSelectList(java.util.List<SqlNode> selectList)
-
Methods inherited from class org.apache.calcite.sql.validate.ListScope
addChild, findAliases, findAllColumnNames, findQualifyingTableName, findQualifyingTableNames, getChildNames, getChildren, resolve, resolveColumn
-
Methods inherited from class org.apache.calcite.sql.validate.DelegatingScope
addColumnNames, fullyQualify, getOperandScope, getParent, getTableNamespace, getValidator, nullifyType, resolveInNamespace, resolveTable, validateExpr
-
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.SqlValidatorScope
isWithin
-
-
-
-
Field Detail
-
select
private final SqlSelect select
-
windowNames
protected final java.util.List<java.lang.String> windowNames
-
expandedSelectList
private java.util.List<SqlNode> expandedSelectList
-
orderList
private SqlNodeList orderList
List of column names which sort this scope. Empty if this scope is not sorted. Null if has not been computed yet.
-
windowParent
private final SqlValidatorScope windowParent
Scope to use to resolve windows
-
-
Constructor Detail
-
SelectScope
SelectScope(SqlValidatorScope parent, SqlValidatorScope winParent, SqlSelect select)
Creates a scope corresponding to a SELECT clause.- Parameters:
parent
- Parent scope, must not be nullwinParent
- Scope for window parent, may be nullselect
- Select clause
-
-
Method Detail
-
getTable
public SqlValidatorTable getTable()
-
getNode
public SqlSelect getNode()
Description copied from interface:SqlValidatorScope
Returns the root node of this scope. Never null.
-
lookupWindow
public SqlWindow lookupWindow(java.lang.String name)
Description copied from interface:SqlValidatorScope
Finds a window with a given name. Returns null if not found.- Specified by:
lookupWindow
in interfaceSqlValidatorScope
- Overrides:
lookupWindow
in classDelegatingScope
-
getMonotonicity
public SqlMonotonicity getMonotonicity(SqlNode expr)
Description copied from interface:SqlValidatorScope
Returns whether an expression is monotonic in this scope. For example, if the scope has previously been sorted by columns X, Y, then X is monotonic in this scope, but Y is not.- Specified by:
getMonotonicity
in interfaceSqlValidatorScope
- Overrides:
getMonotonicity
in classDelegatingScope
-
getOrderList
public SqlNodeList getOrderList()
Description copied from interface:SqlValidatorScope
Returns the expressions by which the rows in this scope are sorted. If the rows are unsorted, returns null.- Specified by:
getOrderList
in interfaceSqlValidatorScope
- Overrides:
getOrderList
in classDelegatingScope
-
addWindowName
public void addWindowName(java.lang.String winName)
-
existingWindowName
public boolean existingWindowName(java.lang.String winName)
-
getExpandedSelectList
public java.util.List<SqlNode> getExpandedSelectList()
-
setExpandedSelectList
public void setExpandedSelectList(java.util.List<SqlNode> selectList)
-
-