use of com.actiontech.dble.plan.common.item.function.ItemFunc in project dble by actiontech.
the class PlanUtil method rebuildSubQueryFuncItem.
private static Item rebuildSubQueryFuncItem(Item item) {
ItemFunc func = (ItemFunc) item;
Item itemTmp = item.cloneItem();
for (int index = 0; index < func.getArgCount(); index++) {
Item arg = item.arguments().get(index);
if (arg instanceof ItemScalarSubQuery) {
Item result = ((ItemScalarSubQuery) arg).getValue();
if (result == null || result.getResultItem() == null) {
itemTmp.arguments().set(index, new ItemNull());
} else {
itemTmp.arguments().set(index, result.getResultItem());
}
} else if (arg instanceof ItemInSubQuery) {
ItemInSubQuery inSubItem = (ItemInSubQuery) arg;
if (inSubItem.getValue().size() == 0) {
itemTmp.arguments().set(index, genBoolItem(inSubItem.isNeg()));
} else {
List<Item> newArgs = new ArrayList<>(inSubItem.getValue().size() + 1);
newArgs.add(inSubItem.getLeftOperand());
newArgs.addAll(inSubItem.getValue());
itemTmp.arguments().set(index, new ItemFuncIn(newArgs, inSubItem.isNeg()));
}
itemTmp.setItemName(null);
return itemTmp;
} else if (arg instanceof ItemFunc) {
itemTmp.arguments().set(index, rebuildSubQueryItem(arg));
}
}
itemTmp.setItemName(null);
return itemTmp;
}
use of com.actiontech.dble.plan.common.item.function.ItemFunc in project dble by actiontech.
the class PlanUtil method pushFunctionToUnionChild.
/**
* arg of merge node's function belong to child
*
* @param toPush toPush
* @param colIndexs colIndexs
* @param childSelects childSelects
* @return ItemFunc
*/
private static ItemFunc pushFunctionToUnionChild(ItemFunc toPush, Map<String, Integer> colIndexs, List<Item> childSelects) {
ItemFunc func = (ItemFunc) toPush.cloneStruct();
for (int index = 0; index < toPush.getArgCount(); index++) {
Item arg = toPush.arguments().get(index);
Item pushedArg = pushItemToUnionChild(arg, colIndexs, childSelects);
func.arguments().set(index, pushedArg);
}
func.setPushDownName(null);
refreshReferTables(func);
return func;
}
use of com.actiontech.dble.plan.common.item.function.ItemFunc in project dble by actiontech.
the class ERJoinChooser method nodeHasSelectable.
private Item nodeHasSelectable(PlanNode child, Item sel) {
if (sel instanceof ItemField) {
return nodeHasColumn(child, (ItemField) sel);
} else if (sel.canValued()) {
return sel;
} else if (sel.type().equals(Item.ItemType.SUM_FUNC_ITEM)) {
return null;
} else {
ItemFunc fcopy = (ItemFunc) sel.cloneStruct();
for (int index = 0; index < fcopy.getArgCount(); index++) {
Item arg = fcopy.arguments().get(index);
Item argSel = nodeHasSelectable(child, arg);
if (argSel == null)
return null;
else
fcopy.arguments().set(index, argSel);
}
PlanUtil.refreshReferTables(fcopy);
fcopy.setPushDownName(null);
return fcopy;
}
}
use of com.actiontech.dble.plan.common.item.function.ItemFunc in project dble by actiontech.
the class FilterPusher method replaceFunctionArg.
/**
* replaceFunctionArg
*
* @param f
* @param sels1
* @param sels2
* @return if f also contains selectable which is not sels1 ,return null
*/
public static ItemFunc replaceFunctionArg(ItemFunc f, List<Item> sels1, List<Item> sels2) {
ItemFunc ret = (ItemFunc) f.cloneStruct();
for (int index = 0; index < ret.getArgCount(); index++) {
Item arg = ret.arguments().get(index);
if (arg instanceof ItemFunc) {
ItemFunc newfArg = replaceFunctionArg((ItemFunc) arg, sels1, sels2);
if (newfArg == null)
return null;
else
ret.arguments().set(index, newfArg);
} else if (arg instanceof ItemField) {
int tmpIndex = sels1.indexOf(arg);
if (tmpIndex < 0) {
return null;
} else {
Item newArg = sels2.get(tmpIndex);
ret.arguments().set(index, newArg.cloneStruct());
}
} else {
// do nothing;
}
}
ret.setPushDownName(null);
PlanUtil.refreshReferTables(ret);
return ret;
}
Aggregations