use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.
the class HandlerTool method createItem.
/**
* create Item, the Item value referenced by field and changed by field changes
*
* @param sel
* @param fields
* @param type
* @return
*/
public static Item createItem(Item sel, List<Field> fields, int startIndex, boolean allPushDown, HandlerType type) {
Item ret;
if (sel.basicConstItem())
return sel;
if (sel instanceof ItemScalarSubQuery) {
ItemScalarSubQuery scalarSubQuery = (ItemScalarSubQuery) sel;
if (scalarSubQuery.getPlanNode().type() == PlanNode.PlanNodeType.NONAME) {
Item result = scalarSubQuery.getSelect();
result.setItemName(scalarSubQuery.getItemName());
result.setAlias(scalarSubQuery.getItemName());
return result;
} else {
return scalarSubQuery.getValue();
}
}
Item.ItemType i = sel.type();
if (i == Item.ItemType.FUNC_ITEM || i == Item.ItemType.COND_ITEM) {
ItemFunc func = (ItemFunc) sel;
if (func.getPushDownName() == null || func.getPushDownName().length() == 0) {
ret = createFunctionItem(func, fields, startIndex, allPushDown, type);
} else {
ret = createFieldItem(func, fields, startIndex);
}
} else if (i == Item.ItemType.SUM_FUNC_ITEM) {
ItemSum sumFunc = (ItemSum) sel;
if (type != HandlerType.GROUPBY) {
ret = createFieldItem(sumFunc, fields, startIndex);
} else if (sumFunc.getPushDownName() == null || sumFunc.getPushDownName().length() == 0) {
ret = createSumItem(sumFunc, fields, startIndex, allPushDown, type);
} else {
ret = createPushDownGroupBy(sumFunc, fields, startIndex);
}
} else {
ret = createFieldItem(sel, fields, startIndex);
}
ret.fixFields();
return ret;
}
use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum 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.function.sumfunc.ItemSum in project dble by actiontech.
the class GroupByLocalResult method onFirstGroupRow.
protected void onFirstGroupRow(RowDataPacket row) {
// we need to calculate group by
initSumFunctions(this.sums, row);
for (int i = 0; i < this.sums.size(); i++) {
ItemSum sum = this.sums.get(i);
Object b = sum.getTransAggObj();
int transSize = sum.getTransSize();
((DGRowPacket) row).setSumTran(i, b, transSize);
}
}
use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.
the class GroupResultDiskBuffer method onFoundRow.
@Override
protected void onFoundRow(RowDataPacket oldRow, RowDataPacket row) {
// we need to calculate group by
initSumFunctions(this.sums, oldRow);
updateSumFunc(this.sums, row);
for (int i = 0; i < this.sums.size(); i++) {
ItemSum sum = this.sums.get(i);
Object b = sum.getTransAggObj();
int transSize = sum.getTransSize();
((DGRowPacket) oldRow).setSumTran(i, b, transSize);
}
}
use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.
the class SelectedProcessor method mergePushOrderBy.
private static void mergePushOrderBy(Item orderSel, List<Item> mergeSelects) {
if (orderSel instanceof ItemField) {
if (!mergeSelects.contains(orderSel))
mergeSelects.add(orderSel);
} else if (orderSel instanceof ItemFunc) {
ItemFunc func = (ItemFunc) orderSel;
if (func.isWithSumFunc()) {
for (int index = 0; index < func.getArgCount(); index++) {
Item arg = func.arguments().get(index);
mergePushOrderBy(arg, mergeSelects);
}
} else {
if (!mergeSelects.contains(func)) {
mergeSelects.add(func);
}
// union's order by must be found from selects
func.setPushDownName(func.getItemName());
}
} else if (orderSel instanceof ItemSum) {
ItemSum func = (ItemSum) orderSel;
for (int index = 0; index < func.getArgCount(); index++) {
Item arg = func.arguments().get(index);
mergePushOrderBy(arg, mergeSelects);
}
}
}
Aggregations