code: public static boolean sortingOrderHasNonGroupingFields(DefaultLimitSpec limitSpec, List<DimensionSpec> dimensions)
    {
      for (OrderByColumnSpec orderSpec : limitSpec.getColumns()) {
        int dimIndex = OrderByColumnSpec.getDimIndexForOrderBy(orderSpec, dimensions);
        if (dimIndex < 0) {
          return true;
        }
      }
      return false;
    }
docs: Check if a limitSpec has columns in the sorting order that are not part of the grouping fields represented
  by `dimensions`.
  
  @param limitSpec LimitSpec, assumed to be non-null
  @param dimensions Grouping fields for a groupBy query
  @return True if limitSpec has sorting columns not contained in dimensions