Search in sources :

Example 6 with RowDataComparator

use of com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator in project dble by actiontech.

the class OrderedGroupByHandler method fieldEofResponse.

@Override
public void fieldEofResponse(byte[] headerNull, List<byte[]> fieldsNull, final List<FieldPacket> fieldPackets, byte[] eofNull, boolean isLeft, BackendConnection conn) {
    this.charset = CharsetUtil.getJavaCharset(conn.getCharset().getResults());
    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);
    }
    comparator = new RowDataComparator(this.fieldPackets, this.groupBys, this.isAllPushDown(), this.type());
    prepareSumAggregators(sums, this.referredSumFunctions, this.fieldPackets, this.isAllPushDown(), true, (MySQLConnection) conn);
    setupSumFunctions(sums);
    sendGroupFieldPackets(conn);
}
Also used : Field(com.actiontech.dble.plan.common.field.Field) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

Example 7 with RowDataComparator

use of com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator in project dble by actiontech.

the class MultiNodeSelectHandler method mergeFieldEof.

private void mergeFieldEof(List<byte[]> fields, BackendConnection conn) throws IOException {
    fieldCount = fields.size();
    List<FieldPacket> fieldPackets = new ArrayList<>();
    for (byte[] field : fields) {
        this.netOutBytes += field.length;
        FieldPacket fieldPacket = new FieldPacket();
        fieldPacket.read(field);
        if (rrs.getSchema() != null) {
            fieldPacket.setDb(rrs.getSchema().getBytes());
        }
        if (rrs.getTableAlias() != null) {
            fieldPacket.setTable(rrs.getTableAlias().getBytes());
        }
        if (rrs.getTable() != null) {
            fieldPacket.setOrgTable(rrs.getTable().getBytes());
        }
        fieldPackets.add(fieldPacket);
    }
    List<Order> orderBys = new ArrayList<>();
    for (String groupBy : rrs.getGroupByCols()) {
        ItemField itemField = new ItemField(rrs.getSchema(), rrs.getTableAlias(), groupBy);
        orderBys.add(new Order(itemField));
    }
    rowComparator = new RowDataComparator(fieldPackets, orderBys);
    outputHandler.fieldEofResponse(null, null, fieldPackets, null, false, conn);
}
Also used : Order(com.actiontech.dble.plan.Order) ItemField(com.actiontech.dble.plan.common.item.ItemField) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

Example 8 with RowDataComparator

use of com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator 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 9 with RowDataComparator

use of com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator in project dble by actiontech.

the class OrderedGroupByHandler method prepareSumAggregators.

/**
 * see Sql_executor.cc
 *
 * @return
 */
protected void prepareSumAggregators(List<ItemSum> functions, List<ItemSum> sumFunctions, List<FieldPacket> packets, boolean isAllPushDown, boolean needDistinct, MySQLConnection conn) {
    LOGGER.info("prepare_sum_aggregators");
    for (int i = 0; i < functions.size(); i++) {
        ItemSum func = functions.get(i);
        ResultStore store = null;
        if (func.hasWithDistinct()) {
            ItemSum selFunc = sumFunctions.get(i);
            List<Order> orders = HandlerTool.makeOrder(selFunc.arguments());
            RowDataComparator distinctCmp = new RowDataComparator(packets, orders, isAllPushDown, this.type());
            store = new DistinctLocalResult(pool, packets.size(), distinctCmp, this.charset).setMemSizeController(session.getOtherBufferMC());
            distinctStores.add(store);
        }
        func.setAggregator(needDistinct && func.hasWithDistinct() ? AggregatorType.DISTINCT_AGGREGATOR : AggregatorType.SIMPLE_AGGREGATOR, store);
    }
}
Also used : Order(com.actiontech.dble.plan.Order) DistinctLocalResult(com.actiontech.dble.backend.mysql.store.DistinctLocalResult) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ResultStore(com.actiontech.dble.plan.common.external.ResultStore) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

Aggregations

RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)9 Order (com.actiontech.dble.plan.Order)4 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)3 Field (com.actiontech.dble.plan.common.field.Field)3 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)3 DistinctLocalResult (com.actiontech.dble.backend.mysql.store.DistinctLocalResult)2 Item (com.actiontech.dble.plan.common.item.Item)2 GroupByBucket (com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.directgroupby.GroupByBucket)1 GroupByLocalResult (com.actiontech.dble.backend.mysql.store.GroupByLocalResult)1 SortedLocalResult (com.actiontech.dble.backend.mysql.store.SortedLocalResult)1 ResultStore (com.actiontech.dble.plan.common.external.ResultStore)1 ItemField (com.actiontech.dble.plan.common.item.ItemField)1 ArrayList (java.util.ArrayList)1