Search in sources :

Example 11 with SQLCharExpr

use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project Mycat_plus by coderczp.

the class GlobalTableUtil method addColumnIfCreate.

static String addColumnIfCreate(String sql, SQLStatement statement) {
    if (isCreate(statement) && sql.trim().toUpperCase().startsWith("CREATE TABLE ") && !hasGlobalColumn(statement)) {
        SQLColumnDefinition column = new SQLColumnDefinition();
        column.setDataType(new SQLCharacterDataType("bigint"));
        column.setName(new SQLIdentifierExpr(GLOBAL_TABLE_MYCAT_COLUMN));
        column.setComment(new SQLCharExpr("全局表保存修改时间戳的字段名"));
        ((SQLCreateTableStatement) statement).getTableElementList().add(column);
    }
    return statement.toString();
}
Also used : SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLCharacterDataType(com.alibaba.druid.sql.ast.statement.SQLCharacterDataType) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)

Example 12 with SQLCharExpr

use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project dble by actiontech.

the class DruidInsertReplaceParser method shardingValueToSting.

protected static String shardingValueToSting(SQLExpr valueExpr) throws SQLNonTransientException {
    String shardingValue = null;
    if (valueExpr instanceof SQLIntegerExpr) {
        SQLIntegerExpr intExpr = (SQLIntegerExpr) valueExpr;
        shardingValue = intExpr.getNumber() + "";
    } else if (valueExpr instanceof SQLCharExpr) {
        SQLCharExpr charExpr = (SQLCharExpr) valueExpr;
        shardingValue = charExpr.getText();
    }
    if (shardingValue == null) {
        throw new SQLNonTransientException("Not Supported of Sharding Value EXPR :" + valueExpr.toString());
    }
    return shardingValue;
}
Also used : SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLNonTransientException(java.sql.SQLNonTransientException) SQLIntegerExpr(com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)

Example 13 with SQLCharExpr

use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project dble by actiontech.

the class ItemFuncGroupConcat method toExpression.

@Override
public SQLExpr toExpression() {
    SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName());
    if (hasWithDistinct()) {
        aggregate.setOption(SQLAggregateOption.DISTINCT);
    }
    if (orders != null) {
        SQLOrderBy orderBy = new SQLOrderBy();
        for (Order order : orders) {
            SQLSelectOrderByItem orderItem = new SQLSelectOrderByItem(order.getItem().toExpression());
            orderItem.setType(order.getSortOrder());
            orderBy.addItem(orderItem);
        }
        aggregate.putAttribute(ItemFuncKeyWord.ORDER_BY, orderBy);
    }
    for (Item arg : args) {
        aggregate.addArgument(arg.toExpression());
    }
    if (seperator != null) {
        SQLCharExpr sep = new SQLCharExpr(seperator);
        aggregate.putAttribute(ItemFuncKeyWord.SEPARATOR, sep);
    }
    return aggregate;
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLOrderBy(com.alibaba.druid.sql.ast.SQLOrderBy) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLAggregateExpr(com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)

Example 14 with SQLCharExpr

use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project dble by actiontech.

the class GlobalTableUtil method createCheckColumn.

public static SQLColumnDefinition createCheckColumn() {
    SQLColumnDefinition column = new SQLColumnDefinition();
    column.setDataType(new SQLCharacterDataType("bigint"));
    column.setName(new SQLIdentifierExpr(GLOBAL_TABLE_CHECK_COLUMN));
    column.setComment(new SQLCharExpr("field for checking consistency"));
    return column;
}
Also used : SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLCharacterDataType(com.alibaba.druid.sql.ast.statement.SQLCharacterDataType) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)

Example 15 with SQLCharExpr

use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project Mycat-Server by MyCATApache.

the class MycatStatementParser method parseLoadDataInFile.

// 此处注释掉,以修正后端jdbc方式时,delete语句解析出错的情况
// 
// public SQLSelectParser createSQLSelectParser()
// {
// return new MycatSelectParser(this.selectExprParser);
// }
@Override
protected MySqlLoadDataInFileStatement parseLoadDataInFile() {
    acceptIdentifier("DATA");
    LoadDataStatement stmt = new LoadDataStatement();
    if (identifierEquals(LOW_PRIORITY)) {
        stmt.setLowPriority(true);
        lexer.nextToken();
    }
    if (identifierEquals("CONCURRENT")) {
        stmt.setConcurrent(true);
        lexer.nextToken();
    }
    if (identifierEquals(LOCAL)) {
        stmt.setLocal(true);
        lexer.nextToken();
    }
    acceptIdentifier("INFILE");
    SQLLiteralExpr fileName = (SQLLiteralExpr) exprParser.expr();
    stmt.setFileName(fileName);
    if (lexer.token() == Token.REPLACE) {
        stmt.setReplicate(true);
        lexer.nextToken();
    }
    if (identifierEquals(IGNORE)) {
        stmt.setIgnore(true);
        lexer.nextToken();
    }
    accept(Token.INTO);
    accept(Token.TABLE);
    SQLName tableName = exprParser.name();
    stmt.setTableName(tableName);
    if (identifierEquals(CHARACTER)) {
        lexer.nextToken();
        accept(Token.SET);
        if (lexer.token() != Token.LITERAL_CHARS) {
            throw new ParserException("syntax error, illegal charset");
        }
        String charset = lexer.stringVal();
        lexer.nextToken();
        stmt.setCharset(charset);
    }
    if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
        lexer.nextToken();
        if (identifierEquals("TERMINATED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setColumnsTerminatedBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
        if (identifierEquals("OPTIONALLY")) {
            stmt.setColumnsEnclosedOptionally(true);
            lexer.nextToken();
        }
        if (identifierEquals("ENCLOSED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setColumnsEnclosedBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
        if (identifierEquals("ESCAPED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setColumnsEscaped(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
    }
    if (identifierEquals("LINES")) {
        lexer.nextToken();
        if (identifierEquals("STARTING")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setLinesStartingBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
        if (identifierEquals("TERMINATED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setLinesTerminatedBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
    }
    if (identifierEquals(IGNORE)) {
        lexer.nextToken();
        stmt.setIgnoreLinesNumber(this.exprParser.expr());
        acceptIdentifier("LINES");
    }
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        this.exprParser.exprList(stmt.getColumns(), stmt);
        accept(Token.RPAREN);
    }
    if (lexer.token() == Token.SET) {
        lexer.nextToken();
        this.exprParser.exprList(stmt.getSetList(), stmt);
    }
    return stmt;
}
Also used : SQLLiteralExpr(com.alibaba.druid.sql.ast.expr.SQLLiteralExpr) SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLName(com.alibaba.druid.sql.ast.SQLName)

Aggregations

SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)37 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)16 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)15 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)8 SQLLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLLiteralExpr)8 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)8 SQLCharacterDataType (com.alibaba.druid.sql.ast.statement.SQLCharacterDataType)7 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)6 TableConfig (io.mycat.config.model.TableConfig)6 AbstractPartitionAlgorithm (io.mycat.route.function.AbstractPartitionAlgorithm)6 SlotFunction (io.mycat.route.function.SlotFunction)6 SQLNonTransientException (java.sql.SQLNonTransientException)6 ParserException (com.alibaba.druid.sql.parser.ParserException)5 SQLName (com.alibaba.druid.sql.ast.SQLName)4 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)4 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)4 RouteResultsetNode (io.mycat.route.RouteResultsetNode)4 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)3 SQLNCharExpr (com.alibaba.druid.sql.ast.expr.SQLNCharExpr)3