Skip to content

Commit

Permalink
MONDRIAN: don't inherit formatting for non-measure calculated
Browse files Browse the repository at this point in the history
members (matches MSAS behavior in that respect, although
formatting inference for calculated measures is still different)

[git-p4: depot-paths = "//open/mondrian/": change = 8335]
  • Loading branch information
jsichi committed Dec 13, 2006
1 parent 7153942 commit 3a8e511
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/mondrian/olap/Formula.java
Expand Up @@ -323,15 +323,16 @@ public int getSolveOrder() {
*/
private Exp getFormatExp() {
// If they have specified a format string (which they can do under
// several names) reutrn that.
// several names) return that.
for (String prop : Property.FORMAT_PROPERTIES) {
Exp formatExp = getMemberProperty(prop);
if (formatExp != null) {
return formatExp;
}
}

// Choose a format appropriate to the expression.
// For now, only do it for integers.
// For now, only do it for decimals.
final Type type = exp.getType();
if (type instanceof DecimalType) {
int scale = ((DecimalType) type).getScale();
Expand All @@ -345,6 +346,14 @@ private Exp getFormatExp() {
return Literal.createString(formatString);
}

if (!mdxMember.isMeasure()) {
// Don't try to do any format string inference on non-measure
// calculated members; that can hide the correct formatting
// from base measures (see TestCalculatedMembers.testFormatString
// for an example).
return null;
}

// Burrow into the expression. If we find a member, use its format
// string.
try {
Expand Down
44 changes: 44 additions & 0 deletions testsrc/main/mondrian/test/TestCalculatedMembers.java
Expand Up @@ -710,6 +710,50 @@ public void testChildrenOfCalcMembers() {
"{[Product].[All Products].[Food]}\n" +
"{[Product].[All Products].[Non-Consumable]}\n"));
}

public void testFormatString() {
// Verify that
// (a) a calculated member without a format string does not
// override the format string of a base measure
// ([Highly Profitable States] does not override [Store Sales])
// and
// (b) a calculated member with a format string does
// override the format string of a base measure
// ([Plain States] does override [Store Sales])
// and
// (c) the format string for conflicting calculated members
// is chosen according to solve order
// ([Plain States] overrides [Profit])
assertQueryReturns("WITH MEMBER [Customers].[Highly Profitable States]" + nl +
"AS 'SUM(FILTER([Customers].[USA].children,([Measures].[Profit] > 90000)))'" + nl +
"MEMBER [Customers].[Plain States]" + nl +
" AS 'SUM([Customers].[USA].children)', SOLVE_ORDER = 5, FORMAT_STRING='#,###'" + nl +
"SELECT {[Measures].[Store Sales], [Measures].[Profit]} ON COLUMNS," + nl +
"UNION([Customers].[USA].children,{[Customers].[Highly Profitable States],[Customers].[Plain States]}) ON ROWS" + nl +
"FROM [Sales]",
fold(
"Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Store Sales]}\n" +
"{[Measures].[Profit]}\n" +
"Axis #2:\n" +
"{[Customers].[All Customers].[USA].[CA]}\n" +
"{[Customers].[All Customers].[USA].[OR]}\n" +
"{[Customers].[All Customers].[USA].[WA]}\n" +
"{[Customers].[Highly Profitable States]}\n" +
"{[Customers].[Plain States]}\n" +
"Row #0: 159,167.84\n" +
"Row #0: $95,637.41\n" +
"Row #1: 142,277.07\n" +
"Row #1: $85,504.57\n" +
"Row #2: 263,793.22\n" +
"Row #2: $158,468.91\n" +
"Row #3: 422,961.06\n" +
"Row #3: $254,106.33\n" +
"Row #4: 565,238\n" +
"Row #4: 339,611\n"));
}
}

// End CalculatedMembersTestCase.java

0 comments on commit 3a8e511

Please sign in to comment.