Github user JamesRTaylor commented on a diff in the pull request: https://github.com/apache/phoenix/pull/308#discussion_r203879864 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java --- @@ -135,17 +142,24 @@ public ResultIterator iterator(ParallelScanGrouper scanGrouper, Scan scan) throw aggResultIterator = new ClientUngroupedAggregatingResultIterator(LookAheadResultIterator.wrap(iterator), serverAggregators); aggResultIterator = new UngroupedAggregatingResultIterator(LookAheadResultIterator.wrap(aggResultIterator), clientAggregators); } else { - if (!groupBy.isOrderPreserving()) { - int thresholdBytes = context.getConnection().getQueryServices().getProps().getInt( - QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES); - List<Expression> keyExpressions = groupBy.getKeyExpressions(); + List<Expression> keyExpressions = groupBy.getKeyExpressions(); + if (groupBy.isOrderPreserving()) { + aggResultIterator = new ClientGroupedAggregatingResultIterator(LookAheadResultIterator.wrap(iterator), serverAggregators, keyExpressions); --- End diff -- Pass through context here too to ClientGroupedAggregatingResultIterator as you'll need it to get the memory manager.
---