This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1dc3f43 optimize cacheCurrentRow logic of GroupByStreamMergeResult
(#10142)
1dc3f43 is described below
commit 1dc3f430ca4192c85d53dc207af969a853bcf524
Author: zhaojun <[email protected]>
AuthorDate: Wed Apr 21 23:18:14 2021 +0800
optimize cacheCurrentRow logic of GroupByStreamMergeResult (#10142)
---
.../sharding/merge/dql/groupby/GroupByStreamMergedResult.java | 6 +++++-
.../sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
index d33cb04..2ad9ce9 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResult.java
@@ -73,11 +73,15 @@ public final class GroupByStreamMergedResult extends
OrderByStreamMergedResult {
private boolean aggregateCurrentGroupByRowAndNext() throws SQLException {
boolean result = false;
+ boolean cachedRow = false;
Map<AggregationProjection, AggregationUnit> aggregationUnitMap =
Maps.toMap(
selectStatementContext.getProjectionsContext().getAggregationProjections(),
input -> AggregationUnitFactory.create(input.getType(), input instanceof
AggregationDistinctProjection));
while (currentGroupByValues.equals(new
GroupByValue(getCurrentQueryResult(),
selectStatementContext.getGroupByContext().getItems()).getGroupValues())) {
aggregate(aggregationUnitMap);
- cacheCurrentRow();
+ if (!cachedRow) {
+ cacheCurrentRow();
+ cachedRow = true;
+ }
result = super.next();
if (!result) {
break;
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
index 225c2c8..0a0ece0 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
@@ -114,7 +114,7 @@ public final class GroupByStreamMergedResultTest {
when(queryResult1.getValue(6, Object.class)).thenReturn(20);
QueryResult queryResult2 = mockQueryResult();
when(queryResult2.next()).thenReturn(true, true, true, false);
- when(queryResult2.getValue(1, Object.class)).thenReturn(20, 30, 30,
40);
+ when(queryResult2.getValue(1, Object.class)).thenReturn(20, 30, 40);
when(queryResult2.getValue(2, Object.class)).thenReturn(0);
when(queryResult2.getValue(3, Object.class)).thenReturn(2, 2, 3, 3, 3,
4);
when(queryResult2.getValue(5, Object.class)).thenReturn(2, 2, 3, 3, 3,
4);