Search in sources :

Example 6 with ItemInSubQuery

use of com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery in project dble by actiontech.

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLBinaryOpExpr x) {
    Item itemLeft = getItem(x.getLeft());
    SQLExpr rightExpr = x.getRight();
    Item itemRight = getItem();
    if (itemRight instanceof ItemInSubQuery && (rightExpr instanceof SQLSomeExpr || rightExpr instanceof SQLAllExpr || rightExpr instanceof SQLAnyExpr)) {
        item = itemRight;
        return;
    }
    switch(x.getOperator()) {
        case Is:
            // is null, or is unknown
            if (itemRight instanceof ItemNull || itemRight instanceof ItemString) {
                item = new ItemFuncIsnull(itemLeft);
            } else if (itemRight instanceof ItemInt) {
                ItemInt itemBool = (ItemInt) itemRight;
                if (itemBool.valInt().longValue() == 1) {
                    // is true
                    item = new ItemFuncIstrue(itemLeft);
                } else {
                    item = new ItemFuncIsfalse(itemLeft);
                }
            } else {
                throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not support type:" + x.getRight());
            }
            break;
        case IsNot:
            // is not null, or is not unknown
            if (itemRight instanceof ItemNull || itemRight instanceof ItemString) {
                item = new ItemFuncIsnotnull(itemLeft);
            } else if (itemRight instanceof ItemInt) {
                ItemInt itemBool = (ItemInt) itemRight;
                if (itemBool.valInt().longValue() == 1) {
                    // is true
                    item = new ItemFuncIsnottrue(itemLeft);
                } else {
                    item = new ItemFuncIsnotfalse(itemLeft);
                }
            } else {
                throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not support type:" + x.getRight());
            }
            break;
        case Escape:
            if (itemLeft instanceof ItemFuncLike) {
                // A LIKE B ESCAPE C ,A is "itemLeft"
                SQLBinaryOpExpr like = (SQLBinaryOpExpr) (x.getLeft());
                Item itemLikeLeft = getItem(like.getLeft());
                Item itemLikeRight = getItem(x.getRight());
                boolean isNot = (like.getOperator() == SQLBinaryOperator.NotLike);
                item = new ItemFuncLike(itemLikeLeft, itemLikeRight, itemRight, isNot);
            } else {
                throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported kind expression:" + x.getOperator());
            }
            break;
        case NotLike:
            item = new ItemFuncLike(itemLeft, itemRight, null, true);
            break;
        case Like:
            item = new ItemFuncLike(itemLeft, itemRight, null, false);
            break;
        case Equality:
            item = new ItemFuncEqual(itemLeft, itemRight);
            break;
        case Add:
            item = new ItemFuncPlus(itemLeft, itemRight);
            break;
        case Divide:
            item = new ItemFuncDiv(itemLeft, itemRight);
            break;
        case DIV:
            item = new ItemFuncIntDiv(itemLeft, itemRight);
            break;
        case Mod:
        case Modulus:
            item = new ItemFuncMod(itemLeft, itemRight);
            break;
        case Multiply:
            item = new ItemFuncMul(itemLeft, itemRight);
            break;
        case Subtract:
            item = new ItemFuncMinus(itemLeft, itemRight);
            break;
        case PG_And:
        case BooleanAnd:
            List<Item> argsAnd = new ArrayList<>();
            argsAnd.add(itemLeft);
            argsAnd.add(itemRight);
            item = new ItemCondAnd(argsAnd);
            break;
        case Concat:
        case BooleanOr:
            List<Item> argsOr = new ArrayList<>();
            argsOr.add(itemLeft);
            argsOr.add(itemRight);
            item = new ItemCondOr(argsOr);
            break;
        case BooleanXor:
            item = new ItemFuncXor(itemLeft, itemRight);
            break;
        case BitwiseAnd:
            item = new ItemFuncBitAnd(itemLeft, itemRight);
            break;
        case BitwiseOr:
            item = new ItemFuncBitOr(itemLeft, itemRight);
            break;
        case BitwiseXor:
            item = new ItemFuncBitXor(itemLeft, itemRight);
            break;
        case LeftShift:
            item = new ItemFuncLeftShift(itemLeft, itemRight);
            break;
        case RightShift:
            item = new ItemFuncRightShift(itemLeft, itemRight);
            break;
        case GreaterThan:
            item = new ItemFuncGt(itemLeft, itemRight);
            break;
        case GreaterThanOrEqual:
            item = new ItemFuncGe(itemLeft, itemRight);
            break;
        case NotEqual:
        case LessThanOrGreater:
            item = new ItemFuncNe(itemLeft, itemRight);
            break;
        case LessThan:
            item = new ItemFuncLt(itemLeft, itemRight);
            break;
        case LessThanOrEqual:
            item = new ItemFuncLe(itemLeft, itemRight);
            break;
        case LessThanOrEqualOrGreaterThan:
            item = new ItemFuncStrictEqual(itemLeft, itemRight);
            break;
        case RegExp:
            item = new ItemFuncRegex(itemLeft, itemRight);
            break;
        case NotRegExp:
            item = new ItemFuncRegex(itemLeft, itemRight);
            item = new ItemFuncNot(item);
            break;
        case Assignment:
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not support assignment");
        default:
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported kind expression:" + x.getOperator());
    }
    item.setWithSubQuery(itemLeft.isWithSubQuery() || itemRight.isWithSubQuery());
    item.setCorrelatedSubQuery(itemLeft.isCorrelatedSubQuery() || itemRight.isCorrelatedSubQuery());
    initName(x);
}
Also used : ArrayList(java.util.ArrayList) ItemFuncNot(com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot) ItemCondOr(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr) ItemInSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) ItemCondAnd(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd) ItemFuncXor(com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncXor) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Aggregations

ItemInSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery)6 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)3 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)3 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)2 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)2 ItemCondOr (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr)2 ItemAllAnySubQuery (com.actiontech.dble.plan.common.item.subquery.ItemAllAnySubQuery)2 ItemScalarSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)2 AllAnySubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.AllAnySubQueryHandler)1 InSubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.InSubQueryHandler)1 SingleRowSubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.SingleRowSubQueryHandler)1 SubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.SubQueryHandler)1 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)1 ItemFuncNot (com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot)1 ItemFuncXor (com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncXor)1 ItemExistsSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemExistsSubQuery)1 ItemSingleRowSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemSingleRowSubQuery)1 ItemSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)1 BoolPtr (com.actiontech.dble.plan.common.ptr.BoolPtr)1 ArrayList (java.util.ArrayList)1