Source:
protected Grouper<ByteBuffer> newGrouper() { Grouper grouper = null; final DefaultLimitSpec limitSpec = query.isApplyLimitPushDown() && querySpecificConfig.isApplyLimitPushDownToSegment() ? (DefaultLimitSpec) query.getLimitSpec() : null; boolean canDoPushdown = false; if (limitSpec != null) { canDoPushdown = canPushdownLimit(query.getDimensions().stream().map(DimensionSpec::getDimension)); canDoPushdown &= canPushdownLimit(limitSpec.getColumns().stream().map(OrderByColumnSpec::getDimension)); } if (canDoPushdown) { LimitedBufferHashGrouper limitGrouper = new LimitedBufferHashGrouper<>( Suppliers.ofInstance(buffer), keySerde, AggregatorAdapters.factorizeBuffered( cursor.getColumnSelectorFactory(), query.getAggregatorSpecs() ), querySpecificConfig.getBufferGrouperMaxSize(), querySpecificConfig.getBufferGrouperMaxLoadFactor(), querySpecificConfig.getBufferGrouperInitialBuckets(), limitSpec.getLimit(), DefaultLimitSpec.sortingOrderHasNonGroupingFields( limitSpec, query.getDimensions() ) ); if (limitGrouper.validateBufferCapacity(buffer.capacity())) { grouper = limitGrouper; } else { LOGGER.warn( "Limit is not applied in segment scan phase due to limited buffer capacity for query [%s].", query.getId() ); } } if (grouper == null) { grouper = new BufferHashGrouper<>( Suppliers.ofInstance(buffer), keySerde, AggregatorAdapters.factorizeBuffered( cursor.getColumnSelectorFactory(), query.getAggregatorSpecs() ), querySpecificConfig.getBufferGrouperMaxSize(), querySpecificConfig.getBufferGrouperMaxLoadFactor(), querySpecificConfig.getBufferGrouperInitialBuckets(), true ); } return grouper; }

Target:
protected Grouper<ByteBuffer> newGrouper() { Grouper<ByteBuffer> grouper = null; final ColumnSelectorFactory selectorFactory = cursor.getColumnSelectorFactory(); final DefaultLimitSpec limitSpec = query.isApplyLimitPushDown() && querySpecificConfig.isApplyLimitPushDownToSegment() ? (DefaultLimitSpec) query.getLimitSpec() : null; final boolean canDoLimitPushdown; if (limitSpec != null) { canDoLimitPushdown = Stream.concat( query.getDimensions().stream().map(DimensionSpec::getDimension), limitSpec.getColumns().stream().map(OrderByColumnSpec::getDimension) ).allMatch(col -> GroupByQueryEngineV2.canPushDownLimit(selectorFactory, col)); } else { canDoLimitPushdown = false; } if (canDoLimitPushdown) { LimitedBufferHashGrouper<ByteBuffer> limitGrouper = new LimitedBufferHashGrouper<>( Suppliers.ofInstance(buffer), keySerde, AggregatorAdapters.factorizeBuffered( selectorFactory, query.getAggregatorSpecs() ), querySpecificConfig.getBufferGrouperMaxSize(), querySpecificConfig.getBufferGrouperMaxLoadFactor(), querySpecificConfig.getBufferGrouperInitialBuckets(), limitSpec.getLimit(), DefaultLimitSpec.sortingOrderHasNonGroupingFields( limitSpec, query.getDimensions() ) ); if (limitGrouper.validateBufferCapacity(buffer.capacity())) { grouper = limitGrouper; } else { LOGGER.warn( "Limit is not applied in segment scan phase due to limited buffer capacity for query [%s].", query.getId() ); } } if (grouper == null) { grouper = new BufferHashGrouper<>( Suppliers.ofInstance(buffer), keySerde, AggregatorAdapters.factorizeBuffered( selectorFactory, query.getAggregatorSpecs() ), querySpecificConfig.getBufferGrouperMaxSize(), querySpecificConfig.getBufferGrouperMaxLoadFactor(), querySpecificConfig.getBufferGrouperInitialBuckets(), true ); } return grouper; }