}
QuerySort sortBy = query.getSort();
// A table description column lookup is enough because sorting by a column
// that has multiple matching columns after pivoting is impossible. For example,
// it is impossible to sort by an aggregation column when there is a pivot.
DataTableColumnLookup columnLookup = new DataTableColumnLookup(table);
TableRowComparator comparator = new TableRowComparator(sortBy, locale, columnLookup);
Collections.sort(table.getRows(), comparator);
return table;
}