Skip to content

Commit

Permalink
[MONDRIAN-2124] Cell queries are not aggregated when ignored/un-match…
Browse files Browse the repository at this point in the history
…ed columns are present

There's logic in AggregationManager.findAgg() which determines whether or not it's possible to omit the rollup when pulling data
from an aggregate table.  This is allowed, for example, if the granularity of the request matches the granularity of the agg table.
Formerly we were determining whether the granularity is the same  by looking at whether the bitkeys matched, and whether
the agg table was fully collapsed.  This left open the possibility that ignored or unused columns in the agg table could result in difft
 granularity.  Now we take the conservative stance that presence of any ignored column means that we have to rollup.
 Similary, for distinct-count measures, if an ignored or unused column is present, we now make the assumption that the agg table
 cannot be safely used.
  • Loading branch information
mkambol committed Jun 18, 2014
1 parent 8cfaafe commit ce288b4
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 21 deletions.
13 changes: 11 additions & 2 deletions src/main/mondrian/rolap/agg/AggregationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
// You must accept the terms of that agreement to use this software.
//
// Copyright (C) 2001-2005 Julian Hyde
// Copyright (C) 2005-2013 Pentaho and others
// Copyright (C) 2005-2014 Pentaho and others
// All Rights Reserved.
//
// jhyde, 30 August, 2001
*/

package mondrian.rolap.agg;

import mondrian.olap.CacheControl;
Expand Down Expand Up @@ -378,9 +377,19 @@ public static AggStar findAgg(
// the agg stars levels, or if the agg star is not
// fully collapsed.
rollup[0] = !aggStar.isFullyCollapsed()
|| aggStar.hasIgnoredColumns()
|| (levelBitKey.isEmpty()
|| !aggStar.getLevelBitKey().equals(levelBitKey));
return aggStar;
} else if (aggStar.hasIgnoredColumns()) {
// we cannot safely pull a distinct count from an agg
// table if ignored columns are present since granularity
// may not be at the level of the dc measure
LOGGER.info(
aggStar.getFactTable().getName()
+ " cannot be used for distinct-count measures since it has"
+ " unused or ignored columns.");
continue;
}

// If there are distinct measures, we can only rollup in limited
Expand Down
10 changes: 8 additions & 2 deletions src/main/mondrian/rolap/aggmatcher/AggStar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// You must accept the terms of that agreement to use this software.
//
// Copyright (C) 2005-2005 Julian Hyde
// Copyright (C) 2005-2013 Pentaho and others
// Copyright (C) 2005-2014 Pentaho and others
// All Rights Reserved.
*/

package mondrian.rolap.aggmatcher;

import mondrian.olap.*;
Expand Down Expand Up @@ -55,6 +54,7 @@
*/
public class AggStar {
private static final Logger LOGGER = Logger.getLogger(AggStar.class);
private boolean hasIgnoredColumns;

static Logger getLogger() {
return LOGGER;
Expand Down Expand Up @@ -110,6 +110,8 @@ public static AggStar makeAggStar(
JdbcSchema.Table.Column.Usage usage = it.next();
aggStarFactTable.loadLevel(usage);
}
aggStar.hasIgnoredColumns =
dbTable.getColumnUsages(UsageType.IGNORE).hasNext();

// 5. for each distinct-count measure, populate a list of the levels
// which it is OK to roll up
Expand Down Expand Up @@ -450,6 +452,10 @@ private void addColumn(final AggStar.Table.Column column) {
private static final Logger JOIN_CONDITION_LOGGER =
Logger.getLogger(AggStar.Table.JoinCondition.class);

public boolean hasIgnoredColumns() {
return hasIgnoredColumns;
}

/**
* Base Table class for the FactTable and DimTable classes.
* This class parallels the RolapStar.Table class.
Expand Down
5 changes: 3 additions & 2 deletions src/main/mondrian/rolap/aggmatcher/Recognizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// You must accept the terms of that agreement to use this software.
//
// Copyright (C) 2005-2005 Julian Hyde
// Copyright (C) 2005-2012 Pentaho and others
// Copyright (C) 2005-2014 Pentaho and others
// All Rights Reserved.
*/

package mondrian.rolap.aggmatcher;

import mondrian.olap.*;
Expand Down Expand Up @@ -757,6 +756,8 @@ protected void checkUnusedColumns() {
dbFactTable.getName(),
aggColumn.getName());
unusedColumnMsgs.put(aggColumn.getName(), msg);
// since the column has no usage it will be ignored
makeIgnore(aggColumn);
}
}
for (String msg : unusedColumnMsgs.values()) {
Expand Down
Loading

0 comments on commit ce288b4

Please sign in to comment.