Skip to content

Commit

Permalink
make sure hierarchyConsistent uses the right hierarchy for .CurrentMe…
Browse files Browse the repository at this point in the history
…mber, added test case for that

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@460 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
pstoellberger committed Jul 6, 2011
1 parent 33d32f7 commit 0eb19d9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/org/olap4j/query/Olap4jNodeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.olap4j.mdx.CallNode;
import org.olap4j.mdx.CubeNode;
import org.olap4j.mdx.DimensionNode;
import org.olap4j.mdx.HierarchyNode;
import org.olap4j.mdx.IdentifierNode;
import org.olap4j.mdx.LevelNode;
import org.olap4j.mdx.LiteralNode;
Expand Down Expand Up @@ -578,13 +579,6 @@ private static ParseTreeNode toHierarchyConsistentNode(
// consistent results, generate a filter that checks
// inclusions for ancestors in higher levels
if (qDim.getInclusions().size() > 1) {
CallNode currentMemberNode =
new CallNode(
null,
"CurrentMember",
Syntax.Property,
new DimensionNode(null, qDim.getDimension()));

Map<Integer, Level> levels = new HashMap<Integer, Level>();
for (Selection s : qDim.getInclusions()) {
if (s.getRootElement() instanceof Member) {
Expand Down Expand Up @@ -613,6 +607,13 @@ private static ParseTreeNode toHierarchyConsistentNode(
if (levelDepths[i] < maxDepth
&& currentLevel.getLevelType() != Level.Type.ALL)
{
CallNode currentMemberNode =
new CallNode(
null,
"CurrentMember",
Syntax.Property,
new HierarchyNode(null, currentLevel.getHierarchy()));

CallNode ancestorNode =
new CallNode(
null,
Expand Down
54 changes: 54 additions & 0 deletions testsrc/org/olap4j/OlapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,60 @@ public void testCompoundFilter() {
fail();
}
}
public void testMultipleHierarchyConsistency() {
try {
Cube cube = getFoodmartCube("Sales");
if (cube == null) {
fail("Could not find Sales cube");
}
// Setup a base query.
Query query = new Query("my query", cube);
QueryDimension timeDimension = query.getDimension("Time");
timeDimension.setHierarchyConsistent(true);

timeDimension.include(nameList("Time.Weekly", "1997", "10", "23"));
timeDimension.include(nameList("Time.Weekly", "1997", "10", "28"));
timeDimension.include(nameList("Time.Weekly", "Year", "1997"));

QueryDimension measuresDimension = query.getDimension("Measures");
measuresDimension.include(nameList("Measures", "Sales Count"));

query.getAxis(Axis.COLUMNS).addDimension(measuresDimension);
query.getAxis(Axis.ROWS).addDimension(timeDimension);

query.validate();

// Validate the generated MDX
String mdxString = query.getSelect().toString();
TestContext.assertEqualsVerbose(
"SELECT\n"
+ "{[Measures].[Sales Count]} ON COLUMNS,\n"
+ "{{[Time.Weekly].[1997]}, Filter({{[Time.Weekly].[1997].[10].[23], [Time.Weekly].[1997].[10].[28]}}, (Ancestor([Time.Weekly].CurrentMember, [Time.Weekly].[Year]) IN {[Time.Weekly].[1997]}))} ON ROWS\n"
+ "FROM [Sales]",
mdxString);

// Validate the returned results
CellSet results = query.execute();
String resultsString = TestContext.toString(results);
TestContext.assertEqualsVerbose(
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Measures].[Sales Count]}\n"
+ "Axis #2:\n"
+ "{[Time.Weekly].[1997]}\n"
+ "{[Time.Weekly].[1997].[10].[23]}\n"
+ "{[Time.Weekly].[1997].[10].[28]}\n"
+ "Row #0: 86,837\n"
+ "Row #1: 123\n"
+ "Row #2: \n",
resultsString);
query.validate();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
public void testHierarchyConsistency() {
try {
Cube cube = getFoodmartCube("Sales");
Expand Down

0 comments on commit 0eb19d9

Please sign in to comment.