private AggregationResult toAggregationResult(GroupingExpression exp, Group group, BuildFrame frame) {
        AggregationResult result = converter.toAggregationResult(exp);
        result.setTag(++tag);

        String label = exp.getLabel();
        if (result instanceof HitsAggregationResult hits) {
            if (label != null) {
                throw new IllegalInputException("Can not label expression '" + exp + "'.");
            }
            if (frame.state.max != null) {
                transform.putMax(tag, frame.state.max, "hit list");
                int offset = transform.getOffset(tag);
                hits.setMaxHits(LOOKAHEAD + frame.state.max + offset);
                frame.state.max = null;
            }
            transform.putLabel(group.getTag(), tag, frame.state.label, "hit list");
        } else {
            transform.putLabel(group.getTag(), tag, label != null ? label : exp.toString(), "output");
        }
        return result;
    }
Constructs a set of Vespa specific grouping request that corresponds to the parameters given to this builder.
This method might fail due to unsupported constructs in the request, in which case an exception is thrown.

@throws IllegalStateException         If this method is called more than once.
@throws IllegalInputException If the grouping request contains unsupported constructs.
container-search/src/main/java/com/yahoo/search/grouping/vespa/RequestBuilder.java