Search in sources :

Example 1 with ItemCond

use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCond 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;
}
Also used : ItemCondAnd(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd) ItemCond(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCond) ItemCondOr(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr)

Example 2 with ItemCond

use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCond in project dble by actiontech.

the class FilterPreProcessor method processOneFilter.

/**
 * change "const op column" to "column op const"
 *
 * @param root
 * @return
 */
private static Item processOneFilter(Item root) {
    if (root == null) {
        return null;
    }
    Item newRoot = root;
    if (root instanceof ItemBoolFunc2) {
        Item a = root.arguments().get(0);
        Item b = root.arguments().get(1);
        if (a.basicConstItem() && !b.basicConstItem() && !b.isWithSubQuery()) {
            if (root instanceof ItemFuncGe) {
                newRoot = new ItemFuncLe(b, a);
            } else if (root instanceof ItemFuncGt) {
                newRoot = new ItemFuncLt(b, a);
            } else if (root instanceof ItemFuncLt) {
                newRoot = new ItemFuncGt(b, a);
            } else if (root instanceof ItemFuncLe) {
                newRoot = new ItemFuncGe(b, a);
            } else {
                root.arguments().set(1, a);
                root.arguments().set(0, b);
                root.setItemName(null);
            }
            newRoot.getReferTables().addAll(root.getReferTables());
        }
    } else if (root instanceof ItemCond) {
        ItemCond condfun = (ItemCond) root;
        List<Item> newArgs = new ArrayList<>();
        for (Item arg : condfun.arguments()) {
            Item newArg = processOneFilter(arg);
            if (newArg != null)
                newArgs.add(newArg);
        }
        if (condfun.functype().equals(ItemFunc.Functype.COND_AND_FUNC))
            newRoot = FilterUtils.and(newArgs);
        else
            newRoot = FilterUtils.or(newArgs);
    }
    return newRoot;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemBoolFunc2(com.actiontech.dble.plan.common.item.function.operator.ItemBoolFunc2) ItemCond(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCond)

Example 3 with ItemCond

use of com.actiontech.dble.plan.common.item.function.operator.logic.ItemCond in project dble by actiontech.

the class FilterUtils method splitFilter.

/**
 * split the filter until filter is 'boolean filer' or 'orfilter'
 *
 * @param filter
 * @return
 */
public static List<Item> splitFilter(Item filter) {
    if (filter == null)
        throw new RuntimeException("check filter before split");
    List<Item> filterList = new ArrayList<>();
    if (filter.type() == Item.ItemType.COND_ITEM) {
        ItemCond cond = (ItemCond) filter;
        if (cond.functype() == Functype.COND_AND_FUNC) {
            for (int index = 0; index < cond.getArgCount(); index++) {
                Item subFilter = cond.arguments().get(index);
                if (subFilter == null)
                    continue;
                List<Item> subSplits = splitFilter(subFilter);
                filterList.addAll(subSplits);
            }
        } else if (cond.functype() == Functype.COND_OR_FUNC) {
            // step1 divide the args into base  part
            Set<List<Item>> saveSet = new HashSet<List<Item>>();
            for (int index = 0; index < cond.getArgCount(); index++) {
                Item subFilter = cond.arguments().get(index);
                if (subFilter == null)
                    continue;
                List<Item> subSplits = splitFilter(subFilter);
                saveSet.add(subSplits);
            }
            Map<String, List<Item>> itemMap = gourpByRefertTable(filter, saveSet);
            for (Map.Entry<String, List<Item>> entry : itemMap.entrySet()) {
                ItemCondOr x = new ItemCondOr(entry.getValue());
                x.getReferTables().addAll(entry.getValue().get(0).getReferTables());
                filterList.add(x);
            }
            filterList.add(cond);
        } else {
            filterList.add(cond);
        }
    } else {
        filterList.add(filter);
    }
    return filterList;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemCond(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCond) ItemCondOr(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr)

Aggregations

ItemCond (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCond)3 Item (com.actiontech.dble.plan.common.item.Item)2 ItemCondOr (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr)2 ItemBoolFunc2 (com.actiontech.dble.plan.common.item.function.operator.ItemBoolFunc2)1 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)1