private static GroupingExpression createGroupOrderingClause(Sorting sortingSpec) {
        GroupingExpression groupingClause = null;
        for (Sorting.FieldOrder fieldOrder : sortingSpec.fieldOrders()) {
            Sorting.Order sortOrder = fieldOrder.getSortOrder();
            groupingClause = switch (sortOrder) {
                case ASCENDING, UNDEFINED -> new AttributeValue(fieldOrder.getFieldName());
                case DESCENDING ->
                    // To sort descending, just take the negative. This is the most common case
                        new NegFunction(new AttributeValue(fieldOrder.getFieldName()));
                default -> throw new IllegalStateException("Can not handle sort order " + sortOrder + ".");
            };
        }
        return groupingClause;
    }
Create a hit ordering clause based on the sorting spec.

@param sortingSpec A (single level!) sorting specification
@return a grouping expression which produces a sortable value
container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java