use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd in project dble by actiontech.
the class FilterUtils method createLogicalFilterNoName.
public static ItemCond createLogicalFilterNoName(boolean and, List<Item> subFilters) {
ItemCond cond = null;
if (and)
cond = new ItemCondAnd(subFilters);
else
cond = new ItemCondOr(subFilters);
PlanUtil.refreshReferTables(cond);
return cond;
}
use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd in project dble by actiontech.
the class PlanUtil method rebuildSubQueryItem.
public static Item rebuildSubQueryItem(Item item) {
if (!item.isWithSubQuery()) {
return item;
}
BoolPtr reBuild = new BoolPtr(false);
if (PlanUtil.isCmpFunc(item)) {
Item res1 = rebuildBoolSubQuery(item, 0, reBuild);
if (res1 != null) {
return res1;
}
Item res2 = rebuildBoolSubQuery(item, 1, reBuild);
if (res2 != null) {
return res2;
}
} else if (item instanceof ItemInSubQuery) {
ItemInSubQuery inSubItem = (ItemInSubQuery) item;
if (inSubItem.getValue().size() == 0) {
return genBoolItem(inSubItem.isNeg());
} else {
List<Item> args = new ArrayList<>(inSubItem.getValue().size() + 1);
args.add(inSubItem.getLeftOperand());
args.addAll(inSubItem.getValue());
return new ItemFuncIn(args, inSubItem.isNeg());
}
} else if (item instanceof ItemExistsSubQuery) {
ItemExistsSubQuery existsSubQuery = (ItemExistsSubQuery) item;
Item result = existsSubQuery.getValue();
if (result == null) {
return genBoolItem(existsSubQuery.isNot());
} else {
return genBoolItem(!existsSubQuery.isNot());
}
} else if (item instanceof ItemCondAnd || item instanceof ItemCondOr) {
for (int index = 0; index < item.getArgCount(); index++) {
Item rebuildItem = rebuildSubQueryItem(item.arguments().get(index));
item.arguments().set(index, rebuildItem);
item.setItemName(null);
}
} else if (item instanceof ItemScalarSubQuery) {
Item result = ((ItemScalarSubQuery) item).getValue();
if (result == null || result.getResultItem() == null) {
return new ItemFuncEqual(new ItemInt(1), new ItemInt(0));
}
return result.getResultItem();
}
if (!reBuild.get() && item instanceof ItemFunc) {
return rebuildSubQueryFuncItem(item);
}
return item;
}
use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd in project dble by actiontech.
the class MySQLPlanNodeVisitor method addJoinOnColumns.
private void addJoinOnColumns(Item ifilter, JoinNode joinNode) {
if (ifilter instanceof ItemFuncEqual) {
ItemFuncEqual filter = (ItemFuncEqual) ifilter;
Item column = filter.arguments().get(0);
Item value = filter.arguments().get(1);
if (column != null && column instanceof ItemField && value != null && value instanceof ItemField) {
joinNode.addJoinFilter(filter);
} else {
joinNode.setOtherJoinOnFilter(filter);
}
} else if (ifilter instanceof ItemCondAnd) {
ItemCondAnd ilfand = (ItemCondAnd) ifilter;
List<Item> subFilter = ilfand.arguments();
if (subFilter != null) {
for (Item arg : subFilter) {
Item orgOtherJoin = joinNode.getOtherJoinOnFilter();
addJoinOnColumns(arg, joinNode);
joinNode.setOtherJoinOnFilter(FilterUtils.and(orgOtherJoin, joinNode.getOtherJoinOnFilter()));
}
} else {
throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "and has no other columns , " + ifilter);
}
} else {
joinNode.setOtherJoinOnFilter(ifilter);
}
}
use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd 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);
}
use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd in project dble by actiontech.
the class FilterPreProcessor method convertOrToIn.
/**
* change single Logicalfilter(or) into in
*
* @param filter
*/
private static Item convertOrToIn(Item filter) {
if (filter == null)
return null;
if (filter.type().equals(Item.ItemType.COND_ITEM)) {
if (filter instanceof ItemCondAnd) {
ItemCondAnd andFilter = (ItemCondAnd) filter;
for (int index = 0; index < andFilter.getArgCount(); index++) {
andFilter.arguments().set(index, convertOrToIn(andFilter.arguments().get(index)));
}
andFilter.setItemName(null);
PlanUtil.refreshReferTables(andFilter);
return andFilter;
} else {
// or
ItemCondOr orFilter = (ItemCondOr) filter;
HashMap<Item, Set<Item>> inMap = new HashMap<>();
List<Item> newSubFilterList = new ArrayList<>();
for (int index = 0; index < orFilter.getArgCount(); index++) {
Item subFilter = orFilter.arguments().get(index);
if (subFilter == null)
continue;
if (subFilter instanceof ItemFuncEqual) {
Item a = subFilter.arguments().get(0);
Item b = subFilter.arguments().get(1);
if (!a.canValued() && b.canValued()) {
if (!inMap.containsKey(a))
inMap.put(a, new HashSet<Item>());
inMap.get(a).add(b);
} else {
// stop convert
return filter;
}
} else {
Item subNew = convertOrToIn(subFilter);
newSubFilterList.add(subNew);
}
}
for (Map.Entry<Item, Set<Item>> entry : inMap.entrySet()) {
List<Item> args = new ArrayList<>();
args.add(entry.getKey());
args.addAll(entry.getValue());
ItemFuncIn inItem = new ItemFuncIn(args, false);
PlanUtil.refreshReferTables(inItem);
newSubFilterList.add(inItem);
}
return FilterUtils.or(newSubFilterList);
}
}
return filter;
}
Aggregations