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