Search in sources :

Example 1 with OdpsInsert

use of com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert in project druid by alibaba.

the class OdpsStatementParser method parseOdpsInsert.

public OdpsInsert parseOdpsInsert() {
    OdpsInsert insert = new OdpsInsert();
    if (lexer.isKeepComments() && lexer.hasComment()) {
        insert.addBeforeComment(lexer.readAndResetComments());
    }
    SQLSelectParser selectParser = createSQLSelectParser();
    accept(Token.INSERT);
    if (lexer.token() == Token.INTO) {
        lexer.nextToken();
    } else {
        accept(Token.OVERWRITE);
        insert.setOverwrite(true);
    }
    accept(Token.TABLE);
    insert.setTableSource(this.exprParser.name());
    if (lexer.token() == Token.PARTITION) {
        lexer.nextToken();
        accept(Token.LPAREN);
        for (; ; ) {
            SQLAssignItem ptExpr = new SQLAssignItem();
            ptExpr.setTarget(this.exprParser.name());
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
                SQLExpr ptValue = this.exprParser.expr();
                ptExpr.setValue(ptValue);
            }
            insert.addPartition(ptExpr);
            if (!(lexer.token() == (Token.COMMA))) {
                break;
            } else {
                lexer.nextToken();
            }
        }
        accept(Token.RPAREN);
    }
    SQLSelect query = selectParser.select();
    insert.setQuery(query);
    return insert;
}
Also used : SQLAssignItem(com.alibaba.druid.sql.ast.statement.SQLAssignItem) SQLSelectParser(com.alibaba.druid.sql.parser.SQLSelectParser) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) OdpsInsert(com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 2 with OdpsInsert

use of com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert in project druid by alibaba.

the class OdpsStatementParser method parseInsert.

public SQLStatement parseInsert() {
    OdpsInsertStatement stmt = new OdpsInsertStatement();
    if (lexer.token() == Token.FROM) {
        lexer.nextToken();
        if (lexer.token() == Token.IDENTIFIER) {
            SQLName tableName = this.exprParser.name();
            SQLExprTableSource from = new SQLExprTableSource(tableName);
            stmt.setFrom(from);
        } else {
            accept(Token.LPAREN);
            SQLSelectParser selectParser = createSQLSelectParser();
            SQLSelect select = selectParser.select();
            accept(Token.RPAREN);
            String alias = lexer.stringVal();
            accept(Token.IDENTIFIER);
            SQLSubqueryTableSource from = new SQLSubqueryTableSource(select, alias);
            stmt.setFrom(from);
        }
    }
    for (; ; ) {
        OdpsInsert insert = parseOdpsInsert();
        stmt.addItem(insert);
        if (lexer.token() != Token.INSERT) {
            break;
        }
    }
    return stmt;
}
Also used : SQLSubqueryTableSource(com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource) SQLSelectParser(com.alibaba.druid.sql.parser.SQLSelectParser) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) OdpsInsert(com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert) OdpsInsertStatement(com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement)

Aggregations

SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)2 OdpsInsert (com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert)2 SQLSelectParser (com.alibaba.druid.sql.parser.SQLSelectParser)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLAssignItem (com.alibaba.druid.sql.ast.statement.SQLAssignItem)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1 SQLSubqueryTableSource (com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource)1 OdpsInsertStatement (com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement)1