To create an instance of the default validator implementation, call {@link SqlValidatorUtil#newValidator}.
The validator interface is an instance of the {@link org.eigenbase.util.Glossary#VISITOR_PATTERN visitor pattern}. Implementations of the {@link SqlNode#validate} method call the validateXxx
method appropriate to the kind of node: {@link SqlLiteral#validate(SqlValidator,SqlValidatorScope)} calls {@link #validateLiteral(org.eigenbase.sql.SqlLiteral)}; {@link SqlCall#validate(SqlValidator,SqlValidatorScope)} calls {@link #validateCall(SqlCall,SqlValidatorScope)}; and so forth.
The {@link SqlNode#validateExpr(SqlValidator,SqlValidatorScope)} methodis as {@link SqlNode#validate(SqlValidator,SqlValidatorScope)} but is calledwhen the node is known to be a scalar expression.
In order to resolve names to objects, the validator builds a map of the structure of the query. This map consists of two types of objects. A {@link SqlValidatorScope} describes the tables and columns accessible at aparticular point in the query; and a {@link SqlValidatorNamespace} is adescription of a data source used in a query.
There are different kinds of namespace for different parts of the query. for example {@link IdentifierNamespace} for table names, {@link SelectNamespace} for SELECT queries, {@link SetopNamespace} for UNION, EXCEPTand INTERSECT. A validator is allowed to wrap namespaces in other objects which implement {@link SqlValidatorNamespace}, so don't try to cast your namespace or use instanceof
; use {@link SqlValidatorNamespace#unwrap(Class)} and {@link SqlValidatorNamespace#isWrapperFor(Class)} instead.
The validator builds the map by making a quick scan over the query when the root {@link SqlNode} is first provided. Thereafter, it supplies thecorrect scope or namespace object when it calls validation methods.
The methods {@link #getSelectScope}, {@link #getFromScope}, {@link #getWhereScope}, {@link #getGroupScope}, {@link #getHavingScope}, {@link #getOrderScope} and {@link #getJoinScope} get the correct scope to resolvenames in a particular clause of a SQL statement.
|
|
|
|