From 3583e9f5bec1105d1c134fb90af0246fc692165f Mon Sep 17 00:00:00 2001 From: Paul Stoellberger Date: Tue, 2 Aug 2011 17:11:04 +0000 Subject: [PATCH] if a hierarchy is kept consistent in the query model only make necessary 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 --- src/org/olap4j/query/Olap4jNodeConverter.java | 70 +++++++++---------- testsrc/org/olap4j/OlapTest.java | 22 ++++++ 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/org/olap4j/query/Olap4jNodeConverter.java b/src/org/olap4j/query/Olap4jNodeConverter.java index cce1909..2e9ce00 100644 --- a/src/org/olap4j/query/Olap4jNodeConverter.java +++ b/src/org/olap4j/query/Olap4jNodeConverter.java @@ -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 ancestorList = - new ArrayList(); + List ancestorList = + new ArrayList(); - 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) { diff --git a/testsrc/org/olap4j/OlapTest.java b/testsrc/org/olap4j/OlapTest.java index dee98ca..365ea24 100644 --- a/testsrc/org/olap4j/OlapTest.java +++ b/testsrc/org/olap4j/OlapTest.java @@ -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 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();