Skip to content

Commit

Permalink
MONDRIAN: Testcases for cube whose fact table is a <View> element. (I…
Browse files Browse the repository at this point in the history
…t already worked fine.)

[git-p4: depot-paths = "//open/mondrian/": change = 8440]
  • Loading branch information
julianhyde committed Jan 3, 2007
1 parent ce91ceb commit d54f3b9
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions testsrc/main/mondrian/test/SchemaTest.java
Expand Up @@ -258,6 +258,111 @@ public void testDimensionsShareTable() {
"Row #62: 1,324\n" +
"Row #63: 523\n"));
}

/**
* Tests a cube whose fact table is a &lt;View&gt; element.
*/
public void testViewFactTable() {
TestContext testContext = TestContext.create(
null,

// Warehouse cube where the default member in the Warehouse
// dimension is USA.
"<Cube name=\"Warehouse (based on view)\">\n" +
" <View alias=\"FACT\">\n" +
" <SQL dialect=\"generic\">\n" +
" <![CDATA[select * from \"inventory_fact_1997\" as \"FOOBAR\"]]>\n" +
" </SQL>\n" +
" </View>\n" +
" <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\n" +
" <DimensionUsage name=\"Product\" source=\"Product\" foreignKey=\"product_id\"/>\n" +
" <DimensionUsage name=\"Store\" source=\"Store\" foreignKey=\"store_id\"/>\n" +
" <Dimension name=\"Warehouse\" foreignKey=\"warehouse_id\">\n" +
" <Hierarchy hasAll=\"false\" defaultMember=\"[USA]\" primaryKey=\"warehouse_id\"> \n" +
" <Table name=\"warehouse\"/>\n" +
" <Level name=\"Country\" column=\"warehouse_country\" uniqueMembers=\"true\"/>\n" +
" <Level name=\"State Province\" column=\"warehouse_state_province\"\n" +
" uniqueMembers=\"true\"/>\n" +
" <Level name=\"City\" column=\"warehouse_city\" uniqueMembers=\"false\"/>\n" +
" <Level name=\"Warehouse Name\" column=\"warehouse_name\" uniqueMembers=\"true\"/>\n" +
" </Hierarchy>\n" +
" </Dimension>\n" +
" <Measure name=\"Warehouse Cost\" column=\"warehouse_cost\" aggregator=\"sum\"/>\n" +
" <Measure name=\"Warehouse Sales\" column=\"warehouse_sales\" aggregator=\"sum\"/>\n" +
"</Cube>",
null, null, null);

testContext.assertQueryReturns(
"select\n" +
" {[Time].[1997], [Time].[1997].[Q3]} on columns,\n" +
" {[Store].[USA].Children} on rows\n" +
"From [Warehouse (based on view)]\n" +
"where [Warehouse].[USA]",
fold("Axis #0:\n" +
"{[Warehouse].[USA]}\n" +
"Axis #1:\n" +
"{[Time].[1997]}\n" +
"{[Time].[1997].[Q3]}\n" +
"Axis #2:\n" +
"{[Store].[All Stores].[USA].[CA]}\n" +
"{[Store].[All Stores].[USA].[OR]}\n" +
"{[Store].[All Stores].[USA].[WA]}\n" +
"Row #0: 25,789.086\n" +
"Row #0: 8,624.791\n" +
"Row #1: 17,606.904\n" +
"Row #1: 3,812.023\n" +
"Row #2: 45,647.262\n" +
"Row #2: 12,664.162\n"));
}

/**
* Tests a cube whose fact table is a &lt;View&gt; element, and which
* has dimensions based on the fact table.
*/
public void testViewFactTable2() {
TestContext testContext = TestContext.create(null,
// Similar to "Store" cube in FoodMart.xml.
"<Cube name=\"Store2\">\n" +
" <View alias=\"FACT\">\n" +
" <SQL dialect=\"generic\">\n" +
" <![CDATA[select * from \"store\" as \"FOOBAR\"]]>\n" +
" </SQL>\n" +
" </View>\n" +
" <!-- We could have used the shared dimension \"Store Type\", but we\n" +
" want to test private dimensions without primary key. -->\n" +
" <Dimension name=\"Store Type\">\n" +
" <Hierarchy hasAll=\"true\">\n" +
" <Level name=\"Store Type\" column=\"store_type\" uniqueMembers=\"true\"/>\n" +
" </Hierarchy>\n" +
" </Dimension>\n" +
"\n" +
" <Measure name=\"Store Sqft\" column=\"store_sqft\" aggregator=\"sum\"\n" +
" formatString=\"#,###\"/>\n" +
" <Measure name=\"Grocery Sqft\" column=\"grocery_sqft\" aggregator=\"sum\"\n" +
" formatString=\"#,###\"/>\n" +
"\n" +
"</Cube>",
null, null, null);
testContext.assertQueryReturns(
"select {[Store Type].Children} on columns from [Store2]",
fold("Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Store Type].[All Store Types]}\n" +
"{[Store Type].[All Store Types].[Deluxe Supermarket]}\n" +
"{[Store Type].[All Store Types].[Gourmet Supermarket]}\n" +
"{[Store Type].[All Store Types].[HeadQuarters]}\n" +
"{[Store Type].[All Store Types].[Mid-Size Grocery]}\n" +
"{[Store Type].[All Store Types].[Small Grocery]}\n" +
"{[Store Type].[All Store Types].[Supermarket]}\n" +
"Row #0: 571,596\n" +
"Row #0: 146,045\n" +
"Row #0: 47,447\n" +
"Row #0: \n" +
"Row #0: 109,343\n" +
"Row #0: 75,281\n" +
"Row #0: 193,480\n"));
}
}

// End SchemaTest.java

0 comments on commit d54f3b9

Please sign in to comment.