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);
}
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);
}
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);
}
}
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);
}
}
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;
}
Aggregations