@Override
    public void process(Consumer<Bson> consumer) {
      final Function<Collation, Bson> toSortFn = col -> {
        final String name = naming.get(col.path());
        return col.direction().isAscending() ? Sorts.ascending(name) : Sorts.descending(name);

      };

      BsonDocument sort = new BsonDocument();
      for (Collation collation: query.collations()) {
        sort.putAll(toSortFn.apply(collation).toBsonDocument(BsonDocument.class, codecRegistry));
      }

      if (!sort.isEmpty()) {
        consumer.accept(Aggregates.sort(sort));
      }
    }
Converts query of type {@code select distinct a, b, c from table} to {@code select a, b, c from table group by a, b, c}
so same pipelines (like {@link Group}) can be (re-)used. Does nothing if this is not a {@code distinct} query.
@param query query to be converted
@return new version of the query with projections copied to {@code groupBy} list or unmodified query.
@throws UnsupportedOperationException if query is "distinct" and {@code groupBy} is not empty
criteria/mongo/src/org/immutables/criteria/mongo/AggregationQuery.java