Search in sources :

Example 6 with ItemFunc

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;
}
Also used : ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemInSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery) ItemScalarSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)

Example 7 with ItemFunc

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;
}
Also used : ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc)

Example 8 with ItemFunc

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;
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 9 with ItemFunc

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;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Aggregations

ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)9 Item (com.actiontech.dble.plan.common.item.Item)5 ItemField (com.actiontech.dble.plan.common.item.ItemField)3 ItemScalarSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)3 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)2 ItemInSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery)2 ItemInt (com.actiontech.dble.plan.common.item.ItemInt)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 ItemExistsSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemExistsSubQuery)1 BoolPtr (com.actiontech.dble.plan.common.ptr.BoolPtr)1 ArrayList (java.util.ArrayList)1