Search in sources :

Example 66 with SQLExpr

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

the class OdpsSchemaStatVisitor method visit.

@Override
public boolean visit(OdpsInsert x) {
    setMode(x, TableStat.Mode.Insert);
    setAliasMap();
    SQLExprTableSource tableSource = x.getTableSource();
    SQLExpr tableName = tableSource.getExpr();
    if (tableName instanceof SQLName) {
        String ident = ((SQLName) tableName).toString();
        setCurrentTable(ident);
        TableStat stat = getTableStat(ident);
        stat.incrementInsertCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, tableSource.getAlias(), ident);
        putAliasMap(aliasMap, ident, ident);
    }
    for (SQLAssignItem partition : x.getPartitions()) {
        partition.accept(this);
    }
    accept(x.getQuery());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 67 with SQLExpr

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

the class MySqlOutputVisitor method visit.

@Override
public boolean visit(MySqlAlterUserStatement x) {
    print0(ucase ? "ALTER USER" : "alter user");
    for (SQLExpr user : x.getUsers()) {
        print(' ');
        user.accept(this);
        print0(ucase ? " PASSWORD EXPIRE" : " password expire");
    }
    return false;
}
Also used : SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 68 with SQLExpr

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

the class PhoenixStatementParser method parseInsertColumns.

@Override
protected void parseInsertColumns(SQLInsertInto insert) {
    if (lexer.token() == Token.RPAREN) {
        return;
    }
    for (; ; ) {
        SQLName expr = this.exprParser.name();
        expr.setParent(insert);
        insert.getColumns().add(expr);
        if (lexer.token() == Token.IDENTIFIER) {
            String text = lexer.stringVal();
            if (text.equalsIgnoreCase("TINYINT") || text.equalsIgnoreCase("BIGINT") || text.equalsIgnoreCase("INTEGER") || text.equalsIgnoreCase("DOUBLE") || text.equalsIgnoreCase("DATE") || text.equalsIgnoreCase("VARCHAR")) {
                expr.getAttributes().put("dataType", text);
                lexer.nextToken();
            } else if (text.equalsIgnoreCase("CHAR")) {
                String dataType = text;
                lexer.nextToken();
                accept(Token.LPAREN);
                SQLExpr char_len = this.exprParser.primary();
                accept(Token.RPAREN);
                dataType += ("(" + char_len.toString() + ")");
                expr.getAttributes().put("dataType", dataType);
            }
        }
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        }
        break;
    }
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 69 with SQLExpr

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

the class PGExprParser method primary.

public SQLExpr primary() {
    if (lexer.token() == Token.ARRAY) {
        SQLArrayExpr array = new SQLArrayExpr();
        array.setExpr(new SQLIdentifierExpr(lexer.stringVal()));
        lexer.nextToken();
        accept(Token.LBRACKET);
        this.exprList(array.getValues(), array);
        accept(Token.RBRACKET);
        return primaryRest(array);
    } else if (lexer.token() == Token.POUND) {
        lexer.nextToken();
        if (lexer.token() == Token.LBRACE) {
            lexer.nextToken();
            String varName = lexer.stringVal();
            lexer.nextToken();
            accept(Token.RBRACE);
            SQLVariantRefExpr expr = new SQLVariantRefExpr("#{" + varName + "}");
            return primaryRest(expr);
        } else {
            SQLExpr value = this.primary();
            SQLUnaryExpr expr = new SQLUnaryExpr(SQLUnaryOperator.Pound, value);
            return primaryRest(expr);
        }
    }
    return super.primary();
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) SQLUnaryExpr(com.alibaba.druid.sql.ast.expr.SQLUnaryExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLArrayExpr(com.alibaba.druid.sql.ast.expr.SQLArrayExpr)

Example 70 with SQLExpr

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

the class PGSQLStatementParser method parseAlterColumn.

protected SQLAlterTableAlterColumn parseAlterColumn() {
    if (lexer.token() == Token.COLUMN) {
        lexer.nextToken();
    }
    SQLColumnDefinition column = this.exprParser.parseColumn();
    SQLAlterTableAlterColumn alterColumn = new SQLAlterTableAlterColumn();
    alterColumn.setColumn(column);
    if (column.getDataType() == null && column.getConstraints().size() == 0) {
        if (lexer.token() == Token.SET) {
            lexer.nextToken();
            if (lexer.token() == Token.NOT) {
                lexer.nextToken();
                accept(Token.NULL);
                alterColumn.setSetNotNull(true);
            } else {
                accept(Token.DEFAULT);
                SQLExpr defaultValue = this.exprParser.expr();
                alterColumn.setSetDefault(defaultValue);
            }
        } else if (lexer.token() == Token.DROP) {
            lexer.nextToken();
            if (lexer.token() == Token.NOT) {
                lexer.nextToken();
                accept(Token.NULL);
                alterColumn.setDropNotNull(true);
            } else {
                accept(Token.DEFAULT);
                alterColumn.setDropDefault(true);
            }
        }
    }
    return alterColumn;
}
Also used : SQLAlterTableAlterColumn(com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)225 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)42 SQLName (com.alibaba.druid.sql.ast.SQLName)33 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)30 ParserException (com.alibaba.druid.sql.parser.ParserException)23 SQLObject (com.alibaba.druid.sql.ast.SQLObject)22 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)17 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)16 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)13 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)13 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)12 ArrayList (java.util.ArrayList)12 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)11 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)10 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)10 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)10 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)8 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)8 SQLNumberExpr (com.alibaba.druid.sql.ast.expr.SQLNumberExpr)7 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)7