Skip to content

Commit

Permalink
MONDRIAN-642 - Enhance hideMemberIf="IfBlankName" to consider whitesp…
Browse files Browse the repository at this point in the history
…ace as blank

[git-p4: depot-paths = "//open/mondrian/": change = 13163]
  • Loading branch information
Matt Campbell authored and Matt Campbell committed Nov 16, 2009
1 parent d5548ee commit b8fcead
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/mondrian/olap/Mondrian.xml
Expand Up @@ -636,7 +636,7 @@ Revision is $Id$
<p>Allowable values are:
<code>Never</code> (a member always appears; the default);
<code>IfBlankName</code> (a member doesn't appear if its name
is null or empty); and
is null, empty or all whitespace); and
<code>IfParentsName</code> (a member appears unless its name
matches the parent's.</p>
</Doc>
Expand Down
29 changes: 29 additions & 0 deletions src/main/mondrian/olap/Util.java
Expand Up @@ -2574,6 +2574,35 @@ public static void checkCJResultLimit(long resultSize) {
resultSize, Integer.MAX_VALUE);
}
}

/**
* <p>Copied from commons-lang
* Checks if a String is whitespace, empty ("") or null.</p>
*
* <pre>
* StringUtils.isBlank(null) = true
* StringUtils.isBlank("") = true
* StringUtils.isBlank(" ") = true
* StringUtils.isBlank("bob") = false
* StringUtils.isBlank(" bob ") = false
* </pre>
*
* @param str the String to check, may be null
* @return <code>true</code> if the String is null, empty or whitespace
* @since 2.0
*/
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(str.charAt(i)) == false)) {
return false;
}
}
return true;
}
}

// End Util.java
3 changes: 2 additions & 1 deletion src/main/mondrian/rolap/RolapMember.java
Expand Up @@ -782,7 +782,8 @@ public boolean isHidden() {
// If the key value in the database is null, then we use
// a special key value whose toString() is "null".
final String name = getName();
return name.equals(RolapUtil.mdxNullLiteral()) || name.equals("");
return name.equals(RolapUtil.mdxNullLiteral())
|| Util.isBlank(name);
}

case IfParentsName:
Expand Down
35 changes: 35 additions & 0 deletions testsrc/main/mondrian/test/RaggedHierarchyTest.java
Expand Up @@ -9,6 +9,8 @@
*/
package mondrian.test;

import mondrian.spi.Dialect;

/**
* <code>RaggedHierarchyTest</code> tests ragged hierarchies.
* <p>
Expand Down Expand Up @@ -318,6 +320,39 @@ public void dont_testMeasures() {
+ "Row #30: 35,257\n"
+ "Row #31: 35,257\n");
}

public void testHideIfBlankHidesWhitespace() {
if (TestContext.instance().getDialect().getDatabaseProduct()
== Dialect.DatabaseProduct.ORACLE)
{
TestContext testContext = TestContext.createSubstitutingCube(
"Sales",
"<Dimension name=\"Gender4\" foreignKey=\"customer_id\">\n"
+ " <Hierarchy hasAll=\"true\" allMemberName=\"All Gender\" primaryKey=\"customer_id\">\n"
+ " <Table name=\"customer\"/>\n"
+ " <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\" hideMemberIf=\"IfBlankName\">\n"
+ " <NameExpression> "
+ " <SQL dialect='generic'> "
+ "case \"gender\" "
+ "when 'F' then ' ' "
+ "when 'M' then 'M' "
+ " end "
+ "</SQL> "
+ "</NameExpression> "
+ " </Level>"
+ " </Hierarchy>\n"
+ " </Dimension>");
testContext.assertQueryReturns(
" select {[Gender4].[Gender].members} "
+ "on COLUMNS "
+ "from sales",
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Gender4].[All Gender].[M]}\n"
+ "Row #0: 135,215\n");
}
}
}

// End RaggedHierarchyTest.java

0 comments on commit b8fcead

Please sign in to comment.