if (query.getScenario() != null) {
LOG.info("Query (" + queryName + ") removing scenario:" + query.getScenario().getId());
con.setScenario(null);
}
CellDataSet result = OlapResultSetUtil.cellSet2Matrix(cellSet, formatter);
Long format = new Date().getTime();
result.setRuntime(new Double(format - start).intValue());
getIQuery(queryName).storeCellset(cellSet);
getIQuery(queryName).storeFormatter(formatter);
// we could do a check if query.getTotalFunctions() actually includes a total function and if not
// dont execute the following
if (QueryType.QM.equals(query.getType()) && formatter instanceof FlattenedCellSetFormatter) {
QueryDimension queryDimension = query.getDimension("Measures");
Measure[] selectedMeasures = new Measure[queryDimension.getInclusions().size()];
for (int i = 0; i < selectedMeasures.length; i++) {
selectedMeasures[i] = (Measure) queryDimension.getInclusions().get(i).getRootElement();
}
result.setSelectedMeasures(selectedMeasures);
int rowsIndex = 0;
if (!cellSet.getAxes().get(0).getAxisOrdinal().equals(Axis.ROWS)) {
rowsIndex = rowsIndex + 1 & 1;
}
// TODO - refactor this using axis ordinals etc.
//@formatter:off
final AxisInfo[] axisInfos = new AxisInfo[] { new AxisInfo(cellSet.getAxes().get(rowsIndex)),
new AxisInfo(cellSet.getAxes().get(rowsIndex + 1 & 1)) };
//@formatter:on
List<TotalNode>[][] totals = new List[2][];
TotalsListsBuilder builder = null;
for (int index = 0; index < 2; index++) {
final int second = index + 1 & 1;
TotalAggregator[] aggregators = new TotalAggregator[axisInfos[second].maxDepth + 1];
for (int i = 1; i < aggregators.length - 1; i++) {
String totalFunctionName = query.getTotalFunction(axisInfos[second].uniqueLevelNames.get(i - 1));
aggregators[i] = TotalAggregator.newInstanceByFunctionName(totalFunctionName);
}
String totalFunctionName = query.getTotalFunction(axisInfos[second].axis.getAxisOrdinal().name());
aggregators[0] =
totalFunctionName != null ? TotalAggregator.newInstanceByFunctionName(totalFunctionName) : null;
builder = new TotalsListsBuilder(selectedMeasures, aggregators, cellSet, axisInfos[index], axisInfos[second]);
totals[index] = builder.buildTotalsLists();
}
result.setLeftOffset(axisInfos[0].maxDepth);
result.setRowTotalsLists(totals[1]);
result.setColTotalsLists(totals[0]);
}
Long totals = new Date().getTime();
LOG.info(runId + "\tSize: " + result.getWidth() + "/" + result.getHeight() + "\tExecute:\t" + (exec - start)
+ "ms\tFormat:\t" + (format - exec) + "ms\tTotals:\t" + (totals - format) + "ms\t Total: " + (totals
- start)
+ "ms");
return result;