private int validateGroupMax(GroupingLevel lvl) {
        int max = transform.getMax(lvl.getGroupPrototype().getTag());
        if (lvl.getExpression() instanceof RangeBucketPreDefFunctionNode) {
            int maxBuckets = ((RangeBucketPreDefFunctionNode) lvl.getExpression()).getBucketList().size() + 1; // +1 for "null" bucket
            if (maxBuckets < max || max <= 0) max = maxBuckets;
        }
        if (max <= 0) throw new IllegalInputException(
                "Cannot return unbounded number of groups when 'grouping.globalMaxGroups' is enabled. " +
                        "Either restrict group count with max() or disable 'grouping.globalMaxGroups'. " +
                        "See https://docs.vespa.ai/en/grouping.html for details.");
        return max;
    }
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