// Group the original data set by the domain property. Thus the scalar function is applied to the range values.
DataSet sourceDataSet = domainProperty.getDataSet();
List<DataProperty> targetDataProps = Arrays.asList(new DataProperty[]{domainProperty, rangeProperty});
List<String> targetFunctionCodes = Arrays.asList(new String[]{CountFunction.CODE, scalarFunction.getCode()});
targetDataSet = sourceDataSet.groupBy(domainProperty, targetDataProps, targetFunctionCodes);
// Sort the resulting data set according to the sort policy specified.
if (intervalsSortOrder != INTERVALS_SORT_ORDER_NONE) {
DataSetComparator comp = new DataSetComparator();
comp.addSortCriteria(Integer.toString(intervalsSortCriteria), intervalsSortOrder);