Skip to content

Commit

Permalink
[SP-5208] Backport of MONDRIAN-2663 - CurrentMember function shows an…
Browse files Browse the repository at this point in the history
… error when returning a set or dimension is in a compound slicer (8.3 Suite)
  • Loading branch information
Leonardo Coelho committed Aug 7, 2019
1 parent ee85a0d commit f9f8b46
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 5 deletions.
64 changes: 64 additions & 0 deletions mondrian/src/it/java/mondrian/test/BasicQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9136,6 +9136,34 @@ public void testCurrentMemberWithCompoundSlicer() {
}
}

public void testCurrentMemberWithCompoundSlicerIgnoreException() {
propSaver.set(props.CurrentMemberWithCompoundSlicerAlert, "OFF");

final TestContext context = getTestContext().withFreshConnection();
String mdx = ""
+ "with\n"
+ "member [Measures].[Gender Current Member] "
+ "as '[Gender].CurrentMember.Name'\n"
+ "select [Measures].[Gender Current Member] on 0\n"
+ "from [Sales]\n"
+ "where { [Gender].[M], [Gender].[F] }";

try {
context.assertQueryReturns(
mdx,
"Axis #0:\n"
+ "{[Gender].[M]}\n"
+ "{[Gender].[F]}\n"
+ "Axis #1:\n"
+ "{[Measures].[Gender Current Member]}\n"
+ "Row #0: #null\n");
} catch (MondrianException e) {
fail("MondrianException is not expected");
} finally {
propSaver.reset();
}
}

public void testCurrentMemberWithCompoundSlicer2() {
String mdx =
"with\n"
Expand Down Expand Up @@ -9163,6 +9191,42 @@ public void testCurrentMemberWithCompoundSlicer2() {
}
}

public void testCurrentMemberWithCompoundSlicer2IgnoreException() {
propSaver.set(props.CurrentMemberWithCompoundSlicerAlert, "OFF");

final TestContext context = getTestContext().withFreshConnection();
String mdx =
"with\n"
+ "member [Measures].[Drink Sales Previous Period] as\n"
+ "'( Time.CurrentMember.lag(1), [Product].[All Products].[Drink],"
+ " measures.[unit sales] )'\n"
+ "member [Measures].[Drink Sales Current Period] as\n"
+ "'( Time.CurrentMember, [Product].[All Products].[Drink],"
+ " [Measures].[Unit Sales] )'\n"
+ "select\n"
+ "{ [Measures].[Drink Sales Current Period],"
+ " [Measures].[Drink Sales Current Period] } on 0\n"
+ "from [Sales]\n"
+ "where { [Time].[1997].[Q4],[Time].[1997].[Q3] }\n";

try {
context.assertQueryReturns(
mdx,
"Axis #0:\n"
+ "{[Time].[1997].[Q4]}\n"
+ "{[Time].[1997].[Q3]}\n"
+ "Axis #1:\n"
+ "{[Measures].[Drink Sales Current Period]}\n"
+ "{[Measures].[Drink Sales Current Period]}\n"
+ "Row #0: \n"
+ "Row #0: \n");
} catch (MondrianException e) {
fail("MondrianException is not expected");
} finally {
propSaver.reset();
}
}

public void testMondrian625() {
assertQueriesReturnSimilarResults(
"select\n"
Expand Down
20 changes: 20 additions & 0 deletions mondrian/src/main/java/mondrian/olap/MondrianProperties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,26 @@ not conform to SSAS, but is useful in some applications.</p>
<Type>boolean</Type>
<Default>false</Default>
</PropertyDefinition>
<PropertyDefinition>
<Name>CurrentMemberWithCompoundSlicerAlert</Name>
<Path>mondrian.olap.fun.currentmemberwithcompoundslicer.alert</Path>
<Category>SQL generation</Category>
<Description>
<p>Alerting action to take when a CurrentMember function is applied to
a dimension that is also a compound slicer</p>

<p>Recognized actions:</p>

<ul>
<li><code>OFF</code>: do nothing</li>
<li><code>WARN</code>: log a warning</li>
<li><code>ERROR</code>: throw an CurrentMemberWithCompoundSlicer
MondrianException</li>
</ul>
</Description>
<Type>String</Type>
<Default>ERROR</Default>
</PropertyDefinition>
<PropertyDefinition>
<Name>EnableGroupingSets</Name>
<Path>mondrian.rolap.groupingsets.enable</Path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// http://www.eclipse.org/legal/epl-v10.html.
// You must accept the terms of that agreement to use this software.
//
// Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved.
// Copyright (c) 2002-2019 Hitachi Vantara.. All rights reserved.
*/
package mondrian.olap.fun;

Expand All @@ -15,6 +15,8 @@
import mondrian.resource.MondrianResource;
import mondrian.rolap.RolapEvaluator;
import mondrian.rolap.RolapHierarchy;
import org.apache.log4j.Logger;
import org.eigenbase.util.property.StringProperty;

import java.util.Map;
import java.util.Set;
Expand All @@ -27,6 +29,9 @@
* @since Mar 23, 2006
*/
public class HierarchyCurrentMemberFunDef extends FunDefBase {
private static final Logger LOGGER =
Logger.getLogger(HierarchyCurrentMemberFunDef.class);

static final HierarchyCurrentMemberFunDef instance =
new HierarchyCurrentMemberFunDef();

Expand Down Expand Up @@ -116,12 +121,30 @@ private static void validateSlicerMembers(
if (evaluator instanceof RolapEvaluator) {
RolapEvaluator rev = (RolapEvaluator) evaluator;
Map<Hierarchy, Set<Member>> map =
Util.getMembersToHierarchyMap(rev.getSlicerMembers());
Util.getMembersToHierarchyMap(rev.getSlicerMembers());
Set<Member> members = map.get(hierarchy);

if (members != null && members.size() > 1) {
throw MondrianResource.instance()
.CurrentMemberWithCompoundSlicer.ex(
hierarchy.getUniqueName());
MondrianException exception =
MondrianResource.instance()
.CurrentMemberWithCompoundSlicer.ex(
hierarchy.getUniqueName());
StringProperty alertProperty =
MondrianProperties.instance()
.CurrentMemberWithCompoundSlicerAlert;
String alertValue = alertProperty.get();

if (alertValue.equalsIgnoreCase(
org.apache.log4j.Level.WARN.toString()))
{
LOGGER.warn(exception.getMessage());
} else if (alertValue.equalsIgnoreCase(
org.apache.log4j.Level.ERROR.toString()))
{
throw MondrianResource.instance()
.CurrentMemberWithCompoundSlicer.ex(
hierarchy.getUniqueName());
}
}
}
}
Expand Down

0 comments on commit f9f8b46

Please sign in to comment.