### Question:
ShardingResultSet { protected abstract void aggregateRows(List<byte[]> newRows); ShardingResultSet(List<AggregateFunc> columnAggeTypes, boolean isGroupBy); void addColumn(List<byte[]> columns, int shardingIndex); void addRow(List<byte[]> rows, int shardingIndex); void addCommandComplete(byte[] commandComplete); void addReadyForQuery(byte[] readForQuery); abstract List<byte[]> toPartPackets(boolean withEOF); int getSelectResultSetBufSize(); public long sequenceId; public List<byte[]> columns; public List<byte[]> rows; public List<byte[]> commandCompletes; public List<byte[]> readyForQuerys; }### Answer:
@Test public void aggregateRows() { List<AggregateFunc> columnAggeTypes = new ArrayList<>(); columnAggeTypes.add(AggregateFunc.COUNT); columnAggeTypes.add(AggregateFunc.SUM); columnAggeTypes.add(AggregateFunc.MAX); columnAggeTypes.add(AggregateFunc.MIN); columnAggeTypes.add(AggregateFunc.MIN); ShardingResultSet result = new MysqlShardingResultSet(columnAggeTypes, false); List<byte[]> columns = new ArrayList<>(); columnAggeTypes.forEach(type -> { columns.add(new Column(type.name()).toPacket()); }); result.addColumn(columns, 1); Row r1 = new Row(); r1.addData("1"); r1.addData("1"); r1.addData("1"); r1.addData("1"); r1.addData((String) null); List<byte[]> row1s = new ArrayList<>(); row1s.add(r1.toPacket()); result.addRow(row1s, 1); Row r2 = new Row(); r2.addData("2"); r2.addData("2.01"); r2.addData("12345678901234567890"); r2.addData("-2"); r2.addData((String) null); List<byte[]> row2s = new ArrayList<>(); row2s.add(r2.toPacket()); result.addRow(row2s, 2); Row r3 = new Row(); r3.addData("3"); r3.addData((String) null); r3.addData((String) null); r3.addData((String) null); r3.addData((String) null); List<byte[]> row3s = new ArrayList<>(); row3s.add(r3.toPacket()); result.addRow(row3s, 3); Row aaggregatedRow = Row.loadFromPacket(result.toPartPackets(false).get(7), 5); Assert.assertEquals(aaggregatedRow.toString(), "6,3.01,12345678901234567890,-2,null"); }