Skip to content

Commit

Permalink
Merge pull request pentaho#323 from mkambol/mondrian-1519
Browse files Browse the repository at this point in the history
[MONDRIAN-1519]  Median from set of one member is returned as 50% from m...
  • Loading branch information
lucboudreau committed May 23, 2014
2 parents 0951f8e + c3956f2 commit 365debd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main/mondrian/olap/fun/FunUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// You must accept the terms of that agreement to use this software.
//
// Copyright (C) 2002-2005 Julian Hyde
// Copyright (C) 2005-2013 Pentaho and others
// Copyright (C) 2005-2014 Pentaho and others
// All Rights Reserved.
*/

package mondrian.olap.fun;

import mondrian.calc.*;
Expand Down Expand Up @@ -1229,7 +1228,7 @@ static double percentile(
} else if (p >= 1.0) {
return asArray[length - 1];
} else if (length == 1) {
return asArray[0] * p;
return asArray[0];
} else if (p == 0.5) {
// Special case for median.
if ((length & 1) == 1) {
Expand Down
13 changes: 8 additions & 5 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// You must accept the terms of that agreement to use this software.
//
// Copyright (C) 2003-2005 Julian Hyde
// Copyright (C) 2005-2013 Pentaho and others
// Copyright (C) 2005-2014 Pentaho and others
// All Rights Reserved.
*/

package mondrian.olap.fun;

import mondrian.olap.*;
Expand Down Expand Up @@ -3298,6 +3297,10 @@ public void testMedian() {
"MEDIAN({[Store].[All Stores].[USA].children},"
+ "[Measures].[Store Sales])",
"159,167.84");
// single value
assertExprReturns(
"MEDIAN({[Store].[All Stores].[USA]}, [Measures].[Store Sales])",
"565,238.13");
}

public void testMedian2() {
Expand Down Expand Up @@ -3409,13 +3412,13 @@ public void testPercentile() {
public void testPercentileBugMondrian1045() {
assertExprReturns(
"Percentile({[Store].[All Stores].[USA]}, [Measures].[Store Sales], 50)",
"282,619.07");
"565,238.13");
assertExprReturns(
"Percentile({[Store].[All Stores].[USA]}, [Measures].[Store Sales], 40)",
"226,095.25");
"565,238.13");
assertExprReturns(
"Percentile({[Store].[All Stores].[USA]}, [Measures].[Store Sales], 95)",
"536,976.22");
"565,238.13");
}

public void testMin() {
Expand Down

0 comments on commit 365debd

Please sign in to comment.