|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.sql.validate.SqlValidatorImpl
public class SqlValidatorImpl
Default implementation of SqlValidator
.
Nested Class Summary | |
---|---|
private static class |
SqlValidatorImpl.DeleteNamespace
Namespace for a DELETE statement. |
private class |
SqlValidatorImpl.DeriveTypeVisitor
Visitor which derives the type of a given SqlNode . |
static class |
SqlValidatorImpl.DmlNamespace
Common base class for DML statement namespaces. |
private static class |
SqlValidatorImpl.Expander
Converts an expression into canonical form by fully-qualifying any identifiers. |
protected static class |
SqlValidatorImpl.FunctionParamInfo
Utility object used to maintain information about the parameters in a function call. |
protected static class |
SqlValidatorImpl.IdInfo
|
private static class |
SqlValidatorImpl.InsertNamespace
Namespace for an INSERT statement. |
private static class |
SqlValidatorImpl.MergeNamespace
Namespace for a MERGE statement. |
(package private) class |
SqlValidatorImpl.OrderExpressionExpander
Shuttle which walks over an expression in the ORDER BY clause, replacing usages of aliases with the underlying expression. |
static class |
SqlValidatorImpl.Status
Validation status. |
private static class |
SqlValidatorImpl.UpdateNamespace
Namespace for an UPDATE statement. |
Nested classes/interfaces inherited from interface org.eigenbase.sql.validate.SqlValidator |
---|
SqlValidator.Compatible |
Field Summary | |
---|---|
private AggFinder |
aggFinder
|
private AggFinder |
aggOrOverFinder
|
private RelDataType |
booleanType
|
(package private) SqlValidatorCatalogReader |
catalogReader
|
private SqlConformance |
conformance
|
private Map<SqlSelect,SqlValidatorScope> |
cursorScopes
Maps a SqlSelect node that is the argument to a CURSOR
constructor to the scope of the result of that select node |
private Set<SqlNode> |
cursorSet
Set of select expressions used as cursor definitions. |
protected boolean |
expandColumnReferences
|
protected boolean |
expandIdentifiers
|
protected Stack<SqlValidatorImpl.FunctionParamInfo> |
functionCallStack
Stack of objects that maintain information about function calls. |
protected Map<String,SqlValidatorImpl.IdInfo> |
idPositions
Maps ParsePosition strings to the SqlIdentifier identifier
objects at these positions |
protected Map<SqlNode,SqlValidatorNamespace> |
namespaces
Maps a node to the namespace which describes what columns they contain. |
private int |
nextGeneratedId
|
private Map<SqlNode,RelDataType> |
nodeToTypeMap
Map of derived RelDataType for each node. |
private SqlOperatorTable |
opTab
|
private Map<SqlSelect,SqlValidatorScope> |
orderScopes
Maps a SqlSelect node to the scope used by its ORDER BY clause. |
private Map<SqlNode,SqlNode> |
originalExprs
|
private boolean |
rewriteCalls
|
protected Map<SqlNode,SqlValidatorScope> |
scopes
Maps query node objects to the SqlValidatorScope
scope created from them}. |
private Map<SqlSelect,SqlValidatorScope> |
selectScopes
Maps a SqlSelect node to the scope used by its SELECT and HAVING
clauses. |
static Logger |
tracer
|
protected RelDataTypeFactory |
typeFactory
|
protected RelDataType |
unknownType
|
static String |
UPDATE_ANON_PREFIX
Alias prefix generated for source columns when rewriting UPDATE to MERGE. |
static String |
UPDATE_SRC_ALIAS
Alias generated for the source table when rewriting UPDATE to MERGE. |
static String |
UPDATE_TGT_ALIAS
Alias generated for the target table when rewriting UPDATE to MERGE if no alias was specified by the user. |
private boolean |
validatingSqlMerge
|
private Map<SqlSelect,SqlValidatorScope> |
whereScopes
Maps a SqlSelect node to the scope used by its WHERE and HAVING
clauses. |
Constructor Summary | |
---|---|
protected |
SqlValidatorImpl(SqlOperatorTable opTab,
SqlValidatorCatalogReader catalogReader,
RelDataTypeFactory typeFactory,
SqlConformance conformance)
Creates a validator. |
Method Summary | ||
---|---|---|
protected void |
addToSelectList(List<SqlNode> list,
List<String> aliases,
List<RelDataType> types,
SqlNode exp,
SqlValidatorScope scope,
boolean includeSystemVars)
Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list. |
|
private void |
checkFieldCount(SqlNode node,
RelDataType logicalSourceRowType,
RelDataType logicalTargetRowType)
|
|
protected void |
checkTypeAssignment(RelDataType sourceRowType,
RelDataType targetRowType,
SqlNode query)
|
|
protected SelectNamespace |
createSelectNamespace(SqlSelect select,
SqlNode enclosingNode)
Creates a namespace for a SELECT node. |
|
protected SetopNamespace |
createSetopNamespace(SqlCall call,
SqlNode enclosingNode)
Creates a namespace for a set operation ( UNION ,
INTERSECT , or EXCEPT ). |
|
protected SqlSelect |
createSourceSelectForDelete(SqlDelete call)
Creates the SELECT statement that putatively feeds rows into a DELETE statement to be deleted. |
|
protected SqlSelect |
createSourceSelectForUpdate(SqlUpdate call)
Creates the SELECT statement that putatively feeds rows into an UPDATE statement to be updated. |
|
protected RelDataType |
createTargetRowType(SqlValidatorTable table,
SqlNodeList targetColumnList,
boolean append)
Derives a row-type for INSERT and UPDATE operations. |
|
void |
declareCursor(SqlSelect select,
SqlValidatorScope parentScope)
Declares a SELECT expression as a cursor. |
|
String |
deriveAlias(SqlNode node,
int ordinal)
Derives an alias for an expression. |
|
RelDataType |
deriveConstructorType(SqlValidatorScope scope,
SqlCall call,
SqlFunction unresolvedConstructor,
SqlFunction resolvedConstructor,
RelDataType[] argTypes)
Derives the type of a constructor. |
|
RelDataType |
deriveType(SqlValidatorScope scope,
SqlNode expr)
Derives the type of a node in a given scope. |
|
(package private) RelDataType |
deriveTypeImpl(SqlValidatorScope scope,
SqlNode operand)
Derives the type of a node. |
|
SqlNode |
expand(SqlNode expr,
SqlValidatorScope scope)
Expands an expression. |
|
SqlNode |
expandOrderExpr(SqlSelect select,
SqlNode orderExpr)
Expands an expression in the ORDER BY clause into an expression with the same semantics as expressions in the SELECT clause. |
|
private boolean |
expandSelectItem(SqlNode selectItem,
SqlSelect select,
List<SqlNode> selectItems,
List<String> aliases,
List<RelDataType> types,
boolean includeSystemVars)
If selectItem is "*" or "TABLE.*", expands it and returns
true; otherwise writes the unexpanded item. |
|
SqlNodeList |
expandStar(SqlNodeList selectList,
SqlSelect select,
boolean includeSystemVars)
Returns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded. |
|
private static void |
findAllValidFunctionNames(List<String> names,
SqlValidator validator,
List<SqlMoniker> result,
SqlParserPos pos)
|
|
private static void |
findAllValidUdfNames(List<String> names,
SqlValidator validator,
List<SqlMoniker> result)
|
|
private static
|
firstDuplicate(List<T> list)
Returns the ordinal of the first element in the list which is equal to a previous element in the list. |
|
SqlValidatorCatalogReader |
getCatalogReader()
Returns the catalog reader used by this validator. |
|
SqlConformance |
getConformance()
Returns the dialect of SQL (SQL:2003, etc.) this validator recognizes. |
|
SqlValidatorScope |
getCursorScope(SqlSelect select)
|
|
SqlValidatorScope |
getFromScope(SqlSelect select)
Returns a scope containing the objects visible from the FROM clause of a query. |
|
SqlValidatorScope |
getGroupScope(SqlSelect select)
Returns a scope containing the objects visible from the GROUP BY clause of a query. |
|
SqlValidatorScope |
getHavingScope(SqlSelect select)
Returns a scope containing the objects visible from the HAVING clause of a query. |
|
SqlValidatorScope |
getJoinScope(SqlNode node)
Returns a scope containing the objects visible from the ON and USING sections of a JOIN clause. |
|
protected RelDataType |
getLogicalSourceRowType(RelDataType sourceRowType,
SqlInsert insert)
|
|
protected RelDataType |
getLogicalTargetRowType(RelDataType targetRowType,
SqlInsert insert)
|
|
SqlValidatorNamespace |
getNamespace(SqlNode node)
Finds the namespace corresponding to a given node. |
|
private SqlNode |
getNthExpr(SqlNode query,
int ordinal,
int sourceCount)
Locates the n'th expression in an INSERT or UPDATE query. |
|
SqlOperatorTable |
getOperatorTable()
Returns the operator table used by this validator. |
|
SqlValidatorScope |
getOrderScope(SqlSelect select)
Returns the scope that expressions in the SELECT and HAVING clause of this query should use. |
|
SqlNode |
getOriginal(SqlNode expr)
|
|
SqlValidatorScope |
getOverScope(SqlNode node)
|
|
String |
getParentCursor(String columnListParamName)
Retrieves the name of the parent cursor referenced by a column list parameter. |
|
SelectScope |
getRawSelectScope(SqlSelect select)
Returns the scope for resolving the SELECT, GROUP BY and HAVING clauses. |
|
SqlValidatorScope |
getScope(SqlSelect select,
int operandType)
Returns the appropriate scope for validating a particular clause of a SELECT statement. |
|
SqlValidatorScope |
getSelectScope(SqlSelect select)
Returns the appropriate scope for validating a particular clause of a SELECT statement. |
|
protected SqlNode |
getSelfJoinExprForUpdate(SqlIdentifier table,
String alias)
Allows a subclass to provide information about how to convert an UPDATE into a MERGE via self-join. |
|
(package private) RelDataType |
getTableConstructorRowType(SqlCall values,
SqlValidatorScope scope)
|
|
RelDataTypeFactory |
getTypeFactory()
Returns the type factory used by this validator. |
|
RelDataType |
getUnknownType()
Returns an object representing the "unknown" type. |
|
RelDataType |
getValidatedNodeType(SqlNode node)
Returns the type assigned to a node by validation. |
|
RelDataType |
getValidatedNodeTypeIfKnown(SqlNode node)
Returns the type assigned to a node by validation, or null if unknown. |
|
SqlValidatorScope |
getWhereScope(SqlSelect select)
Returns the scope that expressions in the WHERE and GROUP BY clause of this query should use. |
|
protected SqlWindow |
getWindowByName(SqlIdentifier id,
SqlValidatorScope scope)
|
|
private void |
handleScalarSubQuery(SqlSelect parentSelect,
SqlSelect selectItem,
List<SqlNode> expandedSelectItems,
List<String> aliasList,
List<RelDataType> typeList)
Processes SubQuery found in Select list. |
|
void |
handleUnresolvedFunction(SqlCall call,
SqlFunction unresolvedFunction,
RelDataType[] argTypes)
Handles a call to a function which cannot be resolved, throwing an appropriately descriptive error. |
|
protected void |
inferUnknownTypes(RelDataType inferredType,
SqlValidatorScope scope,
SqlNode node)
|
|
boolean |
isAggregate(SqlNode selectNode)
Returns whether a select list expression is an aggregate function. |
|
boolean |
isAggregate(SqlSelect select)
Returns whether a SELECT statement is an aggregation. |
|
boolean |
isSystemField(RelDataTypeField field)
Returns whether a field is a system field. |
|
(package private) SqlValidatorNamespace |
lookupFieldNamespace(RelDataType rowType,
String name)
|
|
private void |
lookupFromHints(SqlNode node,
SqlValidatorScope scope,
SqlParserPos pos,
List<SqlMoniker> hintList)
|
|
List<SqlMoniker> |
lookupHints(SqlNode topNode,
SqlParserPos pos)
Looks up completion hints for a syntatically correct SQL statement that has been parsed into an expression tree. |
|
private void |
lookupJoinHints(SqlJoin join,
SqlValidatorScope scope,
SqlParserPos pos,
List<SqlMoniker> hintList)
|
|
void |
lookupNameCompletionHints(SqlValidatorScope scope,
List<String> names,
SqlParserPos pos,
List<SqlMoniker> hintList)
Populates a list of all the valid alternatives for an identifier. |
|
SqlMoniker |
lookupQualifiedName(SqlNode topNode,
SqlParserPos pos)
Looks up the fully qualified name for a SqlIdentifier at a given
Parser Position in a parsed expression tree Note: call this only after
SqlValidator.validate(org.eigenbase.sql.SqlNode) has been called. |
|
(package private) void |
lookupSelectHints(SqlSelect select,
SqlParserPos pos,
List<SqlMoniker> hintList)
Looks up completion hints for a syntactically correct select SQL that has been parsed into an expression tree. |
|
private void |
lookupSelectHints(SqlValidatorNamespace ns,
SqlParserPos pos,
List<SqlMoniker> hintList)
|
|
EigenbaseException |
newValidationError(SqlNode node,
SqlValidatorException e)
Adds "line x, column y" context to a validator exception. |
|
protected SqlNode |
performUnconditionalRewrites(SqlNode node,
boolean underFrom)
Performs expression rewrites which are always used unconditionally. |
|
void |
popFunctionCall()
Removes the topmost entry from the function call stack. |
|
void |
pushFunctionCall()
Pushes a new instance of a function call on to a function call stack. |
|
private SqlNode |
registerFrom(SqlValidatorScope parentScope,
SqlValidatorScope usingScope,
SqlNode node,
SqlNode enclosingNode,
String alias,
boolean forceNullable)
Registers scopes and namespaces implied a relational expression in the FROM clause. |
|
protected void |
registerNamespace(SqlValidatorScope usingScope,
String alias,
SqlValidatorNamespace ns,
boolean forceNullable)
Registers a new namespace, and adds it as a child of its parent scope. |
|
private void |
registerOperandSubqueries(SqlValidatorScope parentScope,
SqlCall call,
int operandOrdinal)
Registers any subqueries inside a given call operand, and converts the operand to a scalar subquery if the operator requires it. |
|
private void |
registerQuery(SqlValidatorScope parentScope,
SqlValidatorScope usingScope,
SqlNode node,
SqlNode enclosingNode,
String alias,
boolean forceNullable)
Registers a query in a parent scope. |
|
private void |
registerQuery(SqlValidatorScope parentScope,
SqlValidatorScope usingScope,
SqlNode node,
SqlNode enclosingNode,
String alias,
boolean forceNullable,
boolean checkUpdate)
Registers a query in a parent scope. |
|
private void |
registerSetop(SqlValidatorScope parentScope,
SqlValidatorScope usingScope,
SqlNode node,
SqlNode enclosingNode,
String alias,
boolean forceNullable)
|
|
private void |
registerSubqueries(SqlValidatorScope parentScope,
SqlNode node)
|
|
void |
removeValidatedNodeType(SqlNode node)
Removes a node from the set of validated nodes |
|
SqlWindow |
resolveWindow(SqlNode windowOrRef,
SqlValidatorScope scope,
boolean populateBounds)
Converts a window specification or window name into a fully-resolved window specification. |
|
private void |
rewriteMerge(SqlMerge call)
|
|
private SqlNode |
rewriteUpdateToMerge(SqlUpdate updateCall,
SqlNode selfJoinSrcExpr)
|
|
void |
setCallRewrite(boolean rewriteCalls)
Enables or disables rewrite of "macro-like" calls such as COALESCE. |
|
void |
setColumnReferenceExpansion(boolean expandColumnReferences)
Enables or disables expansion of column references. |
|
void |
setIdentifierExpansion(boolean expandIdentifiers)
Enables or disables expansion of identifiers other than column references. |
|
void |
setOriginal(SqlNode expr,
SqlNode original)
|
|
void |
setValidatedNodeType(SqlNode node,
RelDataType type)
Saves the type of a SqlNode , now that it has been validated. |
|
(package private) void |
setValidatedNodeTypeImpl(SqlNode node,
RelDataType type)
|
|
protected boolean |
shouldAllowIntermediateOrderBy()
|
|
protected boolean |
shouldAllowOverRelation()
|
|
boolean |
shouldExpandIdentifiers()
Returns expansion of identifiers. |
|
SqlNode |
validate(SqlNode topNode)
Validates an expression tree. |
|
private void |
validateAccess(SqlNode node,
SqlValidatorTable table,
SqlAccessEnum requiredAccess)
Validates access to a table. |
|
void |
validateAggregateParams(SqlCall aggFunction,
SqlValidatorScope scope)
Validates parameters for aggregate function. |
|
void |
validateCall(SqlCall call,
SqlValidatorScope scope)
Validates a call to an operator. |
|
void |
validateColumnListParams(SqlFunction function,
RelDataType[] argTypes,
SqlNode[] operands)
Validates a COLUMN_LIST parameter |
|
void |
validateDataType(SqlDataTypeSpec dataType)
Validates a data type expression. |
|
void |
validateDelete(SqlDelete call)
Validates a DELETE statement. |
|
void |
validateDynamicParam(SqlDynamicParam dynamicParam)
Validates a dynamic parameter. |
|
private void |
validateExpr(SqlNode expr,
SqlValidatorScope scope)
Validates an expression. |
|
protected void |
validateFeature(org.eigenbase.resgen.ResourceDefinition feature,
SqlParserPos context)
Validates that a particular feature is enabled. |
|
protected void |
validateFrom(SqlNode node,
RelDataType targetRowType,
SqlValidatorScope scope)
Validates the FROM clause of a query, or (recursively) a child node of the FROM clause: AS, OVER, JOIN, VALUES, or subquery. |
|
protected void |
validateGroupClause(SqlSelect select)
Validates the GROUP BY clause of a SELECT statement. |
|
protected void |
validateHavingClause(SqlSelect select)
|
|
void |
validateIdentifier(SqlIdentifier id,
SqlValidatorScope scope)
Resolves an identifier to a fully-qualified name. |
|
void |
validateInsert(SqlInsert insert)
Validates an INSERT statement. |
|
void |
validateIntervalQualifier(SqlIntervalQualifier qualifier)
Validates a SqlIntervalQualifier |
|
protected void |
validateJoin(SqlJoin join,
SqlValidatorScope scope)
|
|
void |
validateLiteral(SqlLiteral literal)
Validates a literal. |
|
private void |
validateLiteralAsDouble(SqlLiteral literal)
|
|
void |
validateMerge(SqlMerge call)
Validates a MERGE statement. |
|
protected void |
validateNamespace(SqlValidatorNamespace namespace)
Validates a namespace. |
|
private void |
validateNoAggs(SqlNode condition,
String clause)
Throws an error if there is an aggregate or windowed aggregate in the given clause. |
|
private void |
validateNodeFeature(SqlNode node)
|
|
private void |
validateOrderItem(SqlSelect select,
SqlNode orderItem)
|
|
protected void |
validateOrderList(SqlSelect select)
Validates the ORDER BY clause of a SELECT statement. |
|
protected void |
validateOver(SqlCall call,
SqlValidatorScope scope)
|
|
SqlNode |
validateParameterizedExpression(SqlNode topNode,
Map<String,RelDataType> nameToTypeMap)
Validates an expression tree. |
|
void |
validateQuery(SqlNode node,
SqlValidatorScope scope)
Checks that a query is valid. |
|
private SqlNode |
validateScopedExpression(SqlNode topNode,
SqlValidatorScope scope)
|
|
protected void |
validateSelect(SqlSelect select,
RelDataType targetRowType)
Validates a SELECT statement. |
|
protected RelDataType |
validateSelectList(SqlNodeList selectItems,
SqlSelect select,
RelDataType targetRowType)
|
|
void |
validateUpdate(SqlUpdate call)
Validates an UPDATE statement. |
|
private RelDataType |
validateUsingCol(SqlIdentifier id,
SqlNode leftOrRight)
|
|
protected void |
validateValues(SqlCall node,
RelDataType targetRowType,
SqlValidatorScope scope)
Validates a VALUES clause. |
|
protected void |
validateWhereClause(SqlSelect select)
|
|
protected void |
validateWhereOrOn(SqlValidatorScope scope,
SqlNode condition,
String keyword)
|
|
void |
validateWindow(SqlNode windowOrId,
SqlValidatorScope scope,
SqlCall call)
Validates the right-hand side of an OVER expression. |
|
protected void |
validateWindowClause(SqlSelect select)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Logger tracer
public static final String UPDATE_SRC_ALIAS
public static final String UPDATE_TGT_ALIAS
public static final String UPDATE_ANON_PREFIX
private final SqlOperatorTable opTab
final SqlValidatorCatalogReader catalogReader
protected final Map<String,SqlValidatorImpl.IdInfo> idPositions
SqlIdentifier
identifier
objects at these positions
protected final Map<SqlNode,SqlValidatorScope> scopes
query node
objects to the SqlValidatorScope
scope created from them}.
private final Map<SqlSelect,SqlValidatorScope> whereScopes
SqlSelect
node to the scope used by its WHERE and HAVING
clauses.
private final Map<SqlSelect,SqlValidatorScope> selectScopes
SqlSelect
node to the scope used by its SELECT and HAVING
clauses.
private final Map<SqlSelect,SqlValidatorScope> orderScopes
SqlSelect
node to the scope used by its ORDER BY clause.
private final Map<SqlSelect,SqlValidatorScope> cursorScopes
SqlSelect
node that is the argument to a CURSOR
constructor to the scope of the result of that select node
protected final Map<SqlNode,SqlValidatorNamespace> namespaces
node
to the namespace
which describes what columns they contain.
private final Set<SqlNode> cursorSet
protected final Stack<SqlValidatorImpl.FunctionParamInfo> functionCallStack
private int nextGeneratedId
protected final RelDataTypeFactory typeFactory
protected final RelDataType unknownType
private final RelDataType booleanType
private final Map<SqlNode,RelDataType> nodeToTypeMap
private final AggFinder aggFinder
private final AggFinder aggOrOverFinder
private final SqlConformance conformance
private final Map<SqlNode,SqlNode> originalExprs
protected boolean expandIdentifiers
protected boolean expandColumnReferences
private boolean rewriteCalls
private boolean validatingSqlMerge
Constructor Detail |
---|
protected SqlValidatorImpl(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlConformance conformance)
opTab
- Operator tablecatalogReader
- Catalog readertypeFactory
- Type factoryconformance
- Compatibility modeMethod Detail |
---|
public SqlConformance getConformance()
SqlValidator
SqlConformance.Default
.
getConformance
in interface SqlValidator
public SqlValidatorCatalogReader getCatalogReader()
SqlValidator
getCatalogReader
in interface SqlValidator
public SqlOperatorTable getOperatorTable()
SqlValidator
getOperatorTable
in interface SqlValidator
public RelDataTypeFactory getTypeFactory()
SqlValidator
getTypeFactory
in interface SqlValidator
public RelDataType getUnknownType()
SqlValidator
getUnknownType
in interface SqlValidator
public SqlNodeList expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
SqlValidator
expandStar
in interface SqlValidator
selectList
- Select clause to be expandedselect
- QueryincludeSystemVars
- Whether to include system variables
public void declareCursor(SqlSelect select, SqlValidatorScope parentScope)
SqlValidator
declareCursor
in interface SqlValidator
select
- select expression associated with the cursorparentScope
- scope of the parent query associated with the cursorpublic void pushFunctionCall()
SqlValidator
pushFunctionCall
in interface SqlValidator
public void popFunctionCall()
SqlValidator
popFunctionCall
in interface SqlValidator
public String getParentCursor(String columnListParamName)
SqlValidator
getParentCursor
in interface SqlValidator
columnListParamName
- name of the column list parameter
private boolean expandSelectItem(SqlNode selectItem, SqlSelect select, List<SqlNode> selectItems, List<String> aliases, List<RelDataType> types, boolean includeSystemVars)
selectItem
is "*" or "TABLE.*", expands it and returns
true; otherwise writes the unexpanded item.
selectItem
- Select-list itemselect
- Containing select clauseselectItems
- List that expanded items are written toaliases
- List of aliasestypes
- List of data types in alias orderincludeSystemVars
- If true include system vars in lists
public SqlNode validate(SqlNode topNode)
SqlValidator
validate
in interface SqlValidator
topNode
- top of expression tree to be validated
public List<SqlMoniker> lookupHints(SqlNode topNode, SqlParserPos pos)
SqlValidatorWithHints
SqlValidator.validate(org.eigenbase.sql.SqlNode)
.
lookupHints
in interface SqlValidatorWithHints
topNode
- top of expression tree in which to lookup completion hintspos
- indicates the position in the sql statement we want to get
completion hints for. For example, "select a.ename, b.deptno from
sales.emp a join sales.dept b "on a.deptno=b.deptno where empno=1";
setting pos to 'Line 1, Column 17' returns all the possible column names
that can be selected from sales.dept table setting pos to 'Line 1, Column
31' returns all the possible table names in 'sales' schema
SqlMoniker
(sql identifiers) that can fill in
at the indicated positionpublic SqlMoniker lookupQualifiedName(SqlNode topNode, SqlParserPos pos)
SqlValidatorWithHints
SqlIdentifier
at a given
Parser Position in a parsed expression tree Note: call this only after
SqlValidator.validate(org.eigenbase.sql.SqlNode)
has been called.
lookupQualifiedName
in interface SqlValidatorWithHints
topNode
- top of expression tree in which to lookup the qualfied
name for the SqlIdentifierpos
- indicates the position of the SqlIdentifier
in the sql
statement we want to get the qualified name for
SqlIdentifier
if the Parser position represents a valid SqlIdentifier
. Else
return an empty stringvoid lookupSelectHints(SqlSelect select, SqlParserPos pos, List<SqlMoniker> hintList)
select
- the Select node of the parsed expression treepos
- indicates the position in the sql statement we want to get
completion hints forhintList
- list of SqlMoniker
(sql identifiers) that can
fill in at the indicated positionprivate void lookupSelectHints(SqlValidatorNamespace ns, SqlParserPos pos, List<SqlMoniker> hintList)
private void lookupFromHints(SqlNode node, SqlValidatorScope scope, SqlParserPos pos, List<SqlMoniker> hintList)
private void lookupJoinHints(SqlJoin join, SqlValidatorScope scope, SqlParserPos pos, List<SqlMoniker> hintList)
public final void lookupNameCompletionHints(SqlValidatorScope scope, List<String> names, SqlParserPos pos, List<SqlMoniker> hintList)
scope
- Validation scopenames
- Components of the identifierpos
- positionhintList
- a list of valid optionsprivate static void findAllValidUdfNames(List<String> names, SqlValidator validator, List<SqlMoniker> result)
private static void findAllValidFunctionNames(List<String> names, SqlValidator validator, List<SqlMoniker> result, SqlParserPos pos)
public SqlNode validateParameterizedExpression(SqlNode topNode, Map<String,RelDataType> nameToTypeMap)
SqlValidator
validateParameterizedExpression
in interface SqlValidator
topNode
- top of expression tree to be validatednameToTypeMap
- map of simple name to RelDataType
; used to
resolve SqlIdentifier
references
private SqlNode validateScopedExpression(SqlNode topNode, SqlValidatorScope scope)
public void validateQuery(SqlNode node, SqlValidatorScope scope)
SqlValidator
Valid queries include:
SELECT
statement,
UNION
, INTERSECT
,
EXCEPT
)
AS
operator
validateQuery
in interface SqlValidator
node
- Query nodescope
- Scope in which the query occursprotected void validateNamespace(SqlValidatorNamespace namespace)
public SqlValidatorScope getCursorScope(SqlSelect select)
public SqlValidatorScope getWhereScope(SqlSelect select)
SqlValidator
getWhereScope
in interface SqlValidator
select
- Query
public SqlValidatorScope getSelectScope(SqlSelect select)
SqlValidator
Consider
SELECT *
FROM foo
WHERE EXISTS (
SELECT deptno AS x
FROM emp
JOIN dept ON emp.deptno = dept.deptno
WHERE emp.deptno = 5
GROUP BY deptno
ORDER BY x)
What objects can be seen in each part of the sub-query?
SqlValidator.getFromScope(org.eigenbase.sql.SqlSelect)
, you can only see 'foo'.
SqlValidator.getWhereScope(org.eigenbase.sql.SqlSelect)
), GROUP BY (SqlValidator.getGroupScope(org.eigenbase.sql.SqlSelect)
),
SELECT (SqlValidator.getSelectScope(org.eigenbase.sql.SqlSelect)
), and the ON clause of the JOIN (SqlValidator.getJoinScope(org.eigenbase.sql.SqlNode)
) you can see 'emp', 'dept', and 'foo'.
SqlValidator.getOrderScope(org.eigenbase.sql.SqlSelect)
), you can see the column alias
'x'; and tables 'emp', 'dept', and 'foo'.
getSelectScope
in interface SqlValidator
select
- SELECT statement
public SelectScope getRawSelectScope(SqlSelect select)
SqlValidator
SelectScope
; if this is an aggregation query, the AggregatingScope
is stripped away.
getRawSelectScope
in interface SqlValidator
select
- SELECT statement
public SqlValidatorScope getHavingScope(SqlSelect select)
SqlValidator
getHavingScope
in interface SqlValidator
select
- SELECT statement
public SqlValidatorScope getGroupScope(SqlSelect select)
SqlValidator
getGroupScope
in interface SqlValidator
select
- SELECT statement
public SqlValidatorScope getFromScope(SqlSelect select)
SqlValidator
getFromScope
in interface SqlValidator
select
- SELECT statement
public SqlValidatorScope getOrderScope(SqlSelect select)
SqlValidator
getOrderScope
in interface SqlValidator
select
- SELECT statement
public SqlValidatorScope getJoinScope(SqlNode node)
SqlValidator
getJoinScope
in interface SqlValidator
node
- The item in the FROM clause which contains the ON or USING
expression
SqlValidator.getFromScope(org.eigenbase.sql.SqlSelect)
public SqlValidatorScope getOverScope(SqlNode node)
public SqlValidatorScope getScope(SqlSelect select, int operandType)
Consider SELECT * FROM foo WHERE EXISTS ( SELECT deptno AS x FROM emp, dept WHERE emp.deptno = 5 GROUP BY deptno ORDER BY x) In FROM, you can only see 'foo'. In WHERE, GROUP BY and SELECT, you can see 'emp', 'dept', and 'foo'. In ORDER BY, you can see the column alias 'x', 'emp', 'dept', and 'foo'.
public SqlValidatorNamespace getNamespace(SqlNode node)
SqlValidator
For example, in the query SELECT * FROM (SELECT * FROM t), t1 AS
alias
, the both items in the FROM clause have a corresponding
namespace.
getNamespace
in interface SqlValidator
node
- Parse tree node
protected SqlNode performUnconditionalRewrites(SqlNode node, boolean underFrom)
node
- expression to be rewrittenunderFrom
- whether node appears directly under a FROM clause
private void rewriteMerge(SqlMerge call)
private SqlNode rewriteUpdateToMerge(SqlUpdate updateCall, SqlNode selfJoinSrcExpr)
protected SqlNode getSelfJoinExprForUpdate(SqlIdentifier table, String alias)
table
- identifier for table being updatedalias
- alias to use for qualifying columns in expression, or null
for unqualified references; if this is equal to "SYS$SRC", then column references have been anonymized to
"SYS$ANONx", where x is the 1-based column number.
protected SqlSelect createSourceSelectForUpdate(SqlUpdate call)
call
- Call to the UPDATE operator
protected SqlSelect createSourceSelectForDelete(SqlDelete call)
call
- Call to the DELETE operator
RelDataType getTableConstructorRowType(SqlCall values, SqlValidatorScope scope)
public RelDataType getValidatedNodeType(SqlNode node)
SqlValidator
getValidatedNodeType
in interface SqlValidator
node
- the node of interest
public RelDataType getValidatedNodeTypeIfKnown(SqlNode node)
SqlValidator
SqlValidator.getValidatedNodeType(org.eigenbase.sql.SqlNode)
instead.
getValidatedNodeTypeIfKnown
in interface SqlValidator
node
- the node of interest
public void setValidatedNodeType(SqlNode node, RelDataType type)
SqlValidator
SqlNode
, now that it has been validated.
setValidatedNodeType
in interface SqlValidator
node
- A SQL parse tree nodetype
- Its type; must not be nullpublic void removeValidatedNodeType(SqlNode node)
SqlValidator
removeValidatedNodeType
in interface SqlValidator
node
- node to be removedvoid setValidatedNodeTypeImpl(SqlNode node, RelDataType type)
public RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
SqlValidator
deriveType
in interface SqlValidator
scope
- Syntactic scopeexpr
- Parse tree node
NULL
RelDataType deriveTypeImpl(SqlValidatorScope scope, SqlNode operand)
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, RelDataType[] argTypes)
SqlValidator
deriveConstructorType
in interface SqlValidator
scope
- Scopecall
- CallunresolvedConstructor
- TODOresolvedConstructor
- TODOargTypes
- Types of arguments
public void handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, RelDataType[] argTypes)
SqlValidator
handleUnresolvedFunction
in interface SqlValidator
call
- CallunresolvedFunction
- Overloaded function which is the target of the
callargTypes
- Types of argumentsprotected void inferUnknownTypes(RelDataType inferredType, SqlValidatorScope scope, SqlNode node)
protected void addToSelectList(List<SqlNode> list, List<String> aliases, List<RelDataType> types, SqlNode exp, SqlValidatorScope scope, boolean includeSystemVars)
public String deriveAlias(SqlNode node, int ordinal)
SqlValidator
ordinal
is less than zero, otherwise generates an
alias EXPR$ordinal
.
deriveAlias
in interface SqlValidator
node
- Expressionordinal
- Ordinal of expression
public void setIdentifierExpansion(boolean expandIdentifiers)
SqlValidator
setIdentifierExpansion
in interface SqlValidator
expandIdentifiers
- new settingpublic void setColumnReferenceExpansion(boolean expandColumnReferences)
SqlValidator
setColumnReferenceExpansion
in interface SqlValidator
expandColumnReferences
- new settingpublic void setCallRewrite(boolean rewriteCalls)
SqlValidator
setCallRewrite
in interface SqlValidator
rewriteCalls
- new settingpublic boolean shouldExpandIdentifiers()
SqlValidator
shouldExpandIdentifiers
in interface SqlValidator
protected boolean shouldAllowIntermediateOrderBy()
protected void registerNamespace(SqlValidatorScope usingScope, String alias, SqlValidatorNamespace ns, boolean forceNullable)
usingScope
- Parent scope (which will want to look for things in
this namespace)alias
- Alias by which parent will refer to this namespacens
- NamespaceforceNullable
- Whether to force the type of namespace to beprivate SqlNode registerFrom(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
parentScope
and usingScope
are often the same. They
differ when the namespace are not visible within the parent. (Example
needed.)
Likewise, enclosingNode
and node
are often the same.
enclosingNode
is the topmost node within the FROM clause, from
which any decorations like an alias (AS alias
) or a table
sample clause are stripped away to get node
. Both are recorded in
the namespace.
parentScope
- Parent scope which this scope turns to in order to
resolve objectsusingScope
- Scope whose child list this scope should add itself tonode
- Node which namespace is based onenclosingNode
- Outermost node for namespace, including decorations
such as alias and sample clausealias
- AliasforceNullable
- Whether to force the type of namespace to be
nullable because it is in an outer join
node
protected boolean shouldAllowOverRelation()
protected SelectNamespace createSelectNamespace(SqlSelect select, SqlNode enclosingNode)
SELECT
node. Derived class may
override this factory method.
select
- Select nodeenclosingNode
- Enclosing node
protected SetopNamespace createSetopNamespace(SqlCall call, SqlNode enclosingNode)
UNION
,
INTERSECT
, or EXCEPT
). Derived class may override
this factory method.
call
- Call to set operationenclosingNode
- Enclosing node
private void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
parentScope
- Parent scope which this scope turns to in order to
resolve objectsusingScope
- Scope whose child list this scope should add itself tonode
- Query nodealias
- Name of this query within its parent. Must be specified if
usingScope != nullprivate void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable, boolean checkUpdate)
parentScope
- Parent scope which this scope turns to in order to
resolve objectsusingScope
- Scope whose child list this scope should add itself tonode
- Query nodealias
- Name of this query within its parent. Must be specified if
usingScope != nullcheckUpdate
- if true, validate that the update feature is supported
if validating the update statementprivate void registerSetop(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
public boolean isAggregate(SqlSelect select)
SqlValidator
SUM(x) OVER w
, don't count.)
isAggregate
in interface SqlValidator
select
- SELECT statement
public boolean isAggregate(SqlNode selectNode)
SqlValidator
isAggregate
in interface SqlValidator
selectNode
- Expression in SELECT clause
private void validateNodeFeature(SqlNode node)
private void registerSubqueries(SqlValidatorScope parentScope, SqlNode node)
private void registerOperandSubqueries(SqlValidatorScope parentScope, SqlCall call, int operandOrdinal)
parentScope
- Parent scopecall
- CalloperandOrdinal
- Ordinal of operand within callSqlOperator.argumentMustBeScalar(int)
public void validateIdentifier(SqlIdentifier id, SqlValidatorScope scope)
SqlValidator
validateIdentifier
in interface SqlValidator
id
- Identifierscope
- Naming scopepublic void validateLiteral(SqlLiteral literal)
SqlValidator
validateLiteral
in interface SqlValidator
literal
- Literalprivate void validateLiteralAsDouble(SqlLiteral literal)
public void validateIntervalQualifier(SqlIntervalQualifier qualifier)
SqlValidator
SqlIntervalQualifier
validateIntervalQualifier
in interface SqlValidator
qualifier
- Interval qualifierprotected void validateFrom(SqlNode node, RelDataType targetRowType, SqlValidatorScope scope)
node
- Node in FROM clause, typically a table or derived tabletargetRowType
- Desired row type of this expression, or unknownType
if not fussy. Must not be null.scope
- Scopeprotected void validateOver(SqlCall call, SqlValidatorScope scope)
protected void validateJoin(SqlJoin join, SqlValidatorScope scope)
private void validateNoAggs(SqlNode condition, String clause)
condition
- Parse treeclause
- Name of clause: "WHERE", "GROUP BY", "ON"private RelDataType validateUsingCol(SqlIdentifier id, SqlNode leftOrRight)
protected void validateSelect(SqlSelect select, RelDataType targetRowType)
select
- Select statementtargetRowType
- Desired row type, must not be null, may be the data
type 'unknown'.private static <T> int firstDuplicate(List<T> list)
For example, firstDuplicate(Arrays.asList("a", "b", "c", "b",
"a"))
returns 3, the ordinal of the 2nd "b".
list
- List
protected void validateWindowClause(SqlSelect select)
protected void validateOrderList(SqlSelect select)
select
- Select statementprivate void validateOrderItem(SqlSelect select, SqlNode orderItem)
public SqlNode expandOrderExpr(SqlSelect select, SqlNode orderExpr)
SqlValidator
This is made necessary by a couple of dialect 'features':
expandOrderExpr
in interface SqlValidator
select
- Select statement which contains ORDER BYorderExpr
- Expression in the ORDER BY clause.
protected void validateGroupClause(SqlSelect select)
protected void validateWhereClause(SqlSelect select)
protected void validateWhereOrOn(SqlValidatorScope scope, SqlNode condition, String keyword)
protected void validateHavingClause(SqlSelect select)
protected RelDataType validateSelectList(SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType)
private void validateExpr(SqlNode expr, SqlValidatorScope scope)
expr
- Expressionscope
- Scope in which expression occursprivate void handleScalarSubQuery(SqlSelect parentSelect, SqlSelect selectItem, List<SqlNode> expandedSelectItems, List<String> aliasList, List<RelDataType> typeList)
parentSelect
- base SqlSelect itemselectItem
- child SqlSelect from select listexpandedSelectItems
- Select items after processingaliasList
- built from user or system valuestypeList
- Built up entries for each select list entryprotected RelDataType createTargetRowType(SqlValidatorTable table, SqlNodeList targetColumnList, boolean append)
table
- Target table for INSERT/UPDATEtargetColumnList
- List of target columns, or null if not specifiedappend
- Whether to append fields to those in
baseRowType
public void validateInsert(SqlInsert insert)
SqlValidator
validateInsert
in interface SqlValidator
insert
- INSERT statementprivate void checkFieldCount(SqlNode node, RelDataType logicalSourceRowType, RelDataType logicalTargetRowType)
protected RelDataType getLogicalTargetRowType(RelDataType targetRowType, SqlInsert insert)
protected RelDataType getLogicalSourceRowType(RelDataType sourceRowType, SqlInsert insert)
protected void checkTypeAssignment(RelDataType sourceRowType, RelDataType targetRowType, SqlNode query)
private SqlNode getNthExpr(SqlNode query, int ordinal, int sourceCount)
query
- Queryordinal
- Ordinal of expressionsourceCount
- Number of expressions
public void validateDelete(SqlDelete call)
SqlValidator
validateDelete
in interface SqlValidator
call
- DELETE statementpublic void validateUpdate(SqlUpdate call)
SqlValidator
validateUpdate
in interface SqlValidator
call
- UPDATE statementpublic void validateMerge(SqlMerge call)
SqlValidator
validateMerge
in interface SqlValidator
call
- MERGE statementprivate void validateAccess(SqlNode node, SqlValidatorTable table, SqlAccessEnum requiredAccess)
table
- TablerequiredAccess
- Access requested on tableprotected void validateValues(SqlCall node, RelDataType targetRowType, SqlValidatorScope scope)
node
- Values clausetargetRowType
- Row type which expression must conform toscope
- Scope within which clause occurspublic void validateDataType(SqlDataTypeSpec dataType)
SqlValidator
validateDataType
in interface SqlValidator
dataType
- Data typepublic void validateDynamicParam(SqlDynamicParam dynamicParam)
SqlValidator
validateDynamicParam
in interface SqlValidator
dynamicParam
- Dynamic parameterpublic EigenbaseException newValidationError(SqlNode node, SqlValidatorException e)
SqlValidator
Note that the input exception is checked (it derives from Exception
) and the output exception is unchecked (it derives from RuntimeException
). This is intentional -- it should remind code authors
to provide context for their validation errors.
newValidationError
in interface SqlValidator
node
- The place where the exception occurrede
- The validation error
protected SqlWindow getWindowByName(SqlIdentifier id, SqlValidatorScope scope)
public SqlWindow resolveWindow(SqlNode windowOrRef, SqlValidatorScope scope, boolean populateBounds)
SqlValidator
SELECT sum(x) OVER (PARTITION
BY x ORDER BY y), sum(y) OVER w1, sum(z) OVER (w ORDER BY y) FROM t
WINDOW w AS (PARTITION BY x)
all aggregations have the same
resolved window specification (PARTITION BY x ORDER BY y)
.
resolveWindow
in interface SqlValidator
windowOrRef
- Either the name of a window (a SqlIdentifier
)
or a window specification (a SqlWindow
).scope
- Scope in which to resolve window namespopulateBounds
- Whether to populate bounds. Doing so may alter the
definition of the window. It is recommended that populate bounds when
translating to physical algebra, but not when validating.
public SqlNode getOriginal(SqlNode expr)
public void setOriginal(SqlNode expr, SqlNode original)
SqlValidatorNamespace lookupFieldNamespace(RelDataType rowType, String name)
public void validateWindow(SqlNode windowOrId, SqlValidatorScope scope, SqlCall call)
SqlValidator
identifier
referencing a window, or an inline window specification
.
validateWindow
in interface SqlValidator
windowOrId
- SqlNode that can be either SqlWindow with all the
components of a window spec or a SqlIdentifier with the name of a window
spec.scope
- Naming scopecall
- is the SqlNode if a function call if the window is attached
to one.public void validateAggregateParams(SqlCall aggFunction, SqlValidatorScope scope)
SqlValidator
validateAggregateParams
in interface SqlValidator
aggFunction
- function containing COLUMN_LIST parameterscope
- Syntactic scopepublic void validateCall(SqlCall call, SqlValidatorScope scope)
SqlValidator
validateCall
in interface SqlValidator
call
- Operator callscope
- Naming scopeprotected void validateFeature(org.eigenbase.resgen.ResourceDefinition feature, SqlParserPos context)
feature
- feature being used, represented as a resource definition
from EigenbaseResource
context
- parser position context for error reporting, or null if
none availablepublic SqlNode expand(SqlNode expr, SqlValidatorScope scope)
SqlValidator
expand
in interface SqlValidator
expr
- Expressionscope
- Scope
public boolean isSystemField(RelDataTypeField field)
SqlValidator
In the default implementation, always returns false
.
isSystemField
in interface SqlValidator
field
- Field
public void validateColumnListParams(SqlFunction function, RelDataType[] argTypes, SqlNode[] operands)
SqlValidator
validateColumnListParams
in interface SqlValidator
function
- function containing COLUMN_LIST parameterargTypes
- function argumentsoperands
- operands passed into the function call
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |