return dataSet;
}
private DataSet _buildDataSet(InternalContext context, DataSetGroup op) {
DataSetGroupIndex index = context.lastGroupIndex;
DataSet dataSet = context.dataSet;
ColumnGroup columnGroup = op.getColumnGroup();
List<GroupFunction> groupFunctions = op.getGroupFunctions();
// Data set header.
DataSet result = DataSetFactory.newDataSet();
result.addColumn(columnGroup.getColumnId(), ColumnType.LABEL);
for (GroupFunction groupFunction : op.getGroupFunctions()) {
result.addColumn(groupFunction.getColumnId(), ColumnType.NUMBER);
}
// Add the aggregate calculations to the result.
List<DataSetIntervalIndex> intervalIdxs = index.getIntervalIndexes();
for (int i=0; i<intervalIdxs.size(); i++) {
DataSetIntervalIndex intervalIdx = intervalIdxs.get(i);
result.setValueAt(i, 0, intervalIdx.getName());
// Add the aggregate calculations.
for (int j=0; j< groupFunctions.size(); j++) {
GroupFunction groupFunction = groupFunctions.get(j);
DataColumn dataColumn = dataSet.getColumnById(groupFunction.getSourceId());
if (dataColumn == null) dataColumn = dataSet.getColumnByIndex(0);
Double aggValue = _calculateFunction(dataColumn, groupFunction.getFunction(), intervalIdx);
result.setValueAt(i, j + 1, aggValue);
}
}
return result;
}