Search in sources :

Example 6 with ItemSum

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;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemScalarSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)

Example 7 with ItemSum

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;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ItemInt(com.actiontech.dble.plan.common.item.ItemInt) ArrayList(java.util.ArrayList)

Example 8 with ItemSum

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);
    }
}
Also used : ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) DGRowPacket(com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.directgroupby.DGRowPacket)

Example 9 with ItemSum

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);
    }
}
Also used : ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) DGRowPacket(com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.directgroupby.DGRowPacket)

Example 10 with ItemSum

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);
        }
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Aggregations

ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)23 DGRowPacket (com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.directgroupby.DGRowPacket)8 Item (com.actiontech.dble.plan.common.item.Item)6 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)5 ArrayList (java.util.ArrayList)4 RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)3 Field (com.actiontech.dble.plan.common.field.Field)3 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)2 Order (com.actiontech.dble.plan.Order)2 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)2 DirectGroupByHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.DirectGroupByHandler)1 OrderedGroupByHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.OrderedGroupByHandler)1 GroupByBucket (com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.directgroupby.GroupByBucket)1 DistinctLocalResult (com.actiontech.dble.backend.mysql.store.DistinctLocalResult)1 GroupByLocalResult (com.actiontech.dble.backend.mysql.store.GroupByLocalResult)1 ResultStore (com.actiontech.dble.plan.common.external.ResultStore)1 ItemField (com.actiontech.dble.plan.common.item.ItemField)1 ItemInt (com.actiontech.dble.plan.common.item.ItemInt)1 ItemScalarSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemScalarSubQuery)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1