Search in sources :

Example 1 with SQLSubPartition

use of com.alibaba.druid.sql.ast.SQLSubPartition 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 SQLSubPartition

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

the class OracleCreateTableParser method subPartitionBy.

protected SQLSubPartitionBy subPartitionBy() {
    lexer.nextToken();
    accept(Token.BY);
    if (identifierEquals("HASH")) {
        lexer.nextToken();
        accept(Token.LPAREN);
        SQLSubPartitionByHash byHash = new SQLSubPartitionByHash();
        SQLExpr expr = this.exprParser.expr();
        byHash.setExpr(expr);
        accept(Token.RPAREN);
        return byHash;
    } else if (identifierEquals("LIST")) {
        lexer.nextToken();
        accept(Token.LPAREN);
        SQLSubPartitionByList byList = new SQLSubPartitionByList();
        SQLName column = this.exprParser.name();
        byList.setColumn(column);
        accept(Token.RPAREN);
        if (identifierEquals("SUBPARTITION")) {
            lexer.nextToken();
            acceptIdentifier("TEMPLATE");
            accept(Token.LPAREN);
            for (; ; ) {
                SQLSubPartition subPartition = parseSubPartition();
                subPartition.setParent(byList);
                byList.getSubPartitionTemplate().add(subPartition);
                if (lexer.token() == Token.COMMA) {
                    lexer.nextToken();
                    continue;
                }
                break;
            }
            accept(Token.RPAREN);
        }
        return byList;
    }
    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
Also used : SQLSubPartitionByList(com.alibaba.druid.sql.ast.SQLSubPartitionByList) ParserException(com.alibaba.druid.sql.parser.ParserException) SQLSubPartition(com.alibaba.druid.sql.ast.SQLSubPartition) SQLSubPartitionByHash(com.alibaba.druid.sql.ast.SQLSubPartitionByHash) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 3 with SQLSubPartition

use of com.alibaba.druid.sql.ast.SQLSubPartition 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 4 with SQLSubPartition

use of com.alibaba.druid.sql.ast.SQLSubPartition 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

SQLSubPartition (com.alibaba.druid.sql.ast.SQLSubPartition)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)3 SQLName (com.alibaba.druid.sql.ast.SQLName)3 SQLPartitionValue (com.alibaba.druid.sql.ast.SQLPartitionValue)3 SQLPartition (com.alibaba.druid.sql.ast.SQLPartition)2 SQLSubPartitionByHash (com.alibaba.druid.sql.ast.SQLSubPartitionByHash)1 SQLSubPartitionByList (com.alibaba.druid.sql.ast.SQLSubPartitionByList)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1