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;
}
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;
}
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;
}
Aggregations