Search in sources :

Example 1 with ItemFuncNot

use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot in project dble by actiontech.

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLUnaryExpr x) {
    Item a = getItem(x.getExpr());
    switch(x.getOperator()) {
        case Negative:
            item = new ItemFuncNeg(a);
            break;
        case Not:
        case NOT:
            item = new ItemFuncNot(a);
            break;
        case Compl:
            item = new ItemFuncBitInversion(a);
            break;
        case Plus:
            item = a;
            break;
        case BINARY:
            item = new ItemFuncBinary(a, -1);
            break;
        default:
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported kind expression:" + x.getOperator());
    }
    item.setWithSubQuery(a.isWithSubQuery());
    item.setCorrelatedSubQuery(a.isCorrelatedSubQuery());
    initName(x);
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) ItemFuncNot(com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot) ItemFuncBinary(com.actiontech.dble.plan.common.item.function.castfunc.ItemFuncBinary) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 2 with ItemFuncNot

use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot in project dble by actiontech.

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLNotExpr x) {
    Item arg = getItem(x.getExpr());
    item = new ItemFuncNot(arg);
    item.setWithSubQuery(arg.isWithSubQuery());
    item.setCorrelatedSubQuery(arg.isCorrelatedSubQuery());
    initName(x);
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) ItemFuncNot(com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot)

Example 3 with ItemFuncNot

use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot 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

ItemFuncNot (com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot)3 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)3 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2 ItemFuncBinary (com.actiontech.dble.plan.common.item.function.castfunc.ItemFuncBinary)1 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)1 ItemCondOr (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr)1 ItemFuncXor (com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncXor)1 ItemInSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery)1 ArrayList (java.util.ArrayList)1