Skip to content

Commit

Permalink
MONDRIAN: fix for BISERVER-2491, partial rollup was returning empty m…
Browse files Browse the repository at this point in the history
…ember lists. The solution was to add Member.isEvaluated(), which is slightly different than isCalculated(), and only used in the RolapEvaluator.

[git-p4: depot-paths = "//open/mondrian/": change = 12198]
  • Loading branch information
Will Gorman committed Jan 5, 2009
1 parent c4aedf0 commit 77bd7b0
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/main/mondrian/olap/Member.java
Expand Up @@ -99,6 +99,16 @@ enum MemberType {
* member</code> clause in an mdx query or a calculated member defined in
* cube. */
boolean isCalculated();

/**
* Returns whether this member should be evaluated within the Evaluator, normally
* isCalculated() and isEvaluated() should return the same value, but in situations
* where mondrian would like to treat the two concepts separately such in role based
* security, these values may differ.
*
* @return true if evaluated
*/
boolean isEvaluated();
int getSolveOrder();
Exp getExpression();

Expand Down
4 changes: 4 additions & 0 deletions src/main/mondrian/olap/MemberBase.java
Expand Up @@ -158,6 +158,10 @@ public boolean isCalculated() {
return (flags & FLAG_CALCULATED) != 0;
}

public boolean isEvaluated() {
return isCalculated();
}

public OlapElement lookupChild(
SchemaReader schemaReader,
Id.Segment childName)
Expand Down
4 changes: 4 additions & 0 deletions src/main/mondrian/olap/fun/FunUtil.java
Expand Up @@ -2665,6 +2665,10 @@ public boolean isCalculated() {
throw new UnsupportedOperationException();
}

public boolean isEvaluated() {
throw new UnsupportedOperationException();
}

public int getSolveOrder() {
throw new UnsupportedOperationException();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/mondrian/rolap/RolapEvaluator.java
Expand Up @@ -171,7 +171,7 @@ public RolapEvaluator(RolapEvaluatorRoot root) {
}

currentMembers[ordinal] = member;
if (member.isCalculated()) {
if (member.isEvaluated()) {
addCalcMember(member);
}
}
Expand Down Expand Up @@ -368,11 +368,11 @@ public final Member setContext(Member member) {
if (m.equals(previous)) {
return m;
}
if (previous.isCalculated()) {
if (previous.isEvaluated()) {
removeCalcMember(previous);
}
currentMembers[ordinal] = m;
if (m.isCalculated()) {
if (m.isEvaluated()) {
addCalcMember(m);
}
return previous;
Expand Down Expand Up @@ -738,7 +738,7 @@ public final Object getParameterValue(ParameterSlot slot) {

final void addCalcMember(Member member) {
assert member != null;
assert member.isCalculated();
assert member.isEvaluated();
calcMembers[calcMemberCount++] = member;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/mondrian/rolap/RolapHierarchy.java
Expand Up @@ -921,6 +921,10 @@ protected boolean computeCalculated(final MemberType memberType) {
}

public boolean isCalculated() {
return false;
}

public boolean isEvaluated() {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/rolap/SubstitutingMemberReader.java
Expand Up @@ -177,7 +177,7 @@ public void getMemberChildren(
MemberChildrenConstraint constraint)
{
memberReader.getMemberChildren(
substitute(parentMembers),
desubstitute(parentMembers),
new SubstitutingMemberList(children),
constraint);
}
Expand Down
4 changes: 4 additions & 0 deletions testsrc/main/mondrian/olap/fun/MemberHelperTest.java
Expand Up @@ -165,6 +165,10 @@ public boolean isCalculated() {
return false;
}

public boolean isEvaluated() {
return false;
}

public boolean isCalculatedInQuery() {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions testsrc/main/mondrian/olap/fun/TestMember.java
Expand Up @@ -78,6 +78,11 @@ public boolean isChildOrEqualTo(Member member) {
public boolean isCalculated() {
throw new UnsupportedOperationException();
}

public boolean isEvaluated() {
throw new UnsupportedOperationException();
}

public int getSolveOrder() {
throw new UnsupportedOperationException();
}
Expand Down
102 changes: 99 additions & 3 deletions testsrc/main/mondrian/test/AccessControlTest.java
Expand Up @@ -1201,9 +1201,12 @@ public void testBug2028231() {
"{[Store Size in SQFT].[All Store Size in SQFTs], [Product].[All Products]}\n" +
"{[Store Size in SQFT].[All Store Size in SQFTs].[20319], [Product].[All Products]}\n" +
"Axis #2:\n" +
"{[Store Type].[All Store Types]}\n" +
"{[Store Type].[All Store Types].[Supermarket]}\n" +
"Row #0: 4,042.96\n" +
"Row #0: 4,042.96\n"));
"Row #0: 4,042.96\n" +
"Row #1: 4,042.96\n" +
"Row #1: 4,042.96\n"));

// explicit tuples, not crossjoin
testContext.assertQueryReturns(
Expand All @@ -1222,11 +1225,16 @@ public void testBug2028231() {
"{[Store Size in SQFT].[All Store Size in SQFTs].[20319], [Product].[All Products]}\n" +
"{[Store Size in SQFT].[All Store Size in SQFTs].[20319], [Product].[All Products].[Food]}\n" +
"Axis #2:\n" +
"{[Store Type].[All Store Types]}\n" +
"{[Store Type].[All Store Types].[Supermarket]}\n" +
"Row #0: 4,042.96\n" +
"Row #0: 82.454\n" +
"Row #0: 4,042.96\n" +
"Row #0: 2,696.758\n"));
"Row #0: 2,696.758\n" +
"Row #1: 4,042.96\n" +
"Row #1: 82.454\n" +
"Row #1: 4,042.96\n" +
"Row #1: 2,696.758\n"));

// extended testcase; note that [Store Size in SQFT].Parent is null,
// so disappears
Expand All @@ -1251,11 +1259,16 @@ public void testBug2028231() {
"{[Store Size in SQFT].[All Store Size in SQFTs].[20319], [Product].[All Products]}\n" +
"{[Store Size in SQFT].[All Store Size in SQFTs].[20319], [Product].[All Products].[Food]}\n" +
"Axis #2:\n" +
"{[Store Type].[All Store Types]}\n" +
"{[Store Type].[All Store Types].[Supermarket]}\n" +
"Row #0: 4,042.96\n" +
"Row #0: 4,042.96\n" +
"Row #0: 4,042.96\n" +
"Row #0: 2,696.758\n"));
"Row #0: 2,696.758\n" +
"Row #1: 4,042.96\n" +
"Row #1: 4,042.96\n" +
"Row #1: 4,042.96\n" +
"Row #1: 2,696.758\n"));

testContext.assertQueryReturns(
"select Hierarchize(\n" +
Expand All @@ -1272,13 +1285,37 @@ public void testBug2028231() {
fold("Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Product].[All Products], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"{[Product].[All Products], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"{[Product].[All Products].[Drink].[Dairy], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products].[Drink].[Dairy], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"{[Product].[All Products].[Drink].[Dairy], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products].[Drink].[Dairy], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"{[Product].[All Products].[Food], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products].[Food], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"{[Product].[All Products].[Food], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products].[Food], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"{[Product].[All Products].[Food].[Eggs], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products].[Food].[Eggs], [Store Type].[All Store Types], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"{[Product].[All Products].[Food].[Eggs], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"{[Product].[All Products].[Food].[Eggs], [Store Type].[All Store Types].[Supermarket], [Store Size in SQFT].[All Store Size in SQFTs].[20319]}\n" +
"Row #0: 4,042.96\n" +
"Row #0: 4,042.96\n" +
"Row #0: 4,042.96\n" +
"Row #0: 4,042.96\n" +
"Row #0: 82.454\n" +
"Row #0: 82.454\n" +
"Row #0: 82.454\n" +
"Row #0: 82.454\n" +
"Row #0: 2,696.758\n" +
"Row #0: 2,696.758\n" +
"Row #0: 2,696.758\n" +
"Row #0: 2,696.758\n" +
"Row #0: \n" +
"Row #0: \n" +
"Row #0: \n" +
"Row #0: \n"));
}

Expand Down Expand Up @@ -1399,6 +1436,65 @@ public void testVirtualCube() {
"Row #0: 4,441.18\n" +
"Row #0: 4,441.18\n"));
}

/**
* this tests the fix for
* http://jira.pentaho.com/browse/BISERVER-2491
* rollupPolicy=partial and queries to upper members don't work
*/
public void testBugBiserver2491() {
final String BiServer2491Role2 =
"<Role name=\"role2\">"
+ " <SchemaGrant access=\"none\">"
+ " <CubeGrant cube=\"Sales\" access=\"all\">"
+ " <HierarchyGrant hierarchy=\"[Store]\" access=\"custom\" rollupPolicy=\"partial\">"
+ " <MemberGrant member=\"[Store].[USA].[CA]\" access=\"all\"/>"
+ " <MemberGrant member=\"[Store].[USA].[CA].[Los Angeles]\" access=\"none\"/>"
+ " </HierarchyGrant>"
+ " </CubeGrant>"
+ " </SchemaGrant>"
+ "</Role>";

final TestContext testContext =
TestContext.create(
null, null, null, null, null, BiServer2491Role2)
.withRole("role2");

final String firstBrokenMdx =
"select [Measures].[Unit Sales] ON COLUMNS, {[Store].[Store Country].Members} ON ROWS from [Sales]";

checkQuery(testContext, firstBrokenMdx);
testContext.assertQueryReturns(
firstBrokenMdx,
fold(
"Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Unit Sales]}\n" +
"Axis #2:\n" +
"{[Store].[All Stores].[USA]}\n" +
"Row #0: 49,085\n"));

final String secondBrokenMdx =
"select [Measures].[Unit Sales] ON COLUMNS, Descendants([Store],[Store].[Store Name]) ON ROWS from [Sales]";
checkQuery(testContext, secondBrokenMdx);
testContext.assertQueryReturns(
secondBrokenMdx,
fold(
"Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Unit Sales]}\n" +
"Axis #2:\n" +
"{[Store].[All Stores].[USA].[CA].[Alameda].[HQ]}\n" +
"{[Store].[All Stores].[USA].[CA].[Beverly Hills].[Store 6]}\n" +
"{[Store].[All Stores].[USA].[CA].[San Diego].[Store 24]}\n" +
"{[Store].[All Stores].[USA].[CA].[San Francisco].[Store 14]}\n" +
"Row #0: \n" +
"Row #1: 21,333\n" +
"Row #2: 25,635\n" +
"Row #3: 2,117\n"));
}
}

// End AccessControlTest.java

0 comments on commit 77bd7b0

Please sign in to comment.