}
protected DataSetGroupIndex nestedGroup(DataSetGroup op, DataSetGroupIndex lastGroupIndex, InternalContext context) {
// Index match => Reuse it
DataSetGroupIndex nestedGroupIndex = lastGroupIndex.getGroupIndex(op.getColumnGroup());
if (nestedGroupIndex != null) return nestedGroupIndex;
// No index match => Create a brand new group index
nestedGroupIndex = new DataSetGroupIndex(op.getColumnGroup());
// Apply the nested group operation on each parent group interval.
InternalContext nestedContext = new InternalContext(context.dataSet, null);
List<DataSetIntervalIndex> intervalsIdxs = lastGroupIndex.getIntervalIndexes();
for (DataSetIntervalIndex intervalIndex : intervalsIdxs) {
// In a nested group the intervals can aggregate other intervals.
if (intervalIndex instanceof DataSetIntervalSetIndex) {
DataSetIntervalSetIndex indexSet = (DataSetIntervalSetIndex) intervalIndex;
for (DataSetIntervalIndex subIndex : indexSet.getIntervalIndexes()) {
nestedContext.index = subIndex;
DataSetGroupIndex sg = singleGroup(op, nestedContext);
nestedGroupIndex.indexIntervals(sg.getIntervalIndexes());
}
}
// Or can just be single intervals.
else {
nestedContext.index = intervalIndex;
DataSetGroupIndex sg = singleGroup(op, nestedContext);
nestedGroupIndex.indexIntervals(sg.getIntervalIndexes());
}
}
context.index.indexGroup(nestedGroupIndex);
return nestedGroupIndex;
}