Skip to content

Commit

Permalink
MONDRIAN: Solve problem with equal values in hierarchical sort
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 2210]
  • Loading branch information
hhaas committed Jun 23, 2004
1 parent e5cfd82 commit 04bfb0e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/main/mondrian/olap/fun/FunUtil.java
Expand Up @@ -99,7 +99,7 @@ static int getLiteralArg(Exp[] args, int i, int defaultValue, EnumeratedValues a
return allowedValues.getOrdinal(literal);
}

/**
/**
* returns defaultValue, if the expression can not be evaluated because
* some required operands have not been loaded from the database yet.
*/
Expand All @@ -110,7 +110,7 @@ static boolean getBooleanArg(Evaluator evaluator, Exp[] args, int index, boolean
return ((Boolean) o).booleanValue();
}

/**
/**
* returns null, if the expression can not be evaluated because
* some required operands have not been loaded from the database yet.
*/
Expand Down Expand Up @@ -1018,14 +1018,14 @@ protected int compareHierarchicallyButSiblingsByValue(Member m1, Member m2) {
return 0;
}
while (true) {
int levelDepth1 = m1.getLevel().getDepth(),
levelDepth2 = m2.getLevel().getDepth();
if (levelDepth1 < levelDepth2) {
int depth1 = m1.getDepth(),
depth2 = m2.getDepth();
if (depth1 < depth2) {
m2 = m2.getParentMember();
if (FunUtil.equals(m1, m2)) {
return -1;
}
} else if (levelDepth1 > levelDepth2) {
} else if (depth1 > depth2) {
m1 = m1.getParentMember();
if (FunUtil.equals(m1, m2)) {
return 1;
Expand All @@ -1036,7 +1036,15 @@ protected int compareHierarchicallyButSiblingsByValue(Member m1, Member m2) {
m2 = m2.getParentMember();
if (FunUtil.equals(m1, m2)) {
// including case where both parents are null
return compareByValue(prev1, prev2);
int c = compareByValue(prev1, prev2);
if (c != 0)
return c;
// prev1 and prev2 are siblings.
// Order according to hierarchy, if the values do not differ.
// Needed to have a consistent sort if members with equal (null!)
// values are compared.
c = prev1.compareTo(prev2);
return c; // desc ? -c : c;
}
}
}
Expand Down

0 comments on commit 04bfb0e

Please sign in to comment.