Search in sources :

Example 1 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class MySQLDMLReplaceParser method replace.

/**
 * nothing has been pre-consumed <code><pre>
 * 'REPLACE' ('LOW_PRIORITY' | 'DELAYED')? ('INTO')? tableName
 *  (  'SET' colName ('='|':=') (expr|'DEFAULT') (',' colName ('='|':=') (expr|'DEFAULT'))*
 *   | '(' (  colName (','colName)* ')' (  '(' 'SELECT' ... ')'
 *                                       | 'SELECT' ...
 *                                       |('VALUES'|'VALUE') value ( ',' value )*
 *                                      )
 *          | 'SELECT' ... ')'
 *         )
 *   | 'SELECT' ...
 *   |('VALUES'|'VALUE') value ( ',' value )*
 *  )
 * value := '(' (expr|'DEFAULT') ( ',' (expr|'DEFAULT'))* ')'
 * </pre></code>
 */
public DMLReplaceStatement replace() throws SQLSyntaxErrorException {
    match(KW_REPLACE);
    DMLReplaceStatement.ReplaceMode mode = DMLReplaceStatement.ReplaceMode.UNDEF;
    switch(lexer.token()) {
        case KW_LOW_PRIORITY:
            lexer.nextToken();
            mode = DMLReplaceStatement.ReplaceMode.LOW;
            break;
        case KW_DELAYED:
            lexer.nextToken();
            mode = DMLReplaceStatement.ReplaceMode.DELAY;
            break;
    }
    if (lexer.token() == KW_INTO) {
        lexer.nextToken();
    }
    Identifier table = identifier();
    List<Identifier> columnNameList;
    List<RowExpression> rowList;
    QueryExpression select;
    List<Expression> tempRowValue;
    switch(lexer.token()) {
        case KW_SET:
            lexer.nextToken();
            columnNameList = new LinkedList<Identifier>();
            tempRowValue = new LinkedList<Expression>();
            for (; ; lexer.nextToken()) {
                Identifier id = identifier();
                match(OP_EQUALS, OP_ASSIGN);
                Expression expr = exprParser.expression();
                columnNameList.add(id);
                tempRowValue.add(expr);
                if (lexer.token() != PUNC_COMMA) {
                    break;
                }
            }
            rowList = new ArrayList<RowExpression>(1);
            rowList.add(new RowExpression(tempRowValue));
            return new DMLReplaceStatement(mode, table, columnNameList, rowList);
        case IDENTIFIER:
            if (!"VALUE".equals(lexer.stringValueUppercase())) {
                break;
            }
        case KW_VALUES:
            lexer.nextToken();
            columnNameList = null;
            rowList = rowList();
            return new DMLReplaceStatement(mode, table, columnNameList, rowList);
        case KW_SELECT:
            columnNameList = null;
            select = select();
            return new DMLReplaceStatement(mode, table, columnNameList, select);
        case PUNC_LEFT_PAREN:
            switch(lexer.nextToken()) {
                case PUNC_LEFT_PAREN:
                case KW_SELECT:
                    columnNameList = null;
                    select = selectPrimary();
                    match(PUNC_RIGHT_PAREN);
                    return new DMLReplaceStatement(mode, table, columnNameList, select);
            }
            columnNameList = idList();
            match(PUNC_RIGHT_PAREN);
            switch(lexer.token()) {
                case PUNC_LEFT_PAREN:
                case KW_SELECT:
                    select = selectPrimary();
                    return new DMLReplaceStatement(mode, table, columnNameList, select);
                case KW_VALUES:
                    lexer.nextToken();
                    break;
                default:
                    matchIdentifier("VALUE");
            }
            rowList = rowList();
            return new DMLReplaceStatement(mode, table, columnNameList, rowList);
    }
    throw err("unexpected token for replace: " + lexer.token());
}
Also used : DMLReplaceStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLReplaceStatement) Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) Expression(com.alibaba.cobar.parser.ast.expression.Expression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)

Example 2 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class MySQLDMLParser method tableFactor.

private TableReference tableFactor() throws SQLSyntaxErrorException {
    String alias = null;
    switch(lexer.token()) {
        case PUNC_LEFT_PAREN:
            lexer.nextToken();
            Object ref = trsOrQuery();
            match(PUNC_RIGHT_PAREN);
            if (ref instanceof QueryExpression) {
                alias = as();
                return new SubqueryFactor((QueryExpression) ref, alias);
            }
            return (TableReferences) ref;
        case IDENTIFIER:
            Identifier table = identifier();
            alias = as();
            List<IndexHint> hintList = hintList();
            return new TableRefFactor(table, alias, hintList);
        default:
            throw err("unexpected token for tableFactor: " + lexer.token());
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) IndexHint(com.alibaba.cobar.parser.ast.fragment.tableref.IndexHint) SubqueryFactor(com.alibaba.cobar.parser.ast.fragment.tableref.SubqueryFactor) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) TableRefFactor(com.alibaba.cobar.parser.ast.fragment.tableref.TableRefFactor) TableReferences(com.alibaba.cobar.parser.ast.fragment.tableref.TableReferences)

Example 3 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class MySQLExprParser method primaryExpression.

private Expression primaryExpression(final String consumed, String consumedUp) throws SQLSyntaxErrorException {
    if (consumed != null) {
        return startedFromIdentifier(consumed, consumedUp);
    }
    String tempStr;
    String tempStrUp;
    StringBuilder tempSb;
    Number tempNum;
    Expression tempExpr;
    Expression tempExpr2;
    List<Expression> tempExprList;
    switch(lexer.token()) {
        case PLACE_HOLDER:
            tempStr = lexer.stringValue();
            tempStrUp = lexer.stringValueUppercase();
            lexer.nextToken();
            return createPlaceHolder(tempStr, tempStrUp);
        case LITERAL_BIT:
            tempStr = lexer.stringValue();
            lexer.nextToken();
            return new LiteralBitField(null, tempStr).setCacheEvalRst(cacheEvalRst);
        case LITERAL_HEX:
            LiteralHexadecimal hex = new LiteralHexadecimal(null, lexer.getSQL(), lexer.getOffsetCache(), lexer.getSizeCache(), charset);
            lexer.nextToken();
            return hex.setCacheEvalRst(cacheEvalRst);
        case LITERAL_BOOL_FALSE:
            lexer.nextToken();
            return new LiteralBoolean(false).setCacheEvalRst(cacheEvalRst);
        case LITERAL_BOOL_TRUE:
            lexer.nextToken();
            return new LiteralBoolean(true).setCacheEvalRst(cacheEvalRst);
        case LITERAL_NULL:
            lexer.nextToken();
            return new LiteralNull().setCacheEvalRst(cacheEvalRst);
        case LITERAL_NCHARS:
            tempSb = new StringBuilder();
            do {
                lexer.appendStringContent(tempSb);
            } while (lexer.nextToken() == LITERAL_CHARS);
            return new LiteralString(null, tempSb.toString(), true).setCacheEvalRst(cacheEvalRst);
        case LITERAL_CHARS:
            tempSb = new StringBuilder();
            do {
                lexer.appendStringContent(tempSb);
            } while (lexer.nextToken() == LITERAL_CHARS);
            return new LiteralString(null, tempSb.toString(), false).setCacheEvalRst(cacheEvalRst);
        case LITERAL_NUM_PURE_DIGIT:
            tempNum = lexer.integerValue();
            lexer.nextToken();
            return new LiteralNumber(tempNum).setCacheEvalRst(cacheEvalRst);
        case LITERAL_NUM_MIX_DIGIT:
            tempNum = lexer.decimalValue();
            lexer.nextToken();
            return new LiteralNumber(tempNum).setCacheEvalRst(cacheEvalRst);
        case QUESTION_MARK:
            int index = lexer.paramIndex();
            lexer.nextToken();
            return createParam(index);
        case KW_CASE:
            lexer.nextToken();
            return caseWhenExpression();
        case KW_INTERVAL:
            lexer.nextToken();
            return intervalExpression();
        case KW_EXISTS:
            lexer.nextToken();
            match(PUNC_LEFT_PAREN);
            tempExpr = subQuery();
            match(PUNC_RIGHT_PAREN);
            return new ExistsPrimary((QueryExpression) tempExpr).setCacheEvalRst(cacheEvalRst);
        case USR_VAR:
            tempStr = lexer.stringValue();
            tempExpr = new UsrDefVarPrimary(tempStr).setCacheEvalRst(cacheEvalRst);
            if (lexer.nextToken() == OP_ASSIGN) {
                lexer.nextToken();
                tempExpr2 = expression();
                return new AssignmentExpression(tempExpr, tempExpr2);
            }
            return tempExpr;
        case SYS_VAR:
            return systemVariale();
        case KW_MATCH:
            lexer.nextToken();
            return matchExpression();
        case PUNC_LEFT_PAREN:
            lexer.nextToken();
            if (lexer.token() == KW_SELECT) {
                tempExpr = subQuery();
                match(PUNC_RIGHT_PAREN);
                return tempExpr;
            }
            tempExpr = expression();
            switch(lexer.token()) {
                case PUNC_RIGHT_PAREN:
                    lexer.nextToken();
                    return tempExpr;
                case PUNC_COMMA:
                    lexer.nextToken();
                    tempExprList = new LinkedList<Expression>();
                    tempExprList.add(tempExpr);
                    tempExprList = expressionList(tempExprList);
                    return new RowExpression(tempExprList).setCacheEvalRst(cacheEvalRst);
                default:
                    throw err("unexpected token: " + lexer.token());
            }
        case KW_UTC_DATE:
            lexer.nextToken();
            if (lexer.token() == PUNC_LEFT_PAREN) {
                lexer.nextToken();
                match(PUNC_RIGHT_PAREN);
            }
            return new UtcDate(null).setCacheEvalRst(cacheEvalRst);
        case KW_UTC_TIME:
            lexer.nextToken();
            if (lexer.token() == PUNC_LEFT_PAREN) {
                lexer.nextToken();
                match(PUNC_RIGHT_PAREN);
            }
            return new UtcTime(null).setCacheEvalRst(cacheEvalRst);
        case KW_UTC_TIMESTAMP:
            lexer.nextToken();
            if (lexer.token() == PUNC_LEFT_PAREN) {
                lexer.nextToken();
                match(PUNC_RIGHT_PAREN);
            }
            return new UtcTimestamp(null).setCacheEvalRst(cacheEvalRst);
        case KW_CURRENT_DATE:
            lexer.nextToken();
            if (lexer.token() == PUNC_LEFT_PAREN) {
                lexer.nextToken();
                match(PUNC_RIGHT_PAREN);
            }
            return new Curdate().setCacheEvalRst(cacheEvalRst);
        case KW_CURRENT_TIME:
            lexer.nextToken();
            if (lexer.token() == PUNC_LEFT_PAREN) {
                lexer.nextToken();
                match(PUNC_RIGHT_PAREN);
            }
            return new Curtime().setCacheEvalRst(cacheEvalRst);
        case KW_CURRENT_TIMESTAMP:
        case KW_LOCALTIME:
        case KW_LOCALTIMESTAMP:
            lexer.nextToken();
            if (lexer.token() == PUNC_LEFT_PAREN) {
                lexer.nextToken();
                match(PUNC_RIGHT_PAREN);
            }
            return new Now().setCacheEvalRst(cacheEvalRst);
        case KW_CURRENT_USER:
            lexer.nextToken();
            if (lexer.token() == PUNC_LEFT_PAREN) {
                lexer.nextToken();
                match(PUNC_RIGHT_PAREN);
            }
            return new CurrentUser().setCacheEvalRst(cacheEvalRst);
        case KW_DEFAULT:
            if (lexer.nextToken() == PUNC_LEFT_PAREN) {
                return ordinaryFunction(lexer.stringValue(), lexer.stringValueUppercase());
            }
            return new DefaultValue().setCacheEvalRst(cacheEvalRst);
        case KW_DATABASE:
        case KW_IF:
        case KW_INSERT:
        case KW_LEFT:
        case KW_REPEAT:
        case KW_REPLACE:
        case KW_RIGHT:
        case KW_SCHEMA:
        case KW_VALUES:
            tempStr = lexer.stringValue();
            tempStrUp = lexer.stringValueUppercase();
            String tempStrUp2 = MySQLToken.keyWordToString(lexer.token());
            if (!tempStrUp2.equals(tempStrUp)) {
                tempStrUp = tempStr = tempStrUp2;
            }
            if (lexer.nextToken() == PUNC_LEFT_PAREN) {
                return ordinaryFunction(tempStr, tempStrUp);
            }
            throw err("keyword not followed by '(' is not expression: " + tempStr);
        case KW_MOD:
            lexer.nextToken();
            match(PUNC_LEFT_PAREN);
            tempExpr = expression();
            match(PUNC_COMMA);
            tempExpr2 = expression();
            match(PUNC_RIGHT_PAREN);
            return new ArithmeticModExpression(tempExpr, tempExpr2).setCacheEvalRst(cacheEvalRst);
        case KW_CHAR:
            lexer.nextToken();
            match(PUNC_LEFT_PAREN);
            return functionChar();
        case KW_CONVERT:
            lexer.nextToken();
            match(PUNC_LEFT_PAREN);
            return functionConvert();
        case IDENTIFIER:
            tempStr = lexer.stringValue();
            tempStrUp = lexer.stringValueUppercase();
            lexer.nextToken();
            return startedFromIdentifier(tempStr, tempStrUp);
        case OP_ASTERISK:
            lexer.nextToken();
            return new Wildcard(null).setCacheEvalRst(cacheEvalRst);
        default:
            throw err("unrecognized token as first token of primary: " + lexer.token());
    }
}
Also used : LiteralHexadecimal(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralHexadecimal) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) CurrentUser(com.alibaba.cobar.parser.ast.expression.primary.function.info.CurrentUser) LiteralBitField(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralBitField) Curtime(com.alibaba.cobar.parser.ast.expression.primary.function.datetime.Curtime) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) UtcTimestamp(com.alibaba.cobar.parser.ast.expression.primary.function.datetime.UtcTimestamp) UtcTime(com.alibaba.cobar.parser.ast.expression.primary.function.datetime.UtcTime) DefaultValue(com.alibaba.cobar.parser.ast.expression.primary.DefaultValue) Curdate(com.alibaba.cobar.parser.ast.expression.primary.function.datetime.Curdate) LiteralNumber(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralNumber) AssignmentExpression(com.alibaba.cobar.parser.ast.expression.misc.AssignmentExpression) Wildcard(com.alibaba.cobar.parser.ast.expression.primary.Wildcard) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) LiteralBoolean(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralBoolean) UtcDate(com.alibaba.cobar.parser.ast.expression.primary.function.datetime.UtcDate) ExistsPrimary(com.alibaba.cobar.parser.ast.expression.primary.ExistsPrimary) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ArithmeticModExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression) UsrDefVarPrimary(com.alibaba.cobar.parser.ast.expression.primary.UsrDefVarPrimary) SubqueryAllExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAllExpression) MinusExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.MinusExpression) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) BitAndExpression(com.alibaba.cobar.parser.ast.expression.bit.BitAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) NegativeValueExpression(com.alibaba.cobar.parser.ast.expression.logical.NegativeValueExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) CastBinaryExpression(com.alibaba.cobar.parser.ast.expression.type.CastBinaryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) BitInvertExpression(com.alibaba.cobar.parser.ast.expression.bit.BitInvertExpression) BitXORExpression(com.alibaba.cobar.parser.ast.expression.bit.BitXORExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) BitShiftExpression(com.alibaba.cobar.parser.ast.expression.bit.BitShiftExpression) BitOrExpression(com.alibaba.cobar.parser.ast.expression.bit.BitOrExpression) ComparisionGreaterThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanOrEqualsExpression) MatchExpression(com.alibaba.cobar.parser.ast.expression.primary.MatchExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) ComparisionGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionGreaterThanExpression) ComparisionLessOrGreaterThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessOrGreaterThanExpression) SubqueryAnyExpression(com.alibaba.cobar.parser.ast.expression.misc.SubqueryAnyExpression) RegexpExpression(com.alibaba.cobar.parser.ast.expression.string.RegexpExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) ArithmeticMultiplyExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticMultiplyExpression) ComparisionLessThanOrEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanOrEqualsExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) ArithmeticSubtractExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticSubtractExpression) SoundsLikeExpression(com.alibaba.cobar.parser.ast.expression.string.SoundsLikeExpression) ArithmeticIntegerDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticIntegerDivideExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) LogicalNotExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalNotExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) AssignmentExpression(com.alibaba.cobar.parser.ast.expression.misc.AssignmentExpression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) LogicalXORExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalXORExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) ArithmeticAddExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticAddExpression) ComparisionNotEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNotEqualsExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) ComparisionLessThanExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionLessThanExpression) ArithmeticModExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticModExpression) ArithmeticDivideExpression(com.alibaba.cobar.parser.ast.expression.arithmeic.ArithmeticDivideExpression) LiteralNull(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralNull) Now(com.alibaba.cobar.parser.ast.expression.primary.function.datetime.Now) LiteralNumber(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralNumber)

Example 4 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class MySQLOutputASTVisitor method visit.

@Override
public void visit(DMLInsertStatement node) {
    appendable.append("INSERT ");
    switch(node.getMode()) {
        case DELAY:
            appendable.append("DELAYED ");
            break;
        case HIGH:
            appendable.append("HIGH_PRIORITY ");
            break;
        case LOW:
            appendable.append("LOW_PRIORITY ");
            break;
        case UNDEF:
            break;
        default:
            throw new IllegalArgumentException("unknown mode for INSERT: " + node.getMode());
    }
    if (node.isIgnore())
        appendable.append("IGNORE ");
    appendable.append("INTO ");
    node.getTable().accept(this);
    appendable.append(' ');
    List<Identifier> cols = node.getColumnNameList();
    if (cols != null && !cols.isEmpty()) {
        appendable.append('(');
        printList(cols);
        appendable.append(") ");
    }
    QueryExpression select = node.getSelect();
    if (select == null) {
        appendable.append("VALUES ");
        List<RowExpression> rows = node.getRowList();
        if (rows != null && !rows.isEmpty()) {
            boolean isFst = true;
            for (RowExpression row : rows) {
                if (row == null || row.getRowExprList().isEmpty())
                    continue;
                if (isFst)
                    isFst = false;
                else
                    appendable.append(", ");
                appendable.append('(');
                printList(row.getRowExprList());
                appendable.append(')');
            }
        } else {
            throw new IllegalArgumentException("at least one row for INSERT");
        }
    } else {
        select.accept(this);
    }
    List<Pair<Identifier, Expression>> dup = node.getDuplicateUpdate();
    if (dup != null && !dup.isEmpty()) {
        appendable.append(" ON DUPLICATE KEY UPDATE ");
        boolean isFst = true;
        for (Pair<Identifier, Expression> p : dup) {
            if (isFst)
                isFst = false;
            else
                appendable.append(", ");
            p.getKey().accept(this);
            appendable.append(" = ");
            p.getValue().accept(this);
        }
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) BetweenAndExpression(com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression) ComparisionEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) FunctionExpression(com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression) MatchExpression(com.alibaba.cobar.parser.ast.expression.primary.MatchExpression) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) ComparisionIsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression) LogicalOrExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression) LogicalAndExpression(com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression) UnaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression) ComparisionNullSafeEqualsExpression(com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression) LikeExpression(com.alibaba.cobar.parser.ast.expression.string.LikeExpression) TernaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.TernaryOperatorExpression) CollateExpression(com.alibaba.cobar.parser.ast.expression.type.CollateExpression) Expression(com.alibaba.cobar.parser.ast.expression.Expression) CaseWhenOperatorExpression(com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression) UserExpression(com.alibaba.cobar.parser.ast.expression.misc.UserExpression) PolyadicOperatorExpression(com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression) BinaryOperatorExpression(com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression) Pair(com.alibaba.cobar.parser.util.Pair)

Example 5 with QueryExpression

use of com.alibaba.cobar.parser.ast.expression.misc.QueryExpression in project cobar by alibaba.

the class MySQLDMLSelectParserTest method main.

@SuppressWarnings("unused")
public static void main(String[] ars) throws Exception {
    String sql = Performance.SQL_BENCHMARK_SELECT;
    for (int i = 0; i < 3; ++i) {
        MySQLLexer lexer = new MySQLLexer(sql);
        MySQLExprParser exprParser = new MySQLExprParser(lexer);
        MySQLDMLSelectParser parser = new MySQLDMLSelectParser(lexer, exprParser);
        QueryExpression stmt = parser.select();
    // System.out.println(stmt);
    }
    Thread.sleep(1000);
    long loop = 300 * 10000;
    long t1 = System.currentTimeMillis();
    t1 = System.currentTimeMillis();
    for (long i = 0; i < loop; ++i) {
        MySQLLexer lexer = new MySQLLexer(sql);
        MySQLExprParser exprParser = new MySQLExprParser(lexer);
        MySQLDMLSelectParser parser = new MySQLDMLSelectParser(lexer, exprParser);
        QueryExpression stmt = parser.select();
    }
    long t2 = System.currentTimeMillis();
    System.out.println((t2 - t1) * 1000.0d / loop + " us");
}
Also used : MySQLLexer(com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer) QueryExpression(com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)

Aggregations

QueryExpression (com.alibaba.cobar.parser.ast.expression.misc.QueryExpression)13 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)7 Expression (com.alibaba.cobar.parser.ast.expression.Expression)6 Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)6 BetweenAndExpression (com.alibaba.cobar.parser.ast.expression.comparison.BetweenAndExpression)4 ComparisionEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression)4 ComparisionIsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionIsExpression)4 ComparisionNullSafeEqualsExpression (com.alibaba.cobar.parser.ast.expression.comparison.ComparisionNullSafeEqualsExpression)4 InExpression (com.alibaba.cobar.parser.ast.expression.comparison.InExpression)4 LogicalAndExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalAndExpression)4 LogicalOrExpression (com.alibaba.cobar.parser.ast.expression.logical.LogicalOrExpression)4 UserExpression (com.alibaba.cobar.parser.ast.expression.misc.UserExpression)4 CaseWhenOperatorExpression (com.alibaba.cobar.parser.ast.expression.primary.CaseWhenOperatorExpression)4 MatchExpression (com.alibaba.cobar.parser.ast.expression.primary.MatchExpression)4 FunctionExpression (com.alibaba.cobar.parser.ast.expression.primary.function.FunctionExpression)4 LikeExpression (com.alibaba.cobar.parser.ast.expression.string.LikeExpression)4 CollateExpression (com.alibaba.cobar.parser.ast.expression.type.CollateExpression)4 BinaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.BinaryOperatorExpression)2 PolyadicOperatorExpression (com.alibaba.cobar.parser.ast.expression.PolyadicOperatorExpression)2 UnaryOperatorExpression (com.alibaba.cobar.parser.ast.expression.UnaryOperatorExpression)2