Skip to content

Commit

Permalink
MONDRIAN: Created Test Cases for Shared Tables, bugs include:
Browse files Browse the repository at this point in the history
[ 1735827 ] Shared Tables and native NonEmptyCrossJoin
[ 1735839 ] Shared Tables with Two Separate Aliases Fail

[git-p4: depot-paths = "//open/mondrian/": change = 9456]
  • Loading branch information
Will Gorman committed Jun 12, 2007
1 parent 3fb515a commit ebe128b
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/mondrian/util/Bug.java
Expand Up @@ -53,6 +53,20 @@ public class Bug {
*/
public static final boolean Bug1722959Fixed = false;

/**
* Whether
* <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1735827&group_id=35302&atid=414613">bug 1735827, "Shared Tables and native NonEmptyCrossJoin"</a>
* is fixed.
*/
public static final boolean Bug1735827Fixed = false;

/**
* Whether
* <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1735839&group_id=35302&atid=414613">bug 1735839, "Shared Tables with Two Separate Aliases Fail"</a>
* is fixed.
*/
public static final boolean Bug1735839Fixed = false;

/**
* Returns whether to avoid a test because the memory monitor may cause it
* to fail.
Expand Down
167 changes: 167 additions & 0 deletions testsrc/main/mondrian/test/SchemaTest.java
Expand Up @@ -12,6 +12,7 @@
import org.apache.log4j.*;
import org.apache.log4j.varia.LevelRangeFilter;
import mondrian.rolap.aggmatcher.AggTableManager;
import mondrian.util.Bug;
import mondrian.olap.MondrianProperties;

import java.io.StringWriter;
Expand Down Expand Up @@ -112,6 +113,37 @@ public void testDuplicateTableAlias() {
"Duplicate table alias 'customer' in cube 'Sales'");
}

/**
* This result is somewhat peculiar. If two dimensions share a foreign key, what
* is the expected result? Also, in this case, they share the same table without
* an alias, and the system doesn't complain.
*/
public void testDuplicateTableAliasSameForeignKey() {
final TestContext testContext = TestContext.createSubstitutingCube(
"Sales",
"<Dimension name=\"Yearly Income2\" foreignKey=\"customer_id\">\n" +
" <Hierarchy hasAll=\"true\" primaryKey=\"customer_id\">\n" +
" <Table name=\"customer\"/>\n" +
" <Level name=\"Yearly Income\" column=\"yearly_income\" uniqueMembers=\"true\"/>\n" +
" </Hierarchy>\n" +
"</Dimension>");
testContext.assertQueryReturns(
"select from [Sales]",
fold("Axis #0:\n" +
"{}\n" +
"266,773"));

/** NonEmptyCrossJoin Fails
testContext.assertQueryReturns(
"select NonEmptyCrossJoin({[Yearly Income2].[All Yearly Income2s]},{[Customers].[All Customers]}) on rows," +
"NON EMPTY {[Measures].[Unit Sales]} on columns" +
" from [Sales]",
fold("Axis #0:\n" +
"{}\n" +
"266,773"));
*/
}

/**
* Tests two dimensions using same table (via different join paths).
* Without the table alias, generates SQL which is missing a join condition.
Expand Down Expand Up @@ -266,6 +298,141 @@ public void testDimensionsShareTable() {
"Row #63: 523\n"));
}

/**
* Tests two dimensions using same table (via different join paths).
* native non empty cross join sql generation returns empty query.
*/
public void testDimensionsShareTableNativeNonEmptyCrossJoin() {
if (Bug.Bug1735827Fixed) {
final TestContext testContext = TestContext.createSubstitutingCube(
"Sales",
"<Dimension name=\"Yearly Income2\" foreignKey=\"product_id\">\n" +
" <Hierarchy hasAll=\"true\" primaryKey=\"customer_id\">\n" +
" <Table name=\"customer\" alias=\"customerx\" />\n" +
" <Level name=\"Yearly Income\" column=\"yearly_income\" uniqueMembers=\"true\"/>\n" +
" </Hierarchy>\n" +
"</Dimension>");

testContext.assertQueryReturns(
"select NonEmptyCrossJoin({[Yearly Income2].[All Yearly Income2s]},{[Customers].[All Customers]}) on rows," +
"NON EMPTY {[Measures].[Unit Sales]} on columns" +
" from [Sales]",
fold("Axis #0:\n" +
"{}\n" +
"266,773"));
}
}

/**
* Tests two dimensions using same table with same foreign key
* one table uses an alias.
*
*/
public void testDimensionsShareTableSameForeignKeys() {
// this is most likely due to the same bug
// but i'm not 100% certain
if (Bug.Bug1735827Fixed) {
final TestContext testContext = TestContext.createSubstitutingCube(
"Sales",
"<Dimension name=\"Yearly Income2\" foreignKey=\"customer_id\">\n" +
" <Hierarchy hasAll=\"true\" primaryKey=\"customer_id\">\n" +
" <Table name=\"customer\" alias=\"customerx\" />\n" +
" <Level name=\"Yearly Income\" column=\"yearly_income\" uniqueMembers=\"true\"/>\n" +
" </Hierarchy>\n" +
"</Dimension>");
testContext.assertQueryReturns(
"select NON EMPTY {[Measures].[Unit Sales]} ON COLUMNS,\n" +
"NON EMPTY Crossjoin({[Yearly Income].[All Yearly Incomes].Children},\n" +
" [Yearly Income2].[All Yearly Income2s].Children) ON ROWS\n" +
"from [Sales]",
"Not Sure Yet");
}
}

/**
* Tests two dimensions using same table (via different join paths).
* both using a table alias.
*/
public void testTwoAliasesDimensionsShareTable() {
if (Bug.Bug1735839Fixed) {
final TestContext testContext = TestContext.create(
null,
"<Cube name=\"AliasedDimensionsTesting\" defaultMeasure=\"Supply Time\">\n" +
" <Table name=\"inventory_fact_1997\"/>\n" +
" <Dimension name=\"StoreA\" foreignKey=\"store_id\">" +
" <Hierarchy hasAll=\"true\" primaryKey=\"store_id\">" +
" <Table name=\"store\" alias=\"storea\"/>" +
" <Level name=\"Store Country\" column=\"store_country\" uniqueMembers=\"true\"/>" +
" <Level name=\"Store Name\" column=\"store_name\" uniqueMembers=\"true\"/>" +
" </Hierarchy>" +
" </Dimension>" +

" <Dimension name=\"StoreB\" foreignKey=\"customer_id\">" +
" <Hierarchy hasAll=\"true\" primaryKey=\"store_id\">" +
" <Table name=\"store\" alias=\"storeb\"/>" +
" <Level name=\"Store Country\" column=\"store_country\" uniqueMembers=\"true\"/>" +
" <Level name=\"Store Name\" column=\"store_name\" uniqueMembers=\"true\"/>" +
" </Hierarchy>" +
" </Dimension>" +
" <Measure name=\"Store Invoice\" column=\"store_invoice\" " +
"aggregator=\"sum\"/>\n" +
" <Measure name=\"Supply Time\" column=\"supply_time\" " +
"aggregator=\"sum\"/>\n" +
" <Measure name=\"Warehouse Cost\" column=\"warehouse_cost\" " +
"aggregator=\"sum\"/>\n" +
"</Cube>",
null, null, null);

testContext.assertQueryReturns(
"select NON EMPTY [StoreA].[USA].children on rows," +
"{[Measures].[Warehouse Cost]} on columns" +
" from " +
"AliasedDimensionsTesting", "Not Sure Yet");
}
}

/**
* Tests two dimensions using same table with same foreign key.
* both using a table alias.
*/
public void testTwoAliasesDimensionsShareTableSameForeignKeys() {
if (Bug.Bug1735839Fixed) {
final TestContext testContext = TestContext.create(
null,
"<Cube name=\"AliasedDimensionsTesting\" defaultMeasure=\"Supply Time\">\n" +
" <Table name=\"inventory_fact_1997\"/>\n" +
" <Dimension name=\"StoreA\" foreignKey=\"store_id\">" +
" <Hierarchy hasAll=\"true\" primaryKey=\"store_id\">" +
" <Table name=\"store\" alias=\"storea\"/>" +
" <Level name=\"Store Country\" column=\"store_country\" uniqueMembers=\"true\"/>" +
" <Level name=\"Store Name\" column=\"store_name\" uniqueMembers=\"true\"/>" +
" </Hierarchy>" +
" </Dimension>" +

" <Dimension name=\"StoreB\" foreignKey=\"store_id\">" +
" <Hierarchy hasAll=\"true\" primaryKey=\"store_id\">" +
" <Table name=\"store\" alias=\"storeb\"/>" +
" <Level name=\"Store Country\" column=\"store_country\" uniqueMembers=\"true\"/>" +
" <Level name=\"Store Name\" column=\"store_name\" uniqueMembers=\"true\"/>" +
" </Hierarchy>" +
" </Dimension>" +
" <Measure name=\"Store Invoice\" column=\"store_invoice\" " +
"aggregator=\"sum\"/>\n" +
" <Measure name=\"Supply Time\" column=\"supply_time\" " +
"aggregator=\"sum\"/>\n" +
" <Measure name=\"Warehouse Cost\" column=\"warehouse_cost\" " +
"aggregator=\"sum\"/>\n" +
"</Cube>",
null, null, null);

testContext.assertQueryReturns(
"select NON EMPTY [StoreA].[USA].children on rows," +
"{[Measures].[Warehouse Cost]} on columns" +
" from " +
"AliasedDimensionsTesting", "Not Sure Yet");
}
}

/**
* Tests a cube whose fact table is a &lt;View&gt; element.
*/
Expand Down

0 comments on commit ebe128b

Please sign in to comment.