Search in sources :

Example 1 with OdpsDescStmt

use of com.alibaba.druid.sql.dialect.odps.ast.OdpsDescStmt 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)

Example 2 with OdpsDescStmt

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

the class OdpsStatementParser method parseDescribe.

public OdpsDescStmt parseDescribe() {
    if (lexer.token() == Token.DESC || identifierEquals("DESCRIBE")) {
        lexer.nextToken();
    } else {
        throw new ParserException("expect DESC, actual " + lexer.token());
    }
    OdpsDescStmt stmt = new OdpsDescStmt();
    if (identifierEquals("ROLE")) {
        lexer.nextToken();
        stmt.setObjectType(SQLObjectType.ROLE);
    } else if (identifierEquals("PACKAGE")) {
        lexer.nextToken();
        stmt.setObjectType(SQLObjectType.PACKAGE);
    } else if (identifierEquals("INSTANCE")) {
        lexer.nextToken();
        stmt.setObjectType(SQLObjectType.INSTANCE);
    }
    stmt.setObject(this.exprParser.name());
    if (lexer.token() == Token.PARTITION) {
        lexer.nextToken();
        this.accept(Token.LPAREN);
        for (; ; ) {
            stmt.getPartition().add(this.exprParser.expr());
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            }
            if (lexer.token() == Token.RPAREN) {
                lexer.nextToken();
                break;
            }
        }
    }
    return stmt;
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OdpsDescStmt(com.alibaba.druid.sql.dialect.odps.ast.OdpsDescStmt)

Aggregations

OdpsDescStmt (com.alibaba.druid.sql.dialect.odps.ast.OdpsDescStmt)2 ParserException (com.alibaba.druid.sql.parser.ParserException)2 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 OdpsAddStatisticStatement (com.alibaba.druid.sql.dialect.odps.ast.OdpsAddStatisticStatement)1 OdpsAnalyzeTableStatement (com.alibaba.druid.sql.dialect.odps.ast.OdpsAnalyzeTableStatement)1 OdpsListStmt (com.alibaba.druid.sql.dialect.odps.ast.OdpsListStmt)1 OdpsReadStatement (com.alibaba.druid.sql.dialect.odps.ast.OdpsReadStatement)1 OdpsRemoveStatisticStatement (com.alibaba.druid.sql.dialect.odps.ast.OdpsRemoveStatisticStatement)1