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);
}
Aggregations