use of com.actiontech.dble.plan.common.item.function.operator.ItemBoolFunc2 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;
}
Aggregations