Search in sources :

Example 1 with SQLSubPartitionBy

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

the class MySqlCreateTableParser method partitionClauseRest.

protected void partitionClauseRest(SQLPartitionBy clause) {
    if (identifierEquals("PARTITIONS")) {
        lexer.nextToken();
        SQLIntegerExpr countExpr = this.exprParser.integerExpr();
        clause.setPartitionsCount(countExpr);
    }
    if (lexer.token() == Token.PARTITION) {
        lexer.nextToken();
        if (identifierEquals("NUM")) {
            lexer.nextToken();
        }
        clause.setPartitionsCount(this.exprParser.expr());
        clause.putAttribute("ads.partition", Boolean.TRUE);
    }
    if (identifierEquals("SUBPARTITION")) {
        lexer.nextToken();
        accept(Token.BY);
        SQLSubPartitionBy subPartitionByClause = null;
        boolean linear = false;
        if (identifierEquals("LINEAR")) {
            lexer.nextToken();
            linear = true;
        }
        if (lexer.token() == Token.KEY) {
            MySqlSubPartitionByKey subPartitionKey = new MySqlSubPartitionByKey();
            lexer.nextToken();
            if (linear) {
                clause.setLinear(true);
            }
            accept(Token.LPAREN);
            for (; ; ) {
                subPartitionKey.addColumn(this.exprParser.name());
                if (lexer.token() == Token.COMMA) {
                    lexer.nextToken();
                    continue;
                }
                break;
            }
            accept(Token.RPAREN);
            subPartitionByClause = subPartitionKey;
        } else if (identifierEquals("HASH")) {
            lexer.nextToken();
            SQLSubPartitionByHash subPartitionHash = new SQLSubPartitionByHash();
            if (linear) {
                clause.setLinear(true);
            }
            if (lexer.token() == Token.KEY) {
                lexer.nextToken();
                subPartitionHash.setKey(true);
            }
            accept(Token.LPAREN);
            subPartitionHash.setExpr(this.exprParser.expr());
            accept(Token.RPAREN);
            subPartitionByClause = subPartitionHash;
        } else if (identifierEquals("LIST")) {
            lexer.nextToken();
            MySqlSubPartitionByList subPartitionList = new MySqlSubPartitionByList();
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                SQLExpr expr = this.exprParser.expr();
                if (expr instanceof SQLIdentifierExpr && (identifierEquals("bigint") || identifierEquals("long"))) {
                    String dataType = lexer.stringVal();
                    lexer.nextToken();
                    SQLColumnDefinition column = this.exprParser.createColumnDefinition();
                    column.setName((SQLIdentifierExpr) expr);
                    column.setDataType(new SQLDataTypeImpl(dataType));
                    subPartitionList.addColumn(column);
                    subPartitionList.putAttribute("ads.subPartitionList", Boolean.TRUE);
                } else {
                    subPartitionList.setExpr(expr);
                }
                accept(Token.RPAREN);
            } else {
                acceptIdentifier("COLUMNS");
                accept(Token.LPAREN);
                for (; ; ) {
                    subPartitionList.addColumn(this.exprParser.parseColumn());
                    if (lexer.token() == Token.COMMA) {
                        lexer.nextToken();
                        continue;
                    }
                    break;
                }
                accept(Token.RPAREN);
            }
            subPartitionByClause = subPartitionList;
        }
        if (identifierEquals("SUBPARTITION")) {
            lexer.nextToken();
            acceptIdentifier("OPTIONS");
            accept(Token.LPAREN);
            SQLAssignItem option = this.exprParser.parseAssignItem();
            accept(Token.RPAREN);
            option.setParent(subPartitionByClause);
            subPartitionByClause.getOptions().add(option);
        }
        if (identifierEquals("SUBPARTITIONS")) {
            lexer.nextToken();
            Number intValue = lexer.integerValue();
            SQLNumberExpr numExpr = new SQLNumberExpr(intValue);
            subPartitionByClause.setSubPartitionsCount(numExpr);
            lexer.nextToken();
        }
        if (subPartitionByClause != null) {
            subPartitionByClause.setLinear(linear);
            clause.setSubPartitionBy(subPartitionByClause);
        }
    }
}
Also used : MySqlSubPartitionByList(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList) SQLSubPartitionByHash(com.alibaba.druid.sql.ast.SQLSubPartitionByHash) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLNumberExpr(com.alibaba.druid.sql.ast.expr.SQLNumberExpr) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLAssignItem(com.alibaba.druid.sql.ast.statement.SQLAssignItem) MySqlSubPartitionByKey(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByKey) SQLIntegerExpr(com.alibaba.druid.sql.ast.expr.SQLIntegerExpr) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl) SQLSubPartitionBy(com.alibaba.druid.sql.ast.SQLSubPartitionBy)

Example 2 with SQLSubPartitionBy

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

the class OracleCreateTableParser method parsePartitionByRest.

protected void parsePartitionByRest(SQLPartitionBy clause) {
    if (lexer.token() == Token.STORE) {
        lexer.nextToken();
        accept(Token.IN);
        accept(Token.LPAREN);
        for (; ; ) {
            SQLName tablespace = this.exprParser.name();
            clause.getStoreIn().add(tablespace);
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            }
            break;
        }
        accept(Token.RPAREN);
    }
    if (identifierEquals("SUBPARTITION")) {
        SQLSubPartitionBy subPartitionBy = subPartitionBy();
        clause.setSubPartitionBy(subPartitionBy);
    }
    accept(Token.LPAREN);
    for (; ; ) {
        SQLPartition partition = parsePartition();
        clause.addPartition(partition);
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        }
        break;
    }
    accept(Token.RPAREN);
}
Also used : SQLPartition(com.alibaba.druid.sql.ast.SQLPartition) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLSubPartitionBy(com.alibaba.druid.sql.ast.SQLSubPartitionBy)

Example 3 with SQLSubPartitionBy

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

the class MySqlOutputVisitor method visit.

public boolean visit(SQLVariantRefExpr x) {
    {
        int parametersSize = this.getParametersSize();
        int index = x.getIndex();
        if (index >= 0 && index < parametersSize) {
            return super.visit(x);
        }
    }
    String varName = x.getName();
    if (x.isGlobal()) {
        print0("@@global.");
    } else {
        if (// /
        (!varName.startsWith("@")) && //
        (!varName.equals("?")) && //
        (!varName.startsWith("#")) && //
        (!varName.startsWith("$")) && (!varName.startsWith(":"))) {
            boolean subPartitionOption = false;
            if (x.getParent() != null) {
                subPartitionOption = x.getParent().getParent() instanceof SQLSubPartitionBy;
            }
            if (!subPartitionOption) {
                print0("@@");
            }
        }
    }
    for (int i = 0; i < x.getName().length(); ++i) {
        char ch = x.getName().charAt(i);
        if (ch == '\'') {
            if (x.getName().startsWith("@@") && i == 2) {
                print(ch);
            } else if (x.getName().startsWith("@") && i == 1) {
                print(ch);
            } else if (i != 0 && i != x.getName().length() - 1) {
                print0("\\'");
            } else {
                print(ch);
            }
        } else {
            print(ch);
        }
    }
    String collate = (String) x.getAttribute("COLLATE");
    if (collate != null) {
        print0(ucase ? " COLLATE " : " collate ");
        print0(collate);
    }
    return false;
}
Also used : SQLSubPartitionBy(com.alibaba.druid.sql.ast.SQLSubPartitionBy) MySqlForceIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint) SQLCommentHint(com.alibaba.druid.sql.ast.SQLCommentHint) MySqlUseIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint) MySqlIgnoreIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)

Aggregations

SQLSubPartitionBy (com.alibaba.druid.sql.ast.SQLSubPartitionBy)3 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)1 SQLDataTypeImpl (com.alibaba.druid.sql.ast.SQLDataTypeImpl)1 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLPartition (com.alibaba.druid.sql.ast.SQLPartition)1 SQLSubPartitionByHash (com.alibaba.druid.sql.ast.SQLSubPartitionByHash)1 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)1 SQLNumberExpr (com.alibaba.druid.sql.ast.expr.SQLNumberExpr)1 SQLAssignItem (com.alibaba.druid.sql.ast.statement.SQLAssignItem)1 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)1 MySqlForceIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint)1 MySqlIgnoreIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)1 MySqlUseIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint)1 MySqlSubPartitionByKey (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByKey)1 MySqlSubPartitionByList (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSubPartitionByList)1