private void resolveGroupBy(BuildFrame frame) {
        GroupingExpression exp = frame.astNode.getGroupBy();
        if (exp != null) {
            if (frame.state.groupBy != null) {
                throw new IllegalInputException("Can not group list of groups.");
            }
            frame.state.groupBy = converter.toExpressionNode(exp);
            frame.state.label = exp.toString(); // label for next each()

        } else {
            int level = frame.astNode.getLevel();
            if (level == 0) {
                // no next each()
            } else if (level == 1) {
                frame.state.label = "hits"; // next each() is hitlist
            } else {
                throw new IllegalInputException("Can not create anonymous " +
                                                        GroupingOperation.getLevelDesc(level) + ".");
            }
        }
    }
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