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