return ret;
}
private CubeScan getCubeScan(CubeQuery query, CubeDescriptor cubeDescriptor) throws Exception{
String methodName = "getCubeScan() ";
CubeScan scan = new CubeScan();
List<CubeIndexEntry> index = null;
for(CubeQueryCondition condition: query.getConditions()) {
String dimensionName = condition.getDimensionName();
if(logger.isDebugEnabled()) logger.debug(methodName + "process dimension " + dimensionName);
int dimensionNumber = getDimensionNumber(dimensionName, cubeDescriptor);
if(logger.isDebugEnabled()) logger.debug(methodName + "dimensionNumber = " + dimensionNumber);
List<CubeIndexEntry> dimIndex = new ArrayList<CubeIndexEntry>();
for(long dimVal: condition.dimensionValues) {
List<CubeIndexEntry> dimValIndex = getIndexForDimensionValue(dimensionNumber, dimVal, cubeDescriptor);
dimIndex = mergeIndexes(dimIndex, dimValIndex);
}
if(index == null)
index = dimIndex;
else
index = joinIndexes(index, dimIndex);
long values[] = new long[condition.getDimensionValues().size()];
for(int i = 0; i < values.length; i ++)
values[i] = condition.getDimensionValues().get(i);
scan.getConditions().add(new CubeScanCondition(dimensionNumber, values));
}
if(logger.isDebugEnabled()) logger.debug(methodName + "final index size: " + index.size());
for(CubeIndexEntry indexEntry: index) {
byte startRow[] = getStartRow(indexEntry, cubeDescriptor.dimensions.size());
byte stopRow[] = getStopRow(indexEntry, cubeDescriptor.dimensions.size());
if(logger.isDebugEnabled()) logger.debug(methodName + "add range [" + LogUtils.describe(startRow)
+ ", " + LogUtils.describe(stopRow) + "] to scan.");
Pair<byte[], byte[]> range = new Pair<byte[], byte[]>(startRow, stopRow);
scan.getRanges().add(range);
}
for(CubeQueryAggregate aggregate: query.getAggregates())
scan.getCubeScanAggregates().add(getCubeScanAggregate(aggregate, cubeDescriptor));
int groupBy[] = new int[query.getGroupBy().size()];
for(int i = 0; i < groupBy.length; i ++)
groupBy[i] = getDimensionNumber(query.getGroupBy().get(i), cubeDescriptor);
scan.setGroupBy(groupBy);
scan.prepare();
return scan;
}