+ member);
// If this is a non-empty constraint, it is more efficient to join to
// an aggregate table than to the fact table. See whether a suitable
// aggregate table exists.
AggStar aggStar = chooseAggStar(constraint, member);
// Create the condition, which is either the parent member or
// the full context (non empty).
constraint.addMemberConstraint(sqlQuery, null, aggStar, member);
RolapLevel level = (RolapLevel) member.getLevel().getChildLevel();
boolean levelCollapsed =
(aggStar != null)
&& isLevelCollapsed(aggStar, (RolapCubeLevel)level);
boolean multipleCols =
SqlMemberSource.levelContainsMultipleColumns(level);
if (levelCollapsed && !multipleCols) {
// if this is a single column collapsed level, there is
// no need to join it with dimension tables
RolapStar.Column starColumn =
((RolapCubeLevel) level).getStarKeyColumn();
int bitPos = starColumn.getBitPosition();
AggStar.Table.Column aggColumn = aggStar.lookupColumn(bitPos);
String q = aggColumn.generateExprString(sqlQuery);
final String qAlias =
sqlQuery.addSelectGroupBy(q, starColumn.getInternalType());
sqlQuery.addOrderBy(
q, qAlias, true, false, true, true);
aggColumn.getTable().addToFrom(sqlQuery, false, true);
return sqlQuery.toSqlAndTypes();
}
hierarchy.addToFrom(sqlQuery, level.getKeyExp());
String q = level.getKeyExp().getExpression(sqlQuery);
String idAlias =
sqlQuery.addSelectGroupBy(q, level.getInternalType());
// in non empty mode the level table must be joined to the fact
// table
constraint.addLevelConstraint(sqlQuery, null, aggStar, level);
if (levelCollapsed) {
// if this is a collapsed level, add a join between key and aggstar
RolapStar.Column starColumn =
((RolapCubeLevel) level).getStarKeyColumn();
int bitPos = starColumn.getBitPosition();
AggStar.Table.Column aggColumn = aggStar.lookupColumn(bitPos);
RolapStar.Condition condition =
new RolapStar.Condition(
level.getKeyExp(),
aggColumn.getExpression());
sqlQuery.addWhere(condition.toString(sqlQuery));
hierarchy.addToFromInverse(sqlQuery, level.getKeyExp());
// also may need to join parent levels to make selection unique
RolapCubeLevel parentLevel = (RolapCubeLevel)level.getParentLevel();
boolean isUnique = level.isUnique();
while (parentLevel != null && !parentLevel.isAll() && !isUnique) {
hierarchy.addToFromInverse(sqlQuery, parentLevel.getKeyExp());
starColumn = parentLevel.getStarKeyColumn();
bitPos = starColumn.getBitPosition();
aggColumn = aggStar.lookupColumn(bitPos);
condition =
new RolapStar.Condition(
parentLevel.getKeyExp(),
aggColumn.getExpression());
sqlQuery.addWhere(condition.toString(sqlQuery));