private void validateGlobalMax() {
        if (globalMaxGroups < 0) return;

        this.totalGroupsAndSummaries = -1;
        int totalGroupsAndSummaries = 0;
        for (Grouping grp : requestList) {
            int levelMultiplier = 1;
            for (GroupingLevel lvl : grp.getLevels()) {
                totalGroupsAndSummaries += (levelMultiplier *= validateGroupMax(lvl));
                var hars = hitsAggregationResult(lvl);
                for (HitsAggregationResult har : hars) {
                    totalGroupsAndSummaries += (levelMultiplier * validateSummaryMax(har));
                }
            }
        }
        if (totalGroupsAndSummaries > globalMaxGroups)
            throw new IllegalInputException(String.format(
                    "The theoretical total number of groups and summaries in grouping query exceeds " +
                            "'grouping.globalMaxGroups' ( %d > %d ). " +
                            "Either restrict group/summary counts with max() or disable 'grouping.globalMaxGroups'. " +
                            "See https://docs.vespa.ai/en/grouping.html for details.",
                    totalGroupsAndSummaries, globalMaxGroups));
        this.totalGroupsAndSummaries = totalGroupsAndSummaries;
    }
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