Search in sources :

Example 1 with FlashbackQueryClause

use of com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause in project druid by alibaba.

the class OracleSelectParser method parseTableSourceQueryTableExpr.

private void parseTableSourceQueryTableExpr(OracleSelectTableReference tableReference) {
    tableReference.setExpr(this.exprParser.expr());
    {
        FlashbackQueryClause clause = flashback();
        tableReference.setFlashback(clause);
    }
    if (identifierEquals("SAMPLE")) {
        lexer.nextToken();
        SampleClause sample = new SampleClause();
        if (identifierEquals("BLOCK")) {
            sample.setBlock(true);
            lexer.nextToken();
        }
        accept(Token.LPAREN);
        this.exprParser.exprList(sample.getPercent(), sample);
        accept(Token.RPAREN);
        if (identifierEquals("SEED")) {
            lexer.nextToken();
            accept(Token.LPAREN);
            sample.setSeedValue(expr());
            accept(Token.RPAREN);
        }
        tableReference.setSampleClause(sample);
    }
    if (identifierEquals("PARTITION")) {
        lexer.nextToken();
        PartitionExtensionClause partition = new PartitionExtensionClause();
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            partition.setPartition(exprParser.name());
            accept(Token.RPAREN);
        } else {
            accept(Token.FOR);
            accept(Token.LPAREN);
            exprParser.names(partition.getFor());
            accept(Token.RPAREN);
        }
        tableReference.setPartition(partition);
    }
    if (identifierEquals("SUBPARTITION")) {
        lexer.nextToken();
        PartitionExtensionClause partition = new PartitionExtensionClause();
        partition.setSubPartition(true);
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            partition.setPartition(exprParser.name());
            accept(Token.RPAREN);
        } else {
            accept(Token.FOR);
            accept(Token.LPAREN);
            exprParser.names(partition.getFor());
            accept(Token.RPAREN);
        }
        tableReference.setPartition(partition);
    }
    if (identifierEquals("VERSIONS")) {
        lexer.nextToken();
        if (lexer.token() == Token.BETWEEN) {
            lexer.nextToken();
            VersionsFlashbackQueryClause clause = new VersionsFlashbackQueryClause();
            if (identifierEquals("SCN")) {
                clause.setType(AsOfFlashbackQueryClause.Type.SCN);
                lexer.nextToken();
            } else {
                acceptIdentifier("TIMESTAMP");
                clause.setType(AsOfFlashbackQueryClause.Type.TIMESTAMP);
            }
            SQLBinaryOpExpr binaryExpr = (SQLBinaryOpExpr) exprParser.expr();
            if (binaryExpr.getOperator() != SQLBinaryOperator.BooleanAnd) {
                throw new ParserException("syntax error : " + binaryExpr.getOperator());
            }
            clause.setBegin(binaryExpr.getLeft());
            clause.setEnd(binaryExpr.getRight());
            tableReference.setFlashback(clause);
        } else {
            throw new ParserException("TODO");
        }
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) FlashbackQueryClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause) AsOfFlashbackQueryClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause.AsOfFlashbackQueryClause) VersionsFlashbackQueryClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause.VersionsFlashbackQueryClause) SampleClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.SampleClause) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) VersionsFlashbackQueryClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause.VersionsFlashbackQueryClause) PartitionExtensionClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.PartitionExtensionClause)

Aggregations

SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 FlashbackQueryClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause)1 AsOfFlashbackQueryClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause.AsOfFlashbackQueryClause)1 VersionsFlashbackQueryClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.FlashbackQueryClause.VersionsFlashbackQueryClause)1 PartitionExtensionClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.PartitionExtensionClause)1 SampleClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.SampleClause)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1