Search in sources :

Example 1 with SQLPartitionValue

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

the class MySqlExprParser method parsePartition.

public SQLPartition parsePartition() {
    accept(Token.PARTITION);
    SQLPartition partitionDef = new SQLPartition();
    partitionDef.setName(this.name());
    SQLPartitionValue values = this.parsePartitionValues();
    if (values != null) {
        partitionDef.setValues(values);
    }
    for (; ; ) {
        boolean storage = false;
        if (identifierEquals("DATA")) {
            lexer.nextToken();
            acceptIdentifier("DIRECTORY");
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
            }
            partitionDef.setDataDirectory(this.expr());
        } else if (lexer.token() == Token.TABLESPACE) {
            lexer.nextToken();
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
            }
            SQLName tableSpace = this.name();
            partitionDef.setTableSpace(tableSpace);
        } else if (lexer.token() == Token.INDEX) {
            lexer.nextToken();
            acceptIdentifier("DIRECTORY");
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
            }
            partitionDef.setIndexDirectory(this.expr());
        } else if (identifierEquals("MAX_ROWS")) {
            lexer.nextToken();
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
            }
            SQLExpr maxRows = this.primary();
            partitionDef.setMaxRows(maxRows);
        } else if (identifierEquals("MIN_ROWS")) {
            lexer.nextToken();
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
            }
            SQLExpr minRows = this.primary();
            partitionDef.setMaxRows(minRows);
        } else if (//
        identifierEquals("ENGINE") || (storage = (lexer.token() == Token.STORAGE || identifierEquals("STORAGE")))) {
            if (storage) {
                lexer.nextToken();
            }
            acceptIdentifier("ENGINE");
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
            }
            SQLName engine = this.name();
            partitionDef.setEngine(engine);
        } else if (lexer.token() == Token.COMMENT) {
            lexer.nextToken();
            if (lexer.token() == Token.EQ) {
                lexer.nextToken();
            }
            SQLExpr comment = this.primary();
            partitionDef.setComment(comment);
        } else {
            break;
        }
    }
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        for (; ; ) {
            acceptIdentifier("SUBPARTITION");
            SQLName subPartitionName = this.name();
            SQLSubPartition subPartition = new SQLSubPartition();
            subPartition.setName(subPartitionName);
            partitionDef.addSubPartition(subPartition);
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            }
            break;
        }
        accept(Token.RPAREN);
    }
    return partitionDef;
}
Also used : SQLPartition(com.alibaba.druid.sql.ast.SQLPartition) SQLSubPartition(com.alibaba.druid.sql.ast.SQLSubPartition) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLPartitionValue(com.alibaba.druid.sql.ast.SQLPartitionValue) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 2 with SQLPartitionValue

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

the class OracleCreateTableParser method parsePartition.

protected SQLPartition parsePartition() {
    acceptIdentifier("PARTITION");
    SQLPartition partition = new SQLPartition();
    partition.setName(this.exprParser.name());
    SQLPartitionValue values = this.exprParser.parsePartitionValues();
    if (values != null) {
        partition.setValues(values);
    }
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        for (; ; ) {
            SQLSubPartition subPartition = parseSubPartition();
            partition.addSubPartition(subPartition);
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            }
            break;
        }
        accept(Token.RPAREN);
    } else if (identifierEquals("SUBPARTITIONS")) {
        lexer.nextToken();
        SQLExpr subPartitionsCount = this.exprParser.primary();
        partition.setSubPartitionsCount(subPartitionsCount);
    }
    return partition;
}
Also used : SQLPartition(com.alibaba.druid.sql.ast.SQLPartition) SQLSubPartition(com.alibaba.druid.sql.ast.SQLSubPartition) SQLPartitionValue(com.alibaba.druid.sql.ast.SQLPartitionValue) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 3 with SQLPartitionValue

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

the class OracleCreateTableParser method parseSubPartition.

protected SQLSubPartition parseSubPartition() {
    acceptIdentifier("SUBPARTITION");
    SQLSubPartition subPartition = new SQLSubPartition();
    SQLName name = this.exprParser.name();
    subPartition.setName(name);
    SQLPartitionValue values = this.exprParser.parsePartitionValues();
    if (values != null) {
        subPartition.setValues(values);
    }
    return subPartition;
}
Also used : SQLSubPartition(com.alibaba.druid.sql.ast.SQLSubPartition) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLPartitionValue(com.alibaba.druid.sql.ast.SQLPartitionValue)

Aggregations

SQLPartitionValue (com.alibaba.druid.sql.ast.SQLPartitionValue)3 SQLSubPartition (com.alibaba.druid.sql.ast.SQLSubPartition)3 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 SQLName (com.alibaba.druid.sql.ast.SQLName)2 SQLPartition (com.alibaba.druid.sql.ast.SQLPartition)2