Search in sources :

Example 11 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class SingleRowSubQueryHandler method rowResponse.

@Override
public boolean rowResponse(byte[] rowNull, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
    lock.lock();
    try {
        if (terminate.get()) {
            return true;
        }
        if (++rowCount > 1) {
            String errMessage = "Subquery returns more than 1 row";
            LOGGER.info(errMessage);
            genErrorPackage(ErrorCode.ER_SUBQUERY_NO_1_ROW, errMessage);
            return true;
        }
        RowDataPacket row = rowPacket;
        if (row == null) {
            row = new RowDataPacket(this.fieldPackets.size());
            row.read(rowNull);
        }
        if (!itemSubQuery.isField()) {
            setSubQueryFiled();
        }
        sourceField.setPtr(row.getValue(0));
    } finally {
        lock.unlock();
    }
    return false;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ItemString(com.actiontech.dble.plan.common.item.ItemString)

Example 12 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class TempTableHandler method rowEofResponse.

@Override
public void rowEofResponse(byte[] eof, boolean isLeft, BackendConnection conn) {
    lock.lock();
    try {
        // callBack after terminated
        if (terminate.get()) {
            return;
        }
        tempTable.dataEof();
        // locked onTerminate, because terminated may sync with start
        tempDoneCallBack.call();
        RowDataPacket rp = null;
        while ((rp = tempTable.nextRow()) != null) {
            nextHandler.rowResponse(null, rp, this.isLeft, conn);
        }
        nextHandler.rowEofResponse(eof, this.isLeft, conn);
    } catch (Exception e) {
        LOGGER.info("rowEof exception!", e);
        throw new TempTableException("rowEof exception!", e);
    } finally {
        lock.unlock();
    }
}
Also used : TempTableException(com.actiontech.dble.plan.common.exception.TempTableException) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) TempTableException(com.actiontech.dble.plan.common.exception.TempTableException)

Example 13 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class DirectGroupByHandler method sendGroupRowPacket.

private void sendGroupRowPacket(MySQLConnection conn) {
    groupLocalResult.done();
    RowDataPacket row = null;
    List<Field> localFields = HandlerTool.createFields(localResultFps);
    List<ItemSum> sendSums = new ArrayList<>();
    for (ItemSum selSum : referredSumFunctions) {
        ItemSum sum = (ItemSum) HandlerTool.createItem(selSum, localFields, 0, false, HandlerType.GROUPBY);
        sendSums.add(sum);
    }
    prepareSumAggregators(sendSums, true);
    while ((row = groupLocalResult.next()) != null) {
        if (sendGroupRowPacket(conn, row, sendSums))
            break;
    }
}
Also used : Field(com.actiontech.dble.plan.common.field.Field) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList)

Example 14 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class OrderedGroupByHandler method sendNoRowGroupRowPacket.

/**
 * send data to next even no data here. eg: select count(*) from t2 ,if t2 empty,then send 0
 */
private void sendNoRowGroupRowPacket(MySQLConnection conn) {
    RowDataPacket newRp = new RowDataPacket(this.fieldPackets.size() + this.sums.size());
    // sumfuncs are front
    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);
    }
    originRp = 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 15 with RowDataPacket

use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.

the class GroupByLocalResult method add.

/* should group sumfunctions when find a row in rows */
@Override
public void add(RowDataPacket row) {
    lock.lock();
    try {
        if (isClosed)
            return;
        int index = rows.indexOf(row);
        int incrementSize = 0;
        if (index >= 0) /* found */
        {
            RowDataPacket oldRow = rows.get(index);
            int oldRowSizeBefore = getRowMemory(oldRow);
            onFoundRow(oldRow, row);
            int oldRowSizeAfter = getRowMemory(oldRow);
            incrementSize = oldRowSizeAfter - oldRowSizeBefore;
        } else {
            onFirstGroupRow(row);
            rows.add(row);
            rowCount++;
            incrementSize = getRowMemory(row);
        }
        currentMemory += incrementSize;
        boolean needFlush = false;
        if (bufferMC != null) {
            if (!bufferMC.addSize(incrementSize)) {
                needFlush = true;
            }
        } else if (currentMemory > maxMemory) {
            needFlush = true;
        }
        if (needFlush) {
            if (external == null)
                external = makeExternal();
            addRowsToDisk();
        }
    } finally {
        lock.unlock();
    }
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Aggregations

RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)141 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)59 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)59 ByteBuffer (java.nio.ByteBuffer)59 ServerConfig (com.actiontech.dble.config.ServerConfig)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)8 Map (java.util.Map)8 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)7 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)7 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)7 LocalResult (com.actiontech.dble.backend.mysql.store.LocalResult)6 UnSortedLocalResult (com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)6 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)5 UserStat (com.actiontech.dble.statistic.stat.UserStat)5 BackendConnection (com.actiontech.dble.backend.BackendConnection)4 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 FrontendConnection (com.actiontech.dble.net.FrontendConnection)4 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)4 LinkedList (java.util.LinkedList)4