Skip to content

Commit

Permalink
if a hierarchy is kept consistent in the query model only make necess…
Browse files Browse the repository at this point in the history
…ary checks. no need to check if ancestor of current member is in ancestor_level.members, fix formatting

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@469 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
pstoellberger committed Aug 2, 2011
1 parent f89c6fe commit 3583e9f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/org/olap4j/query/Olap4jNodeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,45 +607,45 @@ 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,
"Ancestor",
Syntax.Function,
currentMemberNode,
new LevelNode(null, currentLevel));
CallNode currentMemberNode =
new CallNode(
null,
"CurrentMember",
Syntax.Property,
new HierarchyNode(
null,
currentLevel.getHierarchy()));

CallNode ancestorNode =
new CallNode(
null,
"Ancestor",
Syntax.Function,
currentMemberNode,
new LevelNode(null, currentLevel));

List <ParseTreeNode> ancestorList =
new ArrayList<ParseTreeNode>();
List <ParseTreeNode> ancestorList =
new ArrayList<ParseTreeNode>();

for (Selection anc : qDim.getInclusions()) {
if (anc.getRootElement() instanceof Member) {
Level l = ((Member)anc.getRootElement()).getLevel();
if (l.equals(levels.get(levelDepths[i]))) {
ancestorList.add(anc.visit());
}
} else if (anc.getRootElement() instanceof Level) {
Level l = ((Level)anc.getRootElement());
if (l.equals(levels.get(levelDepths[i]))) {
ancestorList.add(anc.visit());
for (Selection anc : qDim.getInclusions()) {
if (anc.getRootElement() instanceof Member) {
Level l = ((Member)anc.getRootElement()).getLevel();
if (l.equals(levels.get(levelDepths[i]))) {
ancestorList.add(anc.visit());
}
}
}
}
CallNode ancestorSet = generateListSetCall(ancestorList);
CallNode inClause = new CallNode(
null,
"IN",
Syntax.Infix,
ancestorNode,
ancestorSet);
inConditions.add(inClause);
if (ancestorList.size() > 0) {
CallNode ancestorSet =
generateListSetCall(ancestorList);
CallNode inClause = new CallNode(
null,
"IN",
Syntax.Infix,
ancestorNode,
ancestorSet);
inConditions.add(inClause);
}
}
}
if (inConditions.size() > 0) {
Expand Down
22 changes: 22 additions & 0 deletions testsrc/org/olap4j/OlapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,28 @@ public void testHierarchyConsistency() {
+ "Row #1: 5,552\n"
+ "Row #2: 5,944\n",
resultsString2);

QueryDimension customerDimension = query.getDimension("Customers");
customerDimension.setHierarchyConsistent(true);
NamedList<Level> customerLevels =
customerDimension.getDimension()
.getDefaultHierarchy().getLevels();

Level country = customerLevels.get("Country");
Level state = customerLevels.get("State Province");
customerDimension.include(country);
customerDimension.include(state);

query.getAxis(Axis.ROWS).removeDimension(timeDimension);
query.getAxis(Axis.ROWS).addDimension(customerDimension);

String mdxString3 = query.getSelect().toString();
TestContext.assertEqualsVerbose(
"SELECT\n"
+ "{[Product].[Food]} ON COLUMNS,\n"
+ "Hierarchize(Union(CrossJoin({[Measures].[Sales Count]}, [Customers].[Country].Members), CrossJoin({[Measures].[Sales Count]}, [Customers].[State Province].Members))) ON ROWS\n"
+ "FROM [Sales]",
mdxString3);
} catch (Exception e) {
e.printStackTrace();
fail();
Expand Down

0 comments on commit 3583e9f

Please sign in to comment.