Search in sources :

Example 16 with ItemSum

use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.

the class DirectGroupByHandler method sendNoRowGroupRowPacket.

/**
 * send data to next even no data here.eg:select count(*) from t2,if t2 is empty,send 0
 */
private void sendNoRowGroupRowPacket(MySQLConnection conn) {
    RowDataPacket newRp = new RowDataPacket(this.fieldPackets.size() + this.sums.size());
    for (ItemSum sum : this.sums) {
        sum.noRowsInResult();
        byte[] tmp = sum.getRowPacketByte();
        newRp.add(tmp);
    }
    for (int i = 0; i < this.fieldPackets.size(); i++) {
        newRp.add(null);
    }
    nextHandler.rowResponse(null, newRp, this.isLeft, conn);
}
Also used : ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 17 with ItemSum

use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.

the class DirectGroupByHandler method sendGroupRowPacket.

private boolean sendGroupRowPacket(MySQLConnection conn, RowDataPacket row, List<ItemSum> sendSums) {
    initSumFunctions(sendSums, row);
    RowDataPacket newRp = new RowDataPacket(this.fieldPackets.size() + sendSums.size());
    /**
     * add sums generated by middle-ware.
     * eg: a table node like select count(*) from t
     * the query will be push down,the final rowpacket is
     * count(*){col1,generated by group by handler},count(*){col2,response from mysql node}
     */
    for (ItemSum sendSum : sendSums) {
        byte[] tmp = sendSum.getRowPacketByte();
        newRp.add(tmp);
    }
    for (int i = 0; i < row.getFieldCount(); i++) {
        newRp.add(row.getValue(i));
    }
    return nextHandler.rowResponse(null, newRp, this.isLeft, conn);
}
Also used : ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 18 with ItemSum

use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.

the class DirectGroupByHandler method initSumFunctions.

protected void initSumFunctions(List<ItemSum> functions, RowDataPacket row) {
    for (int index = 0; index < functions.size(); index++) {
        ItemSum sum = functions.get(index);
        Object transObj = ((DGRowPacket) row).getSumTran(index);
        sum.resetAndAdd(row, transObj);
    }
}
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 19 with ItemSum

use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.

the class DirectGroupByHandler method fieldEofResponse.

@Override
public void fieldEofResponse(byte[] headerNull, List<byte[]> fieldsNull, final List<FieldPacket> fieldPackets, byte[] eofNull, boolean isLeft, BackendConnection conn) {
    if (terminate.get())
        return;
    if (this.pool == null)
        this.pool = DbleServer.getInstance().getBufferPool();
    this.fieldPackets = fieldPackets;
    List<Field> sourceFields = HandlerTool.createFields(this.fieldPackets);
    for (ItemSum sumFunc : referredSumFunctions) {
        ItemSum sum = (ItemSum) (HandlerTool.createItem(sumFunc, sourceFields, 0, this.isAllPushDown(), this.type()));
        sums.add(sum);
    }
    prepareSumAggregators(sums, true);
    setupSumFunctions(sums);
    /* group fieldpackets are front of the origin */
    sendGroupFieldPackets((MySQLConnection) conn);
    // row in localresult is DGRowPacket which is added aggregate functions result from origin rowdatapacket
    localResultFps = this.fieldPackets;
    List<ItemSum> localResultReferredSums = referredSumFunctions;
    RowDataComparator comparator = new RowDataComparator(this.localResultFps, this.groupBys, this.isAllPushDown(), this.type());
    groupLocalResult = new GroupByLocalResult(pool, localResultFps.size(), comparator, localResultFps, localResultReferredSums, this.isAllPushDown(), CharsetUtil.getJavaCharset(conn.getCharset().getResults())).setMemSizeController(session.getOtherBufferMC());
    for (int i = 0; i < bucketSize; i++) {
        RowDataComparator tmpComparator = new RowDataComparator(this.localResultFps, this.groupBys, this.isAllPushDown(), this.type());
        GroupByBucket bucket = new GroupByBucket(queue, outQueue, pool, localResultFps.size(), tmpComparator, localResultFps, localResultReferredSums, this.isAllPushDown(), CharsetUtil.getJavaCharset(conn.getCharset().getResults()));
        bucket.setMemSizeController(session.getOtherBufferMC());
        buckets.add(bucket);
        bucket.start();
    }
    if (this.groupStart.compareAndSet(false, true)) {
        startOwnThread(conn);
    }
}
Also used : GroupByLocalResult(com.actiontech.dble.backend.mysql.store.GroupByLocalResult) Field(com.actiontech.dble.plan.common.field.Field) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) GroupByBucket(com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.directgroupby.GroupByBucket) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

Example 20 with ItemSum

use of com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum in project dble by actiontech.

the class DirectGroupByHandler method sendGroupFieldPackets.

/**
 * aggregate functions result and origin rowdatapacket
 */
private List<FieldPacket> sendGroupFieldPackets(MySQLConnection conn) {
    List<FieldPacket> newFps = new ArrayList<>();
    for (ItemSum sum1 : sums) {
        Item sum = sum1;
        FieldPacket tmp = new FieldPacket();
        sum.makeField(tmp);
        newFps.add(tmp);
    }
    newFps.addAll(this.fieldPackets);
    nextHandler.fieldEofResponse(null, null, newFps, null, this.isLeft, conn);
    return newFps;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ArrayList(java.util.ArrayList) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

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