Skip to content

Commit

Permalink
MONDRIAN-643 non joining dimensions on other axes should not be inclu…
Browse files Browse the repository at this point in the history
…ded with native sql constraints

[git-p4: depot-paths = "//open/mondrian/": change = 13137]
  • Loading branch information
Matt Campbell authored and Matt Campbell committed Oct 28, 2009
1 parent c732986 commit d01301d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/main/mondrian/rolap/RolapNativeSet.java
Expand Up @@ -8,10 +8,16 @@
*/
package mondrian.rolap;

import java.util.*;

import mondrian.calc.*;
import mondrian.calc.ExpCompiler;
import mondrian.calc.ListCalc;
import mondrian.calc.ResultStyle;
import mondrian.mdx.LevelExpr;
import mondrian.mdx.MemberExpr;
import mondrian.mdx.NamedSetExpr;
import mondrian.mdx.ResolvedFunCall;
import mondrian.olap.*;
import static mondrian.rolap.RolapLevel.HideMemberCondition.IfBlankName;
import static mondrian.rolap.RolapLevel.HideMemberCondition.Never;
import mondrian.rolap.TupleReader.MemberBuilder;
import mondrian.rolap.aggmatcher.AggStar;
import mondrian.rolap.cache.HardSmartCache;
Expand All @@ -20,13 +26,10 @@
import mondrian.rolap.sql.MemberChildrenConstraint;
import mondrian.rolap.sql.SqlQuery;
import mondrian.rolap.sql.TupleConstraint;
import mondrian.mdx.*;

import static mondrian.rolap.RolapLevel.HideMemberCondition.*;

import org.apache.log4j.Logger;

import javax.sql.DataSource;
import java.util.*;

/**
* Analyses set expressions and executes them in SQL if possible.
Expand Down Expand Up @@ -100,11 +103,20 @@ public void addConstraint(
if (!(arg instanceof MemberListCrossJoinArg)
|| !((MemberListCrossJoinArg) arg).hasCalcMembers())
{
arg.addConstraint(sqlQuery, baseCube, aggStar);
RolapLevel level = arg.getLevel();
if (level == null || levelIsOnBaseCube(baseCube, level)) {
arg.addConstraint(sqlQuery, baseCube, aggStar);
}
}
}
}

private boolean levelIsOnBaseCube(
final RolapCube baseCube, final RolapLevel level)
{
return baseCube.findBaseCubeHierarchy(level.getHierarchy()) != null;
}

/**
* Returns null to prevent the member/childern from being cached. There
* exists no valid MemberChildrenConstraint that would fetch those
Expand Down
18 changes: 18 additions & 0 deletions testsrc/main/mondrian/rolap/NonEmptyTest.java
Expand Up @@ -3932,6 +3932,24 @@ public void testNativeCrossjoinWillConstrainUsingArgsFromAllAxes() {
assertQuerySql(mdx, new SqlPattern[]{pattern});
}

public void testNonJoiningDimIsNotIncludedInNativeTupleQuery() {
String mdxQuery = "select\n"
+ " non empty {[Warehouse].[All Warehouses].[USA].[CA].[Beverly Hills].[Big Quality Warehouse]} on 0, "
+ " non empty Crossjoin([Gender].[Gender].members ,{[Marital Status].[Marital Status].members}) on 1, "
+ " non empty {[Measures].[Unit Sales]} on 2"
+ "from [Warehouse and Sales]";
SqlPattern[] expectedPatterns = {
new SqlPattern(
Dialect.DatabaseProduct.ACCESS,
"select `customer`.`gender` as `c0`, `customer`.`marital_status` as `c1` "
+ "from `customer` as `customer`, `sales_fact_1997` as `sales_fact_1997` "
+ "where `sales_fact_1997`.`customer_id` = `customer`.`customer_id` "
+ "group by `customer`.`gender`, `customer`.`marital_status` "
+ "order by 1 ASC, 2 ASC", 286)
};
assertQuerySql(mdxQuery, expectedPatterns);
}

/**
* Make sure the mdx runs correctly and not in native mode.
*
Expand Down

0 comments on commit d01301d

Please sign in to comment.