kadirozde commented on a change in pull request #936:
URL: https://github.com/apache/phoenix/pull/936#discussion_r520749622
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/iterate/UngroupedAggregatingResultIterator.java
##########
@@ -33,21 +34,37 @@
public UngroupedAggregatingResultIterator( PeekingResultIterator
resultIterator, Aggregators aggregators) {
super(resultIterator, aggregators);
}
-
@Override
public Tuple next() throws SQLException {
- Tuple result = super.next();
- // Ensure ungrouped aggregregation always returns a row, even if the
underlying iterator doesn't.
- if (result == null && !hasRows) {
- // We should reset ClientAggregators here in case they are being
reused in a new ResultIterator.
- aggregators.reset(aggregators.getAggregators());
- byte[] value = aggregators.toBytes(aggregators.getAggregators());
- result = new SingleKeyValueTuple(
- KeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY,
- SINGLE_COLUMN_FAMILY,
- SINGLE_COLUMN,
- AGG_TIMESTAMP,
- value));
+ Tuple result = resultIterator.next();
+ if (result == null) {
+ // Ensure ungrouped aggregregation always returns a row, even if
the underlying iterator doesn't.
+ if (!hasRows) {
+ // We should reset ClientAggregators here in case they are
being reused in a new ResultIterator.
+ aggregators.reset(aggregators.getAggregators());
+ byte[] value =
aggregators.toBytes(aggregators.getAggregators());
+ result = new SingleKeyValueTuple(
+ KeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY,
+ SINGLE_COLUMN_FAMILY,
+ SINGLE_COLUMN,
+ AGG_TIMESTAMP,
+ value));
+ }
+ } else {
+ Aggregator[] rowAggregators = aggregators.getAggregators();
+ aggregators.reset(rowAggregators);
+ while (true) {
+ aggregators.aggregate(rowAggregators, result);
+ Tuple nextResult = resultIterator.peek();
+ if (nextResult == null) {
+ break;
+ }
+ result = resultIterator.next();
Review comment:
Yes, your understanding is correct.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]