Skip to content

Commit

Permalink
MONDRIAN: Enable testcases via a constant in a new 'Bug' class rather…
Browse files Browse the repository at this point in the history
… than via system properties.

[git-p4: depot-paths = "//open/mondrian/": change = 7912]
  • Loading branch information
julianhyde committed Oct 11, 2006
1 parent 0d4f6ab commit 9938523
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 78 deletions.
13 changes: 5 additions & 8 deletions src/main/mondrian/olap/fun/CrossJoinFunDef.java
Expand Up @@ -18,6 +18,7 @@
import mondrian.calc.*;
import mondrian.calc.impl.AbstractListCalc;
import mondrian.mdx.ResolvedFunCall;
import mondrian.util.Bug;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -134,22 +135,18 @@ List crossJoin(List list1, List list2, Evaluator evaluator) {
long size = (long)list1.size() * (long)list2.size();
int resultLimit = MondrianProperties.instance().ResultLimit.get();

// NOTE: RME : These properties are used by the Checkin_7634
final String USE_PROP_NAME = "mondrian.test.7634.use";
final String SIZE_PROP_NAME = "mondrian.test.7634.size";
final String OLD_PROP_NAME = "mondrian.test.7634.old";
final int opSize = Integer.getInteger(SIZE_PROP_NAME, 1000).intValue();
final int opSize = Bug.Checkin7634Size;
//System.out.println("CrossJoinFunDef.crossjoin: size=" +size);
//System.out.println("CrossJoinFunDef.crossjoin: opSize=" +opSize);
boolean useOptimizer = (System.getProperty(USE_PROP_NAME) == null);
boolean doOld = (System.getProperty(OLD_PROP_NAME) != null);
boolean useOptimizer = Bug.Checkin7634UseOptimizer;
boolean doOld = Bug.Checkin7634DoOld;
if (useOptimizer && size > opSize && evaluator.isNonEmpty()) {
// instead of overflow exception try to further
// optimize nonempty(crossjoin(a,b)) ==
// nonempty(crossjoin(nonempty(a),nonempty(b))
final int missCount = evaluator.getMissCount();

//System.out.println("CrossJoinFunDef.crossjoin: oldprop=" +System.getProperty("mondrian.test.7634.old"));
//System.out.println("CrossJoinFunDef.crossjoin: oldprop=" +doOld);
if (doOld) {
list1 = nonEmptyListOld(evaluator, list1);
list2 = nonEmptyListOld(evaluator, list2);
Expand Down
76 changes: 35 additions & 41 deletions src/main/mondrian/rolap/RolapResult.java
Expand Up @@ -18,6 +18,7 @@
import mondrian.olap.fun.MondrianEvaluationException;
import mondrian.resource.MondrianResource;
import mondrian.rolap.agg.AggregationManager;
import mondrian.util.Bug;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -63,7 +64,8 @@ class RolapResult extends ResultBase {
return;
}

// for use in debugging Checkin_7634
// for use in debugging Checkin_7634
Util.discard(Bug.Checkin7634DoOld);
// this.evaluator.printCurrentMemberNames();
try {
// An array of lists which will hold each axis' implicit members (does
Expand Down Expand Up @@ -142,50 +144,42 @@ class RolapResult extends ResultBase {
}
}

// This is part of the junit test Checkin_7641 that
// shows that there is a difference when the default
// member is not the one used in an axis.
// When Checkin 7641 is resolved, then this System property access and
// boolean should go away.
boolean useCheckin7641 =
(System.getProperty("mondrian.test.checkin.7641") == null);

if (useCheckin7641) {
purge(axisMembers, slicerMembers);

boolean didEvaluatorReplacementMember = false;
RolapEvaluator rolapEval = (RolapEvaluator) evaluator;
Iterator it = axisMembers.iterator();
while (it.hasNext()) {
Member m = (Member) it.next();
if (rolapEval.setContextConditional(m) != null) {
// Do not break out of loops but set change flag.
// There may be more than one Member that has to be
// replaced.
didEvaluatorReplacementMember = true;
if (Bug.Checkin7641UseOptimizer) {
purge(axisMembers, slicerMembers);

boolean didEvaluatorReplacementMember = false;
RolapEvaluator rolapEval = (RolapEvaluator) evaluator;
Iterator it = axisMembers.iterator();
while (it.hasNext()) {
Member m = (Member) it.next();
if (rolapEval.setContextConditional(m) != null) {
// Do not break out of loops but set change flag.
// There may be more than one Member that has to be
// replaced.
didEvaluatorReplacementMember = true;
}
}
}

if (didEvaluatorReplacementMember) {
// Must re-evaluate axes because one of the evaluator's
// members has changed. Do not have to re-evaluate the
// slicer axis or any axis whose members used during evaluation
// were not over-ridden by members from the evaluation of
// different axes (if you just have rows and columns, then
// if rows contributed a member to axisMembers, then columns must
// be re-evaluated and if columns contributed, then rows must
// be re-evaluated).
for (int i = 0; i < axes.length; i++) {
QueryAxis axis = query.axes[i];
final Calc calc = query.axisCalcs[i];
evaluator.setCellReader(aggregatingReader);
RolapAxis axisResult =
executeAxis(evaluator.push(), axis, calc, true, null);
evaluator.clearExpResultCache();
this.axes[i] = axisResult;
if (didEvaluatorReplacementMember) {
// Must re-evaluate axes because one of the evaluator's
// members has changed. Do not have to re-evaluate the
// slicer axis or any axis whose members used during evaluation
// were not over-ridden by members from the evaluation of
// different axes (if you just have rows and columns, then
// if rows contributed a member to axisMembers, then columns must
// be re-evaluated and if columns contributed, then rows must
// be re-evaluated).
for (int i = 0; i < axes.length; i++) {
QueryAxis axis = query.axes[i];
final Calc calc = query.axisCalcs[i];
evaluator.setCellReader(aggregatingReader);
RolapAxis axisResult =
executeAxis(evaluator.push(), axis, calc, true, null);
evaluator.clearExpResultCache();
this.axes[i] = axisResult;
}
}
}
}


// Now that the axes are evaluated, make sure that the number of
Expand Down
48 changes: 48 additions & 0 deletions src/main/mondrian/util/Bug.java
@@ -0,0 +1,48 @@
/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2006-2006 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.util;

/**
* Holder for constants which indicate whether particular issues have been
* fixed. Reference one of those constants in your code, and it is clear which
* code can be enabled when the bug is fixed. Generally a constant is removed
* when its bug is fixed.
*
* @author jhyde
* @version $Id$
* @since Oct 11, 2006
*/
public class Bug {
/**
* Whether
* <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1574942&group_id=35302&atid=414613">bug 1574942, "NON EMPTY when hierarchy's default member is not 'all'"</a>
* is fixed.
*/
public static final boolean Bug1574942Fixed = false;

// Properties relating to checkin 7634.
// (What's the bug associated with this??)

public static boolean Checkin7634UseOptimizer = false;
public static boolean Checkin7634DoOld = false;
public static int Checkin7634Size = 0;

// Properties relating to checkin 7641.
// This is part of the junit test Checkin_7641 that
// shows that there is a difference when the default
// member is not the one used in an axis.
// When Checkin 7641 is resolved, then this System property access and
// boolean should go away.
// (What's the bug associated with this??)

public static boolean Checkin7641UseOptimizer = false;
}

// End Bug.java
40 changes: 20 additions & 20 deletions testsrc/main/mondrian/rolap/aggmatcher/Checkin_7634.java
Expand Up @@ -2,9 +2,11 @@
package mondrian.rolap.aggmatcher;

import mondrian.test.loader.CsvDBTestCase;
import mondrian.test.TestContext;
import mondrian.olap.Result;
import mondrian.util.Bug;

/**
/**
* Checkin 7634 attempted to correct a problem demonstrated by this
* junit. The CrossJoinFunDef class has an optimization that kicks in
* when the combined lists sizes are greater than 1000. I create a
Expand All @@ -20,19 +22,14 @@
* data for the default measure. Thus the old optimization fails
* to produce the correct result.
*
* @author <a>Richard M. Emberson</a>
* @version
* @author Richard M. Emberson
* @version $Id$
*/
public class Checkin_7634 extends CsvDBTestCase {
private static final String DIRECTORY =
"testsrc/main/mondrian/rolap/aggmatcher";
private static final String CHECKIN_7634 = "Checkin_7634.csv";

public static final String USE_PROP_NAME = "mondrian.test.7634.use";
public static final String OLD_PROP_NAME = "mondrian.test.7634.old";
public static final String SIZE_PROP_NAME = "mondrian.test.7634.size";


public Checkin_7634() {
super();
}
Expand All @@ -42,17 +39,18 @@ public Checkin_7634(String name) {
protected void setUp() throws Exception {
super.setUp();

System.getProperties().setProperty(SIZE_PROP_NAME, "2");
Bug.Checkin7634Size = 2;
}
protected void tearDown() throws Exception {
System.getProperties().remove(SIZE_PROP_NAME);
Bug.Checkin7634Size = 0;

super.tearDown();
}

public void _testCrossJoin() throws Exception {
public void testCrossJoin() throws Exception {
if (!Bug.Bug1574942Fixed) return;
// explicit use of [Product].[Class1]
String mdx =
String mdx =
"select {[Measures].[Requested Value]} ON COLUMNS,"+
" NON EMPTY Crossjoin("+
" {[Geography].[All Regions].Children},"+
Expand All @@ -63,30 +61,30 @@ public void _testCrossJoin() throws Exception {

// Execute query but do not used the CrossJoin nonEmptyList optimization
//System.out.println("NO OP");
System.getProperties().setProperty(USE_PROP_NAME, "not-null");
Bug.Checkin7634UseOptimizer = true;
Result result1 = getCubeTestContext().executeQuery(mdx);
String resultString1 = getCubeTestContext().toString(result1);
String resultString1 = TestContext.toString(result1);
//System.out.println(resultString1);
System.getProperties().remove(USE_PROP_NAME);
Bug.Checkin7634UseOptimizer = false;

// Execute query using the new version of the CrossJoin
// nonEmptyList optimization
//System.out.println("OP NEW");
Result result2 = getCubeTestContext().executeQuery(mdx);
String resultString2 = getCubeTestContext().toString(result2);
String resultString2 = TestContext.toString(result2);
//System.out.println(resultString2);

// This succeeds.
assertEquals(resultString1, resultString2);

//System.out.println("OP OLD");
// Execute query using the old version of the CrossJoin
// nonEmptyList optimization
System.getProperties().setProperty(OLD_PROP_NAME, "not-null");
Bug.Checkin7634DoOld = true;
Result result3 = getCubeTestContext().executeQuery(mdx);
String resultString3 = getCubeTestContext().toString(result3);
String resultString3 = TestContext.toString(result3);
//System.out.println(resultString3);
System.getProperties().remove(OLD_PROP_NAME);
Bug.Checkin7634DoOld = false;

// This fails.
assertEquals(resultString1, resultString3);
Expand Down Expand Up @@ -132,3 +130,5 @@ protected String getCubeDescription() {

}
}

// End Checkin_7634.java
23 changes: 14 additions & 9 deletions testsrc/main/mondrian/rolap/aggmatcher/Checkin_7641.java
Expand Up @@ -2,9 +2,11 @@
package mondrian.rolap.aggmatcher;

import mondrian.test.loader.CsvDBTestCase;
import mondrian.test.TestContext;
import mondrian.olap.Result;
import mondrian.util.Bug;

/**
/**
* Checkin 7641 attempted to correct a problem demonstrated by this
* junit. The original problem involved implicit Time member usage in
* on axis and the use of the default Time member in the other axis.
Expand All @@ -14,8 +16,8 @@
* depends upon the existance of a System property) one gets different
* answers when the mdx is evaluated.
*
* @author <a>Richard M. Emberson</a>
* @version
* @author Richard M. Emberson
* @version $Id$
*/
public class Checkin_7641 extends CsvDBTestCase {
private static final String DIRECTORY =
Expand All @@ -37,9 +39,10 @@ protected void tearDown() throws Exception {
super.tearDown();
}

public void _testImplicitMember() throws Exception {
public void testImplicitMember() throws Exception {
if (!Bug.Bug1574942Fixed) return;
// explicit use of [Product].[Class1]
String mdx =
String mdx =
" select NON EMPTY Crossjoin("+
" Hierarchize(Union({[Product].[Class1]}, [Product].[Class1].Children)), "+
" {[Measures].[Requested Value], "+
Expand All @@ -49,13 +52,13 @@ public void _testImplicitMember() throws Exception {
"[Geography].[All Regions].Children)) ON ROWS"+
" from [ImplicitMember]";

System.getProperties().setProperty(PROP_NAME, "not-null");
Bug.Checkin7641UseOptimizer = true;
Result result1 = getCubeTestContext().executeQuery(mdx);
String resultString1 = getCubeTestContext().toString(result1);
String resultString1 = TestContext.toString(result1);
//System.out.println(resultString1);
System.getProperties().remove(PROP_NAME);
Bug.Checkin7641UseOptimizer = false;
Result result2 = getCubeTestContext().executeQuery(mdx);
String resultString2 = getCubeTestContext().toString(result2);
String resultString2 = TestContext.toString(result2);
//System.out.println(resultString2);

assertEquals(resultString1, resultString2);
Expand Down Expand Up @@ -101,3 +104,5 @@ protected String getCubeDescription() {

}
}

// Checkin_7641.java

0 comments on commit 9938523

Please sign in to comment.