Skip to content

Commit

Permalink
MONDRIAN: Fix XMLA tests on MySQL. It's about how empty values are ha…
Browse files Browse the repository at this point in the history
…ndled,

    differences in how the dialects represent booleans, and another test
    assumes that log4j logging is enabled. Add a test for empty value handling.

[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13405]
  • Loading branch information
julianhyde committed Feb 22, 2010
1 parent 63e2c82 commit ee1c9ca
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 14 deletions.
10 changes: 3 additions & 7 deletions src/main/mondrian/olap/fun/FunUtil.java
Expand Up @@ -1460,10 +1460,6 @@ public static int count(
} else {
evaluator.setContext((Member[]) object);
}
Object o = evaluator.evaluateCurrent();
if (o == Util.nullValue) {
continue;
}
if (!evaluator.currentIsEmpty()) {
retval++;
}
Expand All @@ -1485,9 +1481,9 @@ static SetWrapper evaluateSet(
Iterable members,
Calc calc)
{
Util.assertPrecondition(members != null, "members != null");
Util.assertPrecondition(calc != null, "calc != null");
Util.assertPrecondition(calc.getType() instanceof ScalarType);
assert members != null;
assert calc != null;
assert calc.getType() instanceof ScalarType;

// todo: treat constant exps as evaluateMembers() does
SetWrapper retval = new SetWrapper();
Expand Down
12 changes: 9 additions & 3 deletions src/main/mondrian/rolap/RolapEvaluator.java
Expand Up @@ -215,11 +215,17 @@ public boolean nativeEnabled() {
}

public boolean currentIsEmpty() {
// If a cell evaluates to null, it is always deemed empty.
Object o = evaluateCurrent();
if (o == Util.nullValue || o == null) {
return true;
}
// For other cell values (e.g. zero), the cell is deemed empty if the
// number of fact table rows is zero.
final RolapEvaluator eval2 = push(getCube().getFactCountMeasure());
final Object o = eval2.evaluateCurrent();
o = eval2.evaluateCurrent();
return o == null
|| (o instanceof Number
&& ((Number) o).intValue() == 0);
|| (o instanceof Number && ((Number) o).intValue() == 0);
}

public void setNativeEnabled(final Boolean nativeEnabled) {
Expand Down
59 changes: 59 additions & 0 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java
Expand Up @@ -3007,6 +3007,65 @@ public void testCountExcludeEmpty() {
assertExprReturns("count({[Gender].Parent}, ExcludeEmpty)", "0");
}

/**
* Tests that the 'null' value is regarded as empty, even if the underlying
* cell has fact table rows.
*
* <p>For a fuller test case, see
* {@link mondrian.xmla.XmlaCognosTest#testCognosMDXSuiteConvertedAdventureWorksToFoodMart_015()}
*/
public void testCountExcludeEmptyNull() {
assertQueryReturns(
"WITH MEMBER [Measures].[Foo] AS\n"
+ " Iif([Time].CurrentMember.Name = 'Q2', 1, NULL)\n"
+ " MEMBER [Measures].[Bar] AS\n"
+ " Iif([Time].CurrentMember.Name = 'Q2', 1, 0)\n"
+ " MEMBER [Time].[CountExc] AS\n"
+ " Count([Time].[1997].Children, EXCLUDEEMPTY),\n"
+ " SOLVE_ORDER = 2\n"
+ " MEMBER [Time].[CountInc] AS\n"
+ " Count([Time].[1997].Children, INCLUDEEMPTY),\n"
+ " SOLVE_ORDER = 2\n"
+ "SELECT {[Measures].[Foo],\n"
+ " [Measures].[Bar],\n"
+ " [Measures].[Unit Sales]} ON 0,\n"
+ " {[Time].[1997].Children,\n"
+ " [Time].[CountExc],\n"
+ " [Time].[CountInc]} ON 1\n"
+ "FROM [Sales]",
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Measures].[Foo]}\n"
+ "{[Measures].[Bar]}\n"
+ "{[Measures].[Unit Sales]}\n"
+ "Axis #2:\n"
+ "{[Time].[1997].[Q1]}\n"
+ "{[Time].[1997].[Q2]}\n"
+ "{[Time].[1997].[Q3]}\n"
+ "{[Time].[1997].[Q4]}\n"
+ "{[Time].[CountExc]}\n"
+ "{[Time].[CountInc]}\n"
+ "Row #0: \n"
+ "Row #0: 0\n"
+ "Row #0: 66,291\n"
+ "Row #1: 1\n"
+ "Row #1: 1\n"
+ "Row #1: 62,610\n"
+ "Row #2: \n"
+ "Row #2: 0\n"
+ "Row #2: 65,848\n"
+ "Row #3: \n"
+ "Row #3: 0\n"
+ "Row #3: 72,024\n"
+ "Row #4: 1\n"
+ "Row #4: 4\n"
+ "Row #4: 4\n"
+ "Row #5: 4\n"
+ "Row #5: 4\n"
+ "Row #5: 4\n");
}

//todo: testCountNull, testCountNoExp

public void testCovariance() {
Expand Down
20 changes: 16 additions & 4 deletions testsrc/main/mondrian/rolap/NonEmptyTest.java
Expand Up @@ -14,6 +14,7 @@

import junit.framework.Assert;
import mondrian.olap.*;
import mondrian.olap.Level;
import mondrian.rolap.RolapConnection.NonEmptyResult;
import mondrian.rolap.RolapNative.Listener;
import mondrian.rolap.RolapNative.NativeEvent;
Expand All @@ -26,9 +27,7 @@
import mondrian.util.Bug;
import mondrian.spi.Dialect;

import org.apache.log4j.Appender;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Logger;
import org.apache.log4j.*;
import org.apache.log4j.spi.LoggingEvent;
import org.eigenbase.util.property.BooleanProperty;
import org.eigenbase.util.property.StringProperty;
Expand Down Expand Up @@ -2339,6 +2338,16 @@ public boolean requiresLayout() {
}
};
Logger rolapUtilLogger = Logger.getLogger(RolapUtil.class);
final org.apache.log4j.Level prevLevel = rolapUtilLogger.getLevel();
final boolean needToResetLevel;
if (prevLevel == null
|| !prevLevel.isGreaterOrEqual(org.apache.log4j.Level.WARN))
{
rolapUtilLogger.setLevel(org.apache.log4j.Level.WARN);
needToResetLevel = true;
} else {
needToResetLevel = false;
}
rolapUtilLogger.addAppender(alertListener);
String expectedMessage =
"Unable to use native SQL evaluation for 'NonEmptyCrossJoin'";
Expand Down Expand Up @@ -2398,6 +2407,10 @@ public boolean requiresLayout() {
// no biggie if we don't get here for some reason; just being
// half-heartedly clean
rolapUtilLogger.removeAppender(alertListener);

if (needToResetLevel) {
rolapUtilLogger.setLevel(prevLevel);
}
}

private int countFilteredEvents(
Expand Down Expand Up @@ -4089,4 +4102,3 @@ RolapEvaluator getEvaluator(Result res, int[] pos) {
}

// End NonEmptyTest.java

2 changes: 2 additions & 0 deletions testsrc/main/mondrian/xmla/XmlaBaseTestCase.java
Expand Up @@ -291,6 +291,8 @@ protected String fileToString(String filename) throws Exception {
if (s.startsWith("$")) {
getDiffRepos().amend(var, "\n\n");
}
// Give derived class a chance to change the content.
s = filter(getDiffRepos().getCurrentTestCaseName(true), filename, s);
return s;
}

Expand Down
26 changes: 26 additions & 0 deletions testsrc/main/mondrian/xmla/XmlaExcel2007Test.java
Expand Up @@ -9,7 +9,10 @@
*/
package mondrian.xmla;

import mondrian.olap.Util;
import mondrian.spi.Dialect;
import mondrian.test.DiffRepository;
import mondrian.test.TestContext;

/**
* Test suite for compatibility of Mondrian XMLA with Excel 2007.
Expand Down Expand Up @@ -44,6 +47,29 @@ protected DiffRepository getDiffRepos() {
return DiffRepository.lookup(XmlaExcel2007Test.class);
}

protected String filter(
String testCaseName,
String filename,
String content)
{
if (testCaseName.startsWith("testMemberPropertiesAndSlicer")
&& filename.equals("response"))
{
Dialect dialect = TestContext.instance().getDialect();
switch (dialect.getDatabaseProduct()) {
case MYSQL:
final String start = "<Has_x0020_coffee_x0020_bar>";
final String end = "</Has_x0020_coffee_x0020_bar>";
content = Util.replace(
content, start + "1" + end, start + "true" + end);
content = Util.replace(
content, start + "0" + end, start + "false" + end);
break;
}
}
return content;
}

/**
* <p>Testcase for <a href="http://jira.pentaho.com/browse/MONDRIAN-679">
* bug MONDRIAN-679, "VisualTotals gives ClassCastException when called via
Expand Down

0 comments on commit ee1c9ca

Please sign in to comment.