Skip to content

Commit

Permalink
MONDRIAN: Fix bug which occurred when a calculated member was defined…
Browse files Browse the repository at this point in the history
… against a cube which has spaces in its name; and add testcase.

[git-p4: depot-paths = "//open/mondrian/": change = 2998]
  • Loading branch information
julianhyde committed Dec 23, 2004
1 parent 4cd4a88 commit 56637d3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/main/mondrian/rolap/RolapCube.java
Expand Up @@ -122,16 +122,19 @@ class RolapCube extends CubeBase
private Formula parseFormula(String formulaString,
String memberUniqueName, ArrayList propNames, ArrayList propExprs)
{
assert memberUniqueName.startsWith("[");
RolapConnection conn = schema.getInternalConnection();
StringBuffer buf = new StringBuffer(
"WITH MEMBER " + memberUniqueName + " AS " + formulaString);
StringBuffer buf = new StringBuffer(256);
buf.append("WITH MEMBER ").append(memberUniqueName).append(" AS ")
.append(formulaString);
assert propNames.size() == propExprs.size();
for (int i = 0; i < propNames.size(); i++) {
String name = (String) propNames.get(i);
String expr = (String) propExprs.get(i);
buf.append(", ").append(name).append(" = ").append(expr);
}
buf.append(" SELECT FROM " + getUniqueName());
buf.append(" SELECT FROM ")
.append(Util.quoteMdxIdentifier(getUniqueName()));
final String queryString = buf.toString();
final Query queryExp;
try {
Expand Down
6 changes: 2 additions & 4 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java
Expand Up @@ -231,12 +231,10 @@ public void testAncestorWithHiddenParent() throws Exception {
}

public void testOrdinal() throws Exception {
Cell cell = executeExprRaw("[Sales Ragged]", "[Store].[All Stores].[Vatican].ordinal");

Cell cell = executeExprRaw("Sales Ragged", "[Store].[All Stores].[Vatican].ordinal");
assertEquals("Vatican is at level 1.", 1, ((Number)cell.getValue()).intValue());

cell = executeExprRaw("[Sales Ragged]", "[Store].[All Stores].[USA].[Washington].ordinal");

cell = executeExprRaw("Sales Ragged", "[Store].[All Stores].[USA].[Washington].ordinal");
assertEquals("Washington is at level 3.", 3, ((Number) cell.getValue()).intValue());
}

Expand Down
10 changes: 7 additions & 3 deletions testsrc/main/mondrian/test/FoodMartTestCase.java
Expand Up @@ -263,9 +263,13 @@ public String executeExpr(String expression) {
* @return Returns a {@link Cell} which is the result of the expression.
*/
public Cell executeExprRaw(String cubeName, String expression) {
Result result = TestContext.instance().executeFoodMart("with member [Measures].[Foo] as '" +
expression +
"' select {[Measures].[Foo]} on columns from " + cubeName);
if (cubeName.indexOf(' ') >= 0) {
cubeName = Util.quoteMdxIdentifier(cubeName);
}
final String queryString = "with member [Measures].[Foo] as '" +
expression +
"' select {[Measures].[Foo]} on columns from " + cubeName;
Result result = TestContext.instance().executeFoodMart(queryString);

return result.getCell(new int[]{0});
}
Expand Down
16 changes: 15 additions & 1 deletion testsrc/main/mondrian/test/TestCalculatedMembers.java
Expand Up @@ -59,6 +59,21 @@ public void testCalculatedMemberInCubeViaApi() {
}
}

/**
* Tests a calculated member with spaces in its name against a virtual
* cube with spaces in its name.
*/
public void testCalculatedMemberInCubeWithSpace() {
Cube salesCube = getSalesCube("Warehouse and Sales");
salesCube.createCalculatedMember(
"<CalculatedMember name='Profit With Spaces'" +
" dimension='Measures'" +
" formula='[Measures].[Store Sales]-[Measures].[Store Cost]'/>");

String s = executeExpr("Warehouse and Sales", "[Measures].[Profit With Spaces]");
Assert.assertEquals("339,610.90", s);
}

public void testCalculatedMemberInCubeWithProps() {
Cube salesCube = getSalesCube("Sales");

Expand Down Expand Up @@ -108,7 +123,6 @@ public void testCalculatedMemberInCubeWithProps() {
}
}


// should fail if member property's expression is invalid
try {
salesCube.createCalculatedMember(
Expand Down

0 comments on commit 56637d3

Please sign in to comment.