Search in sources :

Example 1 with ItemInt

use of com.actiontech.dble.plan.common.item.ItemInt in project dble by actiontech.

the class JoinNodeHandlerBuilder method buildNestFilters.

/**
 * generate filter for big table according to tmp(small) table's result
 *
 * @param tnBig
 * @param keyToPass
 * @param valueSet
 */
protected void buildNestFilters(PlanNode tnBig, Item keyToPass, Set<String> valueSet, int maxPartSize) {
    List<Item> strategyFilters = tnBig.getNestLoopFilters();
    List<Item> partList = null;
    Item keyInBig = PlanUtil.pushDownItem(node, keyToPass);
    int partSize = 0;
    for (String value : valueSet) {
        if (partList == null)
            partList = new ArrayList<>();
        if (value == null) {
            // is null will never join
            continue;
        } else {
            partList.add(new ItemString(value));
            if (++partSize >= maxPartSize) {
                List<Item> argList = new ArrayList<>();
                argList.add(keyInBig);
                argList.addAll(partList);
                ItemFuncIn inFilter = new ItemFuncIn(argList, false);
                strategyFilters.add(inFilter);
                partList = null;
                partSize = 0;
            }
        }
    }
    if (partSize > 0) {
        List<Item> argList = new ArrayList<>();
        argList.add(keyInBig);
        argList.addAll(partList);
        ItemFuncIn inFilter = new ItemFuncIn(argList, false);
        strategyFilters.add(inFilter);
    }
    // if no data
    if (strategyFilters.isEmpty()) {
        strategyFilters.add(new ItemInt(0));
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncIn(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncIn) ItemInt(com.actiontech.dble.plan.common.item.ItemInt) ArrayList(java.util.ArrayList) ItemString(com.actiontech.dble.plan.common.item.ItemString) ItemString(com.actiontech.dble.plan.common.item.ItemString)

Example 2 with ItemInt

use of com.actiontech.dble.plan.common.item.ItemInt in project dble by actiontech.

the class HandlerTool method createFunctionItem.

protected static ItemFunc createFunctionItem(ItemFunc f, List<Field> fields, int startIndex, boolean allPushDown, HandlerType type) {
    ItemFunc ret = null;
    List<Item> args = new ArrayList<>();
    for (int index = 0; index < f.getArgCount(); index++) {
        Item arg = f.arguments().get(index);
        Item newArg = null;
        if (arg.isWild())
            newArg = new ItemInt(0);
        else
            newArg = createItem(arg, fields, startIndex, allPushDown, type);
        if (newArg == null)
            throw new RuntimeException("Function argument not found:" + arg);
        args.add(newArg);
    }
    ret = (ItemFunc) f.reStruct(args, allPushDown, fields);
    ret.setItemName(f.getPushDownName() == null ? f.getItemName() : f.getPushDownName());
    return ret;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemInt(com.actiontech.dble.plan.common.item.ItemInt) ArrayList(java.util.ArrayList)

Example 3 with ItemInt

use of com.actiontech.dble.plan.common.item.ItemInt in project dble by actiontech.

the class HandlerTool method createSumItem.

/**
 * @param f
 * @param fields
 * @param startIndex
 * @param allPushDown
 * @param type
 * @return
 */
private static ItemSum createSumItem(ItemSum f, List<Field> fields, int startIndex, boolean allPushDown, HandlerType type) {
    ItemSum ret = null;
    List<Item> args = new ArrayList<>();
    for (int index = 0; index < f.getArgCount(); index++) {
        Item arg = f.arguments().get(index);
        Item newArg = null;
        if (arg.isWild())
            newArg = new ItemInt(0);
        else
            newArg = createItem(arg, fields, startIndex, allPushDown, type);
        if (newArg == null)
            throw new RuntimeException("Function argument not found:" + arg);
        args.add(newArg);
    }
    ret = (ItemSum) f.reStruct(args, allPushDown, fields);
    ret.setItemName(f.getPushDownName() == null ? f.getItemName() : f.getPushDownName());
    return ret;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ItemInt(com.actiontech.dble.plan.common.item.ItemInt) ArrayList(java.util.ArrayList)

Example 4 with ItemInt

use of com.actiontech.dble.plan.common.item.ItemInt in project dble by actiontech.

the class SelectedProcessor method pushSelected.

/**
 * pushSelected
 * if parent's  selected refered isA.id,A.name,B.id,B.name,
 * node of A only need push A.id,A.nam
 *
 * @param qtn
 * @param toPushColumns
 * @return
 */
private static PlanNode pushSelected(PlanNode qtn, Collection<Item> toPushColumns) {
    boolean isPushDownNode = false;
    if (PlanUtil.isGlobalOrER(qtn)) {
        // TODO:buildColumnRefers for every child
        List<Item> selList = qtn.getColumnsSelected();
        for (Item pdSel : toPushColumns) {
            if (!selList.contains(pdSel)) {
                selList.add(pdSel);
            }
        }
        isPushDownNode = true;
        qtn.setUpRefers(isPushDownNode);
        return qtn;
    }
    isPushDownNode = (qtn.type() == PlanNode.PlanNodeType.TABLE || qtn.type() == PlanNode.PlanNodeType.NONAME);
    if (qtn.type() == PlanNode.PlanNodeType.MERGE) {
        return mergePushSelected((MergeNode) qtn, toPushColumns);
    } else {
        if (qtn.getSubQueries().size() > 0) {
            for (ItemSubQuery itemSubQuery : qtn.getSubQueries()) {
                pushSelected(itemSubQuery.getPlanNode(), new HashSet<Item>());
            }
        }
        if (toPushColumns.isEmpty()) {
            qtn.setUpRefers(isPushDownNode);
        } else if (qtn.isDistinct()) {
            List<Item> selList = qtn.getColumnsSelected();
            for (Item pdSel : toPushColumns) {
                if (!selList.contains(pdSel)) {
                    selList.add(pdSel);
                }
            }
            qtn.setUpRefers(isPushDownNode);
        } else {
            List<Item> selList = qtn.getColumnsSelected();
            selList.clear();
            boolean existSum = false;
            for (Item toPush : toPushColumns) {
                selList.add(toPush);
                existSum |= toPush.type().equals(Item.ItemType.SUM_FUNC_ITEM);
            }
            // if only push id,it will miss sum(id)
            if (!existSum && qtn.getSumFuncs().size() > 0) {
                selList.add(qtn.getSumFuncs().iterator().next());
            }
            qtn.setUpRefers(isPushDownNode);
        }
        PlanNode.PlanNodeType i = qtn.type();
        if (i == PlanNode.PlanNodeType.NONAME) {
            return qtn;
        } else if (i == PlanNode.PlanNodeType.TABLE) {
            return qtn;
        } else {
            for (PlanNode child : qtn.getChildren()) {
                List<Item> referList = qtn.getColumnsReferedByChild(child);
                if (referList.isEmpty()) {
                    referList.add(new ItemInt(1));
                }
                Collection<Item> pdRefers = getPushDownSel(qtn, child, referList);
                pushSelected(child, pdRefers);
            }
            return qtn;
        }
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) ItemInt(com.actiontech.dble.plan.common.item.ItemInt) ItemSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)

Example 5 with ItemInt

use of com.actiontech.dble.plan.common.item.ItemInt in project dble by actiontech.

the class SubQueryPreProcessor method buildSubQueryWithAndFilter.

private static SubQueryFilter buildSubQueryWithAndFilter(PlanNode node, SubQueryFilter qtn, ItemCondAnd filter, boolean isOrChild, BoolPtr childTransform) {
    for (int index = 0; index < filter.getArgCount(); index++) {
        SubQueryFilter result = buildSubQuery(node, qtn, filter.arguments().get(index), isOrChild, childTransform);
        if (result != qtn) {
            if (result.filter == null) {
                result.filter = new ItemInt(1);
            }
            filter.arguments().set(index, result.filter);
            qtn = result;
        }
    }
    qtn.filter = filter;
    return qtn;
}
Also used : ItemInt(com.actiontech.dble.plan.common.item.ItemInt)

Aggregations

ItemInt (com.actiontech.dble.plan.common.item.ItemInt)5 Item (com.actiontech.dble.plan.common.item.Item)4 ArrayList (java.util.ArrayList)3 ItemString (com.actiontech.dble.plan.common.item.ItemString)1 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)1 ItemFuncIn (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncIn)1 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)1 ItemSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1