|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saffron.sql.SqlValidator
SqlValidator
validates the parse tree of a SQL statement, and
provides semantic information about the parse tree.
Nested Class Summary | |
static interface |
SqlValidator.CatalogReader
A CatalogReader supplies catalog information for a SqlValidator . |
class |
SqlValidator.IdentifierScope
|
(package private) class |
SqlValidator.JoinScope
The name-resolution scope of a JOIN operator. |
class |
SqlValidator.Scope
Name-resolution scope. |
class |
SqlValidator.SelectScope
The name-resolution scope of a SELECT clause. |
(package private) class |
SqlValidator.SetopScope
|
static interface |
SqlValidator.Table
A Table supplies a SqlValidator with the metadata
for a table. |
(package private) class |
SqlValidator.TableConstructorScope
|
Field Summary | |
private SqlValidator.CatalogReader |
catalogReader
|
static String[] |
emptyStrings
|
static SaffronType[] |
emptyTypes
|
private int |
nextGeneratedId
|
SqlOperatorTable |
opTab
|
private SqlNode |
outermostNode
|
private HashMap |
scopes
Maps query nodes to the scope created from
them . |
(package private) SaffronTypeFactory |
typeFactory
|
Constructor Summary | |
SqlValidator(SqlOperatorTable opTab,
SqlValidator.CatalogReader catalogReader,
SaffronTypeFactory typeFactory)
Creates a validator. |
Method Summary | |
private void |
addToSelectList(ArrayList list,
List aliases,
List types,
SqlNode exp,
SqlValidator.Scope scope)
Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list. |
void |
check(String s)
|
void |
checkFails(String s,
String message)
|
private SqlSelect |
createInternalSelect(SqlNode node,
boolean setOutermostNode)
|
private String |
deriveAlias(SqlNode node,
int ordinal)
Derives an alias for an expression. |
(package private) SaffronType |
deriveType(SqlValidator.Scope scope,
SqlNode operand)
|
private boolean |
expandSelectItem(SqlNode selectItem,
SqlSelect select,
ArrayList selectItems,
List aliases,
List types)
If selectItem is "*" or "TABLE.*", expands it and returns
true; otherwise writes the unexpanded item. |
SqlNodeList |
expandStar(SqlNodeList selectList,
SqlSelect query)
Returns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded. |
private SqlNode |
getChild(SqlSelect select,
String alias)
|
SqlNode |
getOutermostNode()
|
SqlValidator.Scope |
getScope(SqlNode node)
|
SqlValidator.SelectScope |
getScope(SqlSelect node)
|
private SaffronType |
getTableConstructorRowType(SqlCall values,
SqlValidator.Scope scope)
|
private boolean |
isStar(SqlNode selectItem)
Returns whether a select item is "*" or "TABLE.*". |
private static SaffronType |
lookupField(SaffronType rowType,
String columnName)
|
private RuntimeException |
newValidationError(String s)
|
private void |
register(SqlValidator.Scope scope,
boolean inFrom)
Registers a new scope. |
private void |
registerFrom(SqlValidator.Scope scope,
SqlNode node,
String alias)
|
private void |
registerQuery(SqlValidator.Scope scope,
SqlNode node,
String alias,
boolean inFrom)
|
private void |
registerSubqueries(SqlValidator.SelectScope selectScope,
SqlNode node)
|
void |
testCrossJoinOnFails()
|
void |
testCrossJoinUsingFails()
|
void |
testDoubleNoAlias()
|
void |
testDuplicateColumnAliasFails()
|
void |
testFromReferenceFails()
|
void |
testIncompatibleUnionFails()
|
void |
testInnerJoinWithoutUsingOrOnFails()
|
void |
testInTooManyColumnsFails()
|
void |
testInvalidGroupBy(TestCase test)
|
void |
testJoinUsingInvalidColsFails()
|
void |
testNaturalCrossJoinFails()
|
void |
testObscuredAliasFails()
|
void |
testSingleNoAlias()
|
void |
testUnionOfNonQueryFails()
|
void |
testWhereReference()
|
void |
validate(SqlNode topNode)
Validates a tree. |
private void |
validateDelete(SqlDelete call)
|
private void |
validateExpression(SqlNode node)
|
private void |
validateFrom(SqlNode node)
|
private void |
validateInsert(SqlInsert call)
|
void |
validateQuery(SqlNode node)
Checks that a query ( select statement, or a set operation
union , intersect , except ) is
valid. |
private void |
validateSelect(SqlSelect select)
|
private void |
validateValues(SqlCall node)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public final SqlOperatorTable opTab
private final SqlValidator.CatalogReader catalogReader
private HashMap scopes
query nodes
to the scope created from
them
.
private SqlNode outermostNode
private int nextGeneratedId
final SaffronTypeFactory typeFactory
public static final SaffronType[] emptyTypes
public static final String[] emptyStrings
Constructor Detail |
public SqlValidator(SqlOperatorTable opTab, SqlValidator.CatalogReader catalogReader, SaffronTypeFactory typeFactory)
Method Detail |
public SqlNode getOutermostNode()
public SqlValidator.SelectScope getScope(SqlSelect node)
public void check(String s)
public void checkFails(String s, String message)
public SqlNodeList expandStar(SqlNodeList selectList, SqlSelect query)
private boolean isStar(SqlNode selectItem)
private boolean expandSelectItem(SqlNode selectItem, SqlSelect select, ArrayList selectItems, List aliases, List types)
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 aliases
public void testDoubleNoAlias()
public void testDuplicateColumnAliasFails()
public void testInvalidGroupBy(TestCase test)
public void testSingleNoAlias()
public void testObscuredAliasFails()
public void testFromReferenceFails()
public void testWhereReference()
public void testIncompatibleUnionFails()
public void testUnionOfNonQueryFails()
public void testInTooManyColumnsFails()
public void testNaturalCrossJoinFails()
public void testCrossJoinUsingFails()
public void testCrossJoinOnFails()
public void testInnerJoinWithoutUsingOrOnFails()
public void testJoinUsingInvalidColsFails()
public void validate(SqlNode topNode)
public void validateQuery(SqlNode node)
select
statement, or a set operation
union
, intersect
, except
) is
valid.
RuntimeException
- if the query is not validpublic SqlValidator.Scope getScope(SqlNode node)
private SqlNode getChild(SqlSelect select, String alias)
private SqlSelect createInternalSelect(SqlNode node, boolean setOutermostNode)
private SaffronType getTableConstructorRowType(SqlCall values, SqlValidator.Scope scope)
SaffronType deriveType(SqlValidator.Scope scope, SqlNode operand)
private void addToSelectList(ArrayList list, List aliases, List types, SqlNode exp, SqlValidator.Scope scope)
private String deriveAlias(SqlNode node, int ordinal)
ordinal
is less than zero, otherwise generates an
alias EXPR$ordinal
.
private RuntimeException newValidationError(String s)
private void register(SqlValidator.Scope scope, boolean inFrom)
scope
- Scope to registerinFrom
- Whether the scope is in the FROM list of its parent. Only
scopes in the FROM list can be returned when resolving identifiers.private void registerFrom(SqlValidator.Scope scope, SqlNode node, String alias)
private void registerQuery(SqlValidator.Scope scope, SqlNode node, String alias, boolean inFrom)
private void registerSubqueries(SqlValidator.SelectScope selectScope, SqlNode node)
private void validateExpression(SqlNode node)
private void validateFrom(SqlNode node)
private void validateSelect(SqlSelect select)
private void validateInsert(SqlInsert call)
private void validateDelete(SqlDelete call)
private void validateValues(SqlCall node)
private static SaffronType lookupField(SaffronType rowType, String columnName)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |