Skip to content

Commit

Permalink
MONDRIAN: Test case for MONDRIAN-675 (bug not fixed).
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian-release/3.1/": change = 13279]
  • Loading branch information
julianhyde committed Jan 2, 2010
1 parent 79e203a commit 5b99a82
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/main/mondrian/util/Bug.java
Expand Up @@ -148,6 +148,14 @@ public class Bug {
*/
public static final boolean BugMondrian648Fixed = false;

/**
* Whether
* <a href="http://jira.pentaho.com/browse/MONDRIAN-675">bug MONDRIAN-675,
* "Allow rollup of measures based on AVG aggregate function"</a>
* is fixed.
*/
public static final boolean BugMondrian675Fixed = false;

/**
* Returns whether to avoid a test because the memory monitor may cause it
* to fail.
Expand Down
49 changes: 49 additions & 0 deletions testsrc/main/mondrian/test/CompoundSlicerTest.java
Expand Up @@ -642,6 +642,55 @@ public void testCompoundSlicerWithDistinctCount() {
+ "Row #0: 1,175\n"
+ "Row #1: 352\n");
}

/**
* Tests compound slicer, and other rollups, with AVG function.
*
* <p>Test case for <a href="http://jira.pentaho.com/browse/MONDRIAN-675">
* Bug MONDRIAN-675,
* "Allow rollup of measures based on AVG aggregate function"</a>.
*/
public void testRollupAvg() {
final TestContext testContext =
TestContext.createSubstitutingCube(
"Sales",
null,
"<Measure name='Avg Unit Sales' aggregator='avg' column='unit_sales'/>",
null,
null);
// basic query with avg
testContext.assertQueryReturns(
"select from [Sales]\n"
+ "where [Measures].[Avg Unit Sales]",
"Axis #0:\n"
+ "{[Measures].[Avg Unit Sales]}\n"
+ "3.072");

// roll up using compound slicer
// (should give a real value, not an error)
testContext.assertQueryReturns(
"select from [Sales]\n"
+ "where [Measures].[Avg Unit Sales]\n"
+ " * {[Customers].[USA].[OR], [Customers].[USA].[CA]}",
Bug.BugMondrian675Fixed
? "what?"
: "Axis #0:\n"
+ "{[Measures].[Avg Unit Sales], [Customers].[All Customers].[USA].[OR]}\n"
+ "{[Measures].[Avg Unit Sales], [Customers].[All Customers].[USA].[CA]}\n"
+ "#ERR: mondrian.olap.fun.MondrianEvaluationException: Don't know how to rollup aggregator 'avg'");

// roll up using a named set
testContext.assertQueryReturns(
"with member [Customers].[OR and CA] as Aggregate(\n"
+ " {[Customers].[USA].[OR], [Customers].[USA].[CA]})\n"
+ "select from [Sales]\n"
+ "where ([Measures].[Avg Unit Sales], [Customers].[OR and CA])",
Bug.BugMondrian675Fixed
? "what?"
: "Axis #0:\n"
+ "{[Measures].[Avg Unit Sales], [Customers].[OR and CA]}\n"
+ "#ERR: mondrian.olap.fun.MondrianEvaluationException: Don't know how to rollup aggregator 'avg'");
}
}

// End CompoundSlicerTest.java
12 changes: 6 additions & 6 deletions testsrc/main/mondrian/test/SchemaTest.java
Expand Up @@ -2151,8 +2151,7 @@ public void testUnionRoleIllegalForwardRef() {
public void testVirtualCubeNamedSetSupportInSchema() {
final TestContext testContext = TestContext.createSubstitutingCube(
"Warehouse and Sales",
null,
null,
null, null, null,
"<NamedSet name=\"Non CA State Stores\" "
+ "formula=\"EXCEPT({[Store].[Store Country].[USA].children},{[Store].[Store Country].[USA].[CA]})\"/>");
testContext.assertQueryReturns(
Expand Down Expand Up @@ -2195,8 +2194,7 @@ public void testVirtualCubeNamedSetSupportInSchema() {
public void testVirtualCubeNamedSetSupportInSchemaError() {
final TestContext testContext = TestContext.createSubstitutingCube(
"Warehouse and Sales",
null,
null,
null, null, null,
"<NamedSet name=\"Non CA State Stores\" "
+ "formula=\"EXCEPT({[Store].[Store State].[USA].children},{[Store].[Store Country].[USA].[CA]})\"/>");
try {
Expand Down Expand Up @@ -2387,7 +2385,8 @@ public void testScdJoin() {
+ " <Level name=\"Product Class\" table=\"product_class\" nameColumn=\"product_subcategory\"\n"
+ " column=\"product_class_id\" type=\"Numeric\" uniqueMembers=\"true\"/>\n"
+ " </Hierarchy>\n"
+ " </Dimension>\n", null, null);
+ " </Dimension>\n",
null, null, null);
testContext.assertQueryReturns(
"select non empty {[Measures].[Unit Sales]} on 0,\n"
+ " non empty Filter({[Product truncated].Members}, [Measures].[Unit Sales] > 10000) on 1\n"
Expand Down Expand Up @@ -2421,7 +2420,8 @@ public void _testNonUniqueAlias() {
+ " <Level name=\"Product Class\" table=\"product_class\" nameColumn=\"product_subcategory\"\n"
+ " column=\"product_class_id\" type=\"Numeric\" uniqueMembers=\"true\"/>\n"
+ " </Hierarchy>\n"
+ " </Dimension>\n", null, null);
+ " </Dimension>\n",
null, null, null);
Throwable throwable = null;
try {
testContext.assertSimpleQuery();
Expand Down
21 changes: 18 additions & 3 deletions testsrc/main/mondrian/test/TestContext.java
Expand Up @@ -420,7 +420,7 @@ public String getFoodMartSchemaSubstitutingCube(
String memberDefs)
{
return getFoodMartSchemaSubstitutingCube(
cubeName, dimensionDefs, memberDefs, null);
cubeName, dimensionDefs, null, memberDefs, null);
}

/**
Expand All @@ -430,6 +430,7 @@ public String getFoodMartSchemaSubstitutingCube(
public String getFoodMartSchemaSubstitutingCube(
String cubeName,
String dimensionDefs,
String measureDefs,
String memberDefs,
String namedSetDefs)
{
Expand Down Expand Up @@ -458,6 +459,17 @@ public String getFoodMartSchemaSubstitutingCube(
+ s.substring(i);
}

// Add measure definitions, if specified.
if (measureDefs != null) {
int i = s.indexOf("<Measure", h);
if (i < 0 || i > end) {
i = end;
}
s = s.substring(0, i)
+ measureDefs
+ s.substring(i);
}

// Add calculated member definitions, if specified.
if (memberDefs != null) {
int i = s.indexOf("<CalculatedMember", h);
Expand Down Expand Up @@ -1612,7 +1624,7 @@ public static TestContext createSubstitutingCube(
final String memberDefs)
{
return createSubstitutingCube(
cubeName, dimensionDefs, memberDefs, null);
cubeName, dimensionDefs, null, memberDefs, null);
}


Expand All @@ -1622,21 +1634,24 @@ public static TestContext createSubstitutingCube(
*
* @param cubeName Name of a cube in the schema (cube must exist)
* @param dimensionDefs String defining dimensions, or null
* @param measureDefs String defining measures, or null
* @param memberDefs String defining calculated members, or null
* @param namedSetDefs String defining named set definitions, or null
* @return TestContext with modified cube defn
*/
public static TestContext createSubstitutingCube(
final String cubeName,
final String dimensionDefs,
final String measureDefs,
final String memberDefs,
final String namedSetDefs)
{
return new TestContext() {
public Util.PropertyList getFoodMartConnectionProperties() {
final String schema =
getFoodMartSchemaSubstitutingCube(
cubeName, dimensionDefs, memberDefs, namedSetDefs);
cubeName, dimensionDefs,
measureDefs, memberDefs, namedSetDefs);
Util.PropertyList properties =
super.getFoodMartConnectionProperties();
properties.put(
Expand Down
16 changes: 11 additions & 5 deletions testsrc/main/mondrian/test/clearview/ClearViewBase.java
Expand Up @@ -97,6 +97,12 @@ protected void runTest() throws Exception {
(! (customDimensions.equals("")
|| customDimensions.equals("${customDimensions}")))
? customDimensions : null;
String measures = diffRepos.expand(
null, "${measures}");
measures =
(! (measures.equals("")
|| measures.equals("${measures}")))
? measures : null;
String calculatedMembers = diffRepos.expand(
null, "${calculatedMembers}");
calculatedMembers =
Expand All @@ -109,8 +115,9 @@ protected void runTest() throws Exception {
(! (namedSets.equals("")
|| namedSets.equals("${namedSets}")))
? namedSets : null;
testContext = testContext.createSubstitutingCube(
cubeName, customDimensions, calculatedMembers, namedSets);
testContext = TestContext.createSubstitutingCube(
cubeName, customDimensions, measures, calculatedMembers,
namedSets);
}

// Set some properties to match the way we configure them
Expand All @@ -121,7 +128,7 @@ protected void runTest() throws Exception {

try {
String mdx = diffRepos.expand(null, "${mdx}");
String result = Util.nl + testContext.toString(
String result = Util.nl + TestContext.toString(
testContext.executeQuery(mdx));
diffRepos.assertEquals("result", "${result}", result);
} finally {
Expand Down Expand Up @@ -175,10 +182,9 @@ private SqlPattern[] buildSqlPatternArray() {
testCaseName, "expectedSql", dialect.name());
if (sql != null) {
sql = sql.replaceAll("[ \t\n\f\r]+", " ").trim();
SqlPattern[] patterns = {
return new SqlPattern[]{
new SqlPattern(dialect, sql, null)
};
return patterns;
}
return null;
}
Expand Down

0 comments on commit 5b99a82

Please sign in to comment.