Search in sources :

Example 1 with SQLUnionQueryTableSource

use of com.alibaba.druid.sql.ast.statement.SQLUnionQueryTableSource in project druid by alibaba.

the class SQLSelectParser method parseTableSource.

public SQLTableSource parseTableSource() {
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        SQLTableSource tableSource;
        if (lexer.token() == Token.SELECT || lexer.token() == Token.WITH || lexer.token == Token.SEL) {
            SQLSelect select = select();
            accept(Token.RPAREN);
            SQLSelectQuery query = queryRest(select.getQuery());
            if (query instanceof SQLUnionQuery) {
                tableSource = new SQLUnionQueryTableSource((SQLUnionQuery) query);
            } else {
                tableSource = new SQLSubqueryTableSource(select);
            }
        } else if (lexer.token() == Token.LPAREN) {
            tableSource = parseTableSource();
            accept(Token.RPAREN);
        } else {
            tableSource = parseTableSource();
            accept(Token.RPAREN);
        }
        return parseTableSourceRest(tableSource);
    }
    if (lexer.token() == Token.SELECT) {
        throw new ParserException("TODO");
    }
    SQLExprTableSource tableReference = new SQLExprTableSource();
    parseTableSourceQueryTableExpr(tableReference);
    SQLTableSource tableSrc = parseTableSourceRest(tableReference);
    if (lexer.hasComment() && lexer.isKeepComments()) {
        tableSrc.addAfterComment(lexer.readAndResetComments());
    }
    return tableSrc;
}
Also used : SQLSubqueryTableSource(com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) SQLUnionQueryTableSource(com.alibaba.druid.sql.ast.statement.SQLUnionQueryTableSource) SQLUnionQuery(com.alibaba.druid.sql.ast.statement.SQLUnionQuery) SQLSelectQuery(com.alibaba.druid.sql.ast.statement.SQLSelectQuery) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) SQLTableSource(com.alibaba.druid.sql.ast.statement.SQLTableSource)

Aggregations

SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)1 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)1 SQLSubqueryTableSource (com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource)1 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)1 SQLUnionQuery (com.alibaba.druid.sql.ast.statement.SQLUnionQuery)1 SQLUnionQueryTableSource (com.alibaba.druid.sql.ast.statement.SQLUnionQueryTableSource)1