Search in sources :

Example 21 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class OracleCreateTableParser method partitionByRange.

protected SQLPartitionByRange partitionByRange() {
    acceptIdentifier("RANGE");
    accept(Token.LPAREN);
    SQLPartitionByRange clause = new SQLPartitionByRange();
    for (; ; ) {
        SQLName column = this.exprParser.name();
        clause.addColumn(column);
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        }
        break;
    }
    accept(Token.RPAREN);
    if (lexer.token() == Token.INTERVAL) {
        lexer.nextToken();
        accept(Token.LPAREN);
        clause.setInterval(this.exprParser.expr());
        accept(Token.RPAREN);
    }
    parsePartitionByRest(clause);
    return clause;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLPartitionByRange(com.alibaba.druid.sql.ast.SQLPartitionByRange)

Example 22 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class OracleExprParser method name.

public SQLName name() {
    SQLName name = super.name();
    if (lexer.token() == Token.MONKEYS_AT) {
        lexer.nextToken();
        if (lexer.token() != Token.IDENTIFIER) {
            throw new ParserException("syntax error, expect identifier, but " + lexer.token());
        }
        OracleDbLinkExpr dbLink = new OracleDbLinkExpr();
        dbLink.setExpr(name);
        dbLink.setDbLink(lexer.stringVal());
        lexer.nextToken();
        return dbLink;
    }
    return name;
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLName(com.alibaba.druid.sql.ast.SQLName) OracleDbLinkExpr(com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDbLinkExpr)

Example 23 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class OracleExprParser method parseConstaint.

public OracleConstraint parseConstaint() {
    OracleConstraint constraint = (OracleConstraint) super.parseConstaint();
    for (; ; ) {
        if (lexer.token() == Token.EXCEPTIONS) {
            lexer.nextToken();
            accept(Token.INTO);
            SQLName exceptionsInto = this.name();
            constraint.setExceptionsInto(exceptionsInto);
            continue;
        }
        if (lexer.token() == Token.DISABLE) {
            lexer.nextToken();
            constraint.setEnable(false);
            continue;
        }
        if (lexer.token() == Token.ENABLE) {
            lexer.nextToken();
            constraint.setEnable(true);
            continue;
        }
        if (lexer.token() == Token.INITIALLY) {
            lexer.nextToken();
            if (lexer.token() == Token.IMMEDIATE) {
                lexer.nextToken();
                constraint.setInitially(Initially.IMMEDIATE);
            } else {
                accept(Token.DEFERRED);
                constraint.setInitially(Initially.DEFERRED);
            }
            continue;
        }
        if (lexer.token() == Token.NOT) {
            lexer.nextToken();
            if (identifierEquals("DEFERRABLE")) {
                lexer.nextToken();
                constraint.setDeferrable(false);
                continue;
            }
            throw new ParserException("TODO " + lexer.token());
        }
        if (identifierEquals("DEFERRABLE")) {
            lexer.nextToken();
            constraint.setDeferrable(true);
            continue;
        }
        break;
    }
    return constraint;
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLName(com.alibaba.druid.sql.ast.SQLName) OracleConstraint(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint)

Example 24 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class OdpsCreateTableParser method parseCrateTable.

public SQLCreateTableStatement parseCrateTable(boolean acceptCreate) {
    OdpsCreateTableStatement stmt = new OdpsCreateTableStatement();
    if (acceptCreate) {
        accept(Token.CREATE);
    }
    accept(Token.TABLE);
    if (lexer.token() == Token.IF || identifierEquals("IF")) {
        lexer.nextToken();
        accept(Token.NOT);
        accept(Token.EXISTS);
        stmt.setIfNotExiists(true);
    }
    stmt.setName(this.exprParser.name());
    if (identifierEquals("LIFECYCLE")) {
        lexer.nextToken();
        stmt.setLifecycle(this.exprParser.expr());
    }
    if (lexer.token() == Token.LIKE) {
        lexer.nextToken();
        SQLName name = this.exprParser.name();
        stmt.setLike(name);
    } else if (lexer.token() == Token.AS) {
        lexer.nextToken();
        OdpsSelectParser selectParser = new OdpsSelectParser(this.exprParser);
        SQLSelect select = selectParser.select();
        stmt.setSelect(select);
    } else {
        accept(Token.LPAREN);
        if (lexer.isKeepComments() && lexer.hasComment()) {
            stmt.addBodyBeforeComment(lexer.readAndResetComments());
        }
        for (; ; ) {
            if (lexer.token() != Token.IDENTIFIER) {
                throw new ParserException("expect identifier");
            }
            SQLColumnDefinition column = this.exprParser.parseColumn();
            stmt.getTableElementList().add(column);
            if (lexer.isKeepComments() && lexer.hasComment()) {
                column.addAfterComment(lexer.readAndResetComments());
            }
            if (!(lexer.token() == (Token.COMMA))) {
                break;
            } else {
                lexer.nextToken();
                if (lexer.isKeepComments() && lexer.hasComment()) {
                    column.addAfterComment(lexer.readAndResetComments());
                }
            }
        }
        accept(Token.RPAREN);
    }
    if (lexer.token() == Token.COMMENT) {
        lexer.nextToken();
        stmt.setComment(this.exprParser.primary());
    }
    if (lexer.token() == Token.PARTITIONED) {
        lexer.nextToken();
        accept(Token.BY);
        accept(Token.LPAREN);
        for (; ; ) {
            if (lexer.token() != Token.IDENTIFIER) {
                throw new ParserException("expect identifier");
            }
            SQLColumnDefinition column = this.exprParser.parseColumn();
            stmt.addPartitionColumn(column);
            if (lexer.isKeepComments() && lexer.hasComment()) {
                column.addAfterComment(lexer.readAndResetComments());
            }
            if (!(lexer.token() == (Token.COMMA))) {
                break;
            } else {
                lexer.nextToken();
                if (lexer.isKeepComments() && lexer.hasComment()) {
                    column.addAfterComment(lexer.readAndResetComments());
                }
            }
        }
        accept(Token.RPAREN);
    }
    if (identifierEquals("LIFECYCLE")) {
        lexer.nextToken();
        stmt.setLifecycle(this.exprParser.expr());
    }
    return stmt;
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) OdpsCreateTableStatement(com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)

Example 25 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class OdpsStatementParser method parseStatementListDialect.

public boolean parseStatementListDialect(List<SQLStatement> statementList) {
    if (lexer.token() == Token.FROM) {
        SQLStatement stmt = this.parseInsert();
        statementList.add(stmt);
        return true;
    }
    if (identifierEquals("ANALYZE")) {
        lexer.nextToken();
        accept(Token.TABLE);
        OdpsAnalyzeTableStatement stmt = new OdpsAnalyzeTableStatement();
        SQLName table = this.exprParser.name();
        stmt.setTable(table);
        if (lexer.token() == Token.PARTITION) {
            lexer.nextToken();
            accept(Token.LPAREN);
            parseAssignItems(stmt.getPartition(), stmt);
            accept(Token.RPAREN);
        }
        accept(Token.COMPUTE);
        acceptIdentifier("STATISTICS");
        statementList.add(stmt);
        return true;
    }
    if (identifierEquals("ADD")) {
        lexer.nextToken();
        if (identifierEquals("STATISTIC")) {
            lexer.nextToken();
            OdpsAddStatisticStatement stmt = new OdpsAddStatisticStatement();
            stmt.setTable(this.exprParser.name());
            stmt.setStatisticClause(parseStaticClause());
            statementList.add(stmt);
            return true;
        }
        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
    }
    if (identifierEquals("REMOVE")) {
        lexer.nextToken();
        if (identifierEquals("STATISTIC")) {
            lexer.nextToken();
            OdpsRemoveStatisticStatement stmt = new OdpsRemoveStatisticStatement();
            stmt.setTable(this.exprParser.name());
            stmt.setStatisticClause(parseStaticClause());
            statementList.add(stmt);
            return true;
        }
        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
    }
    if (identifierEquals("READ")) {
        lexer.nextToken();
        OdpsReadStatement stmt = new OdpsReadStatement();
        stmt.setTable(this.exprParser.name());
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            this.exprParser.names(stmt.getColumns(), stmt);
            accept(Token.RPAREN);
        }
        if (lexer.token() == Token.PARTITION) {
            lexer.nextToken();
            accept(Token.LPAREN);
            parseAssignItems(stmt.getPartition(), stmt);
            accept(Token.RPAREN);
        }
        if (lexer.token() == Token.LITERAL_INT) {
            stmt.setRowCount(this.exprParser.primary());
        }
        statementList.add(stmt);
        return true;
    }
    if (identifierEquals("LIST")) {
        OdpsListStmt stmt = new OdpsListStmt();
        lexer.nextToken();
        stmt.setObject(this.exprParser.expr());
        statementList.add(stmt);
        return true;
    }
    if (lexer.token() == Token.DESC || identifierEquals("DESCRIBE")) {
        OdpsDescStmt stmt = parseDescribe();
        statementList.add(stmt);
        return true;
    }
    return false;
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OdpsAddStatisticStatement(com.alibaba.druid.sql.dialect.odps.ast.OdpsAddStatisticStatement) OdpsReadStatement(com.alibaba.druid.sql.dialect.odps.ast.OdpsReadStatement) OdpsRemoveStatisticStatement(com.alibaba.druid.sql.dialect.odps.ast.OdpsRemoveStatisticStatement) OdpsDescStmt(com.alibaba.druid.sql.dialect.odps.ast.OdpsDescStmt) SQLName(com.alibaba.druid.sql.ast.SQLName) OdpsListStmt(com.alibaba.druid.sql.dialect.odps.ast.OdpsListStmt) OdpsAnalyzeTableStatement(com.alibaba.druid.sql.dialect.odps.ast.OdpsAnalyzeTableStatement) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLName (com.alibaba.druid.sql.ast.SQLName)102 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)33 TableStat (com.alibaba.druid.stat.TableStat)20 ParserException (com.alibaba.druid.sql.parser.ParserException)17 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)8 SQLObject (com.alibaba.druid.sql.ast.SQLObject)6 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)6 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)6 WallContext (com.alibaba.druid.wall.WallContext)6 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)5 WallSqlTableStat (com.alibaba.druid.wall.WallSqlTableStat)5 SQLPartition (com.alibaba.druid.sql.ast.SQLPartition)4 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)4 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)4 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)4 SQLTableElement (com.alibaba.druid.sql.ast.statement.SQLTableElement)4 SQLSubPartition (com.alibaba.druid.sql.ast.SQLSubPartition)3 SQLLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLLiteralExpr)3 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)3