use of mondrian.test.TestContext in project mondrian by pentaho.
the class NonEmptyTest method testContextAtAllWorksWithConstraint.
public void testContextAtAllWorksWithConstraint() {
TestContext ctx = TestContext.instance().create(null, "<Cube name=\"onlyGender\"> \n" + " <Table name=\"sales_fact_1997\"/> \n" + "<Dimension name=\"Gender\" foreignKey=\"customer_id\">\n" + " <Hierarchy hasAll=\"true\" allMemberName=\"All Gender\" primaryKey=\"customer_id\">\n" + " <Table name=\"customer\"/>\n" + " <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\"/>\n" + " </Hierarchy>\n" + " </Dimension>" + " <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"/> \n" + "</Cube> \n", null, null, null, null);
String mdx = " select " + " NON EMPTY {[Measures].[Unit Sales]} ON COLUMNS, " + " NON EMPTY {[Gender].[Gender].Members} ON ROWS " + " from [onlyGender] ";
ctx.assertQueryReturns(mdx, "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n" + "{[Gender].[F]}\n" + "{[Gender].[M]}\n" + "Row #0: 131,558\n" + "Row #1: 135,215\n");
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class NonEmptyTest method testDefaultMemberNonEmptyContext.
public void testDefaultMemberNonEmptyContext() {
TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", " <Dimension name=\"Store2\" foreignKey=\"store_id\" >\n" + " <Hierarchy hasAll=\"false\" primaryKey=\"store_id\" defaultMember='[Store2].[USA].[OR]'>\n" + " <Table name=\"store\"/>\n" + " <Level name=\"Store Country\" column=\"store_country\" uniqueMembers=\"true\"\n" + " />\n" + " <Level name=\"Store State\" column=\"store_state\" uniqueMembers=\"true\"\n" + " />\n" + " <Level name=\"Store City\" column=\"store_city\" uniqueMembers=\"false\" />\n" + " </Hierarchy>\n" + " </Dimension>");
testContext.assertQueryReturns("with member measures.one as '1' " + "select non empty store2.usa.[OR].children on 0, measures.one on 1 from sales", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Store2].[USA].[OR].[Portland]}\n" + "{[Store2].[USA].[OR].[Salem]}\n" + "Axis #2:\n" + "{[Measures].[one]}\n" + "Row #0: 1\n" + "Row #0: 1\n");
testContext.assertQueryReturns("with member measures.one as '1' " + "select store2.usa.[OR].children on 0, measures.one on 1 from sales", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Store2].[USA].[OR].[Portland]}\n" + "{[Store2].[USA].[OR].[Salem]}\n" + "Axis #2:\n" + "{[Measures].[one]}\n" + "Row #0: 1\n" + "Row #0: 1\n");
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class NonEmptyTest method testMultiLevelMemberConstraintNullParent.
/**
* Checks that multi-level member list generates compact form of SQL where
* clause:
* (1) Use IN list if possible(not possible if there are null values because
* NULLs in IN lists do not match)
* (2) Group members sharing the same parent, including parents with NULLs.
* (3) If parent levels include NULLs, comparision includes any unique
* level.
*/
public void testMultiLevelMemberConstraintNullParent() {
propSaver.set(propSaver.properties.GenerateFormattedSql, true);
if (!isDefaultNullMemberRepresentation()) {
return;
}
if (!MondrianProperties.instance().FilterChildlessSnowflakeMembers.get()) {
return;
}
String dimension = "<Dimension name=\"Warehouse2\">\n" + " <Hierarchy hasAll=\"true\" primaryKey=\"warehouse_id\">\n" + " <Table name=\"warehouse\"/>\n" + " <Level name=\"address3\" column=\"wa_address3\" uniqueMembers=\"true\"/>\n" + " <Level name=\"address2\" column=\"wa_address2\" uniqueMembers=\"true\"/>\n" + " <Level name=\"address1\" column=\"wa_address1\" uniqueMembers=\"false\"/>\n" + " <Level name=\"name\" column=\"warehouse_name\" uniqueMembers=\"false\"/>\n" + " </Hierarchy>\n" + "</Dimension>\n";
String cube = "<Cube name=\"Warehouse2\">\n" + " <Table name=\"inventory_fact_1997\"/>\n" + " <DimensionUsage name=\"Product\" source=\"Product\" foreignKey=\"product_id\"/>\n" + " <DimensionUsage name=\"Warehouse2\" source=\"Warehouse2\" foreignKey=\"warehouse_id\"/>\n" + " <Measure name=\"Warehouse Cost\" column=\"warehouse_cost\" aggregator=\"sum\"/>\n" + " <Measure name=\"Warehouse Sales\" column=\"warehouse_sales\" aggregator=\"sum\"/>\n" + "</Cube>";
String query = "with\n" + "set [Filtered Warehouse Set] as " + "{[Warehouse2].[#null].[#null].[5617 Saclan Terrace].[Arnold and Sons]," + " [Warehouse2].[#null].[#null].[3377 Coachman Place].[Jones International]} " + "set [NECJ] as NonEmptyCrossJoin([Filtered Warehouse Set], {[Product].[Product Family].Food}) " + "select [NECJ] on columns from [Warehouse2]";
String necjSqlMySql = "select\n" + " `warehouse`.`wa_address3` as `c0`,\n" + " `warehouse`.`wa_address2` as `c1`,\n" + " `warehouse`.`wa_address1` as `c2`,\n" + " `warehouse`.`warehouse_name` as `c3`,\n" + " `product_class`.`product_family` as `c4`\n" + "from\n" + " `warehouse` as `warehouse`,\n" + " `inventory_fact_1997` as `inventory_fact_1997`,\n" + " `product` as `product`,\n" + " `product_class` as `product_class`\n" + "where\n" + " `inventory_fact_1997`.`warehouse_id` = `warehouse`.`warehouse_id`\n" + "and\n" + " `product`.`product_class_id` = `product_class`.`product_class_id`\n" + "and\n" + " `inventory_fact_1997`.`product_id` = `product`.`product_id`\n" + "and\n" + " ((( `warehouse`.`wa_address2` IS NULL ) and (`warehouse`.`warehouse_name`, `warehouse`.`wa_address1`) in (('Arnold and Sons', '5617 Saclan Terrace'), ('Jones International', '3377 Coachman Place'))))\n" + "and\n" + " (`product_class`.`product_family` = 'Food')\n" + "group by\n" + " `warehouse`.`wa_address3`,\n" + " `warehouse`.`wa_address2`,\n" + " `warehouse`.`wa_address1`,\n" + " `warehouse`.`warehouse_name`,\n" + " `product_class`.`product_family`\n" + "order by\n" + (TestContext.instance().getDialect().requiresOrderByAlias() ? " ISNULL(`c0`) ASC, `c0` ASC,\n" + " ISNULL(`c1`) ASC, `c1` ASC,\n" + " ISNULL(`c2`) ASC, `c2` ASC,\n" + " ISNULL(`c3`) ASC, `c3` ASC,\n" + " ISNULL(`c4`) ASC, `c4` ASC" : " ISNULL(`warehouse`.`wa_address3`) ASC, `warehouse`.`wa_address3` ASC,\n" + " ISNULL(`warehouse`.`wa_address2`) ASC, `warehouse`.`wa_address2` ASC,\n" + " ISNULL(`warehouse`.`wa_address1`) ASC, `warehouse`.`wa_address1` ASC,\n" + " ISNULL(`warehouse`.`warehouse_name`) ASC, `warehouse`.`warehouse_name` ASC,\n" + " ISNULL(`product_class`.`product_family`) ASC, `product_class`.`product_family` ASC");
TestContext testContext = TestContext.instance().create(dimension, cube, null, null, null, null);
SqlPattern[] patterns = { new SqlPattern(Dialect.DatabaseProduct.MYSQL, necjSqlMySql, necjSqlMySql) };
assertQuerySql(testContext, query, patterns);
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class NonEmptyTest method testNonEmptyWithWeirdDefaultMember.
/**
* Tests the behavior if you have NON EMPTY on both axes, and the default
* member of a hierarchy is not 'all' or the first child.
*/
public void testNonEmptyWithWeirdDefaultMember() {
if (!Bug.BugMondrian229Fixed) {
return;
}
TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", " <Dimension name=\"Time\" type=\"TimeDimension\" foreignKey=\"time_id\">\n" + " <Hierarchy hasAll=\"false\" primaryKey=\"time_id\" defaultMember=\"[Time].[1997].[Q1].[1]\" >\n" + " <Table name=\"time_by_day\"/>\n" + " <Level name=\"Year\" column=\"the_year\" type=\"Numeric\" uniqueMembers=\"true\"\n" + " levelType=\"TimeYears\"/>\n" + " <Level name=\"Quarter\" column=\"quarter\" uniqueMembers=\"false\"\n" + " levelType=\"TimeQuarters\"/>\n" + " <Level name=\"Month\" column=\"month_of_year\" uniqueMembers=\"false\" type=\"Numeric\"\n" + " levelType=\"TimeMonths\"/>\n" + " </Hierarchy>\n" + " </Dimension>");
// Check that the grand total is different than when [Time].[1997] is
// the default member.
testContext.assertQueryReturns("select from [Sales]", "Axis #0:\n" + "{}\n" + "21,628");
// Results of this query agree with MSAS 2000 SP1.
// The query gives the same results if the default member of [Time]
// is [Time].[1997] or [Time].[1997].[Q1].[1].
testContext.assertQueryReturns("select\n" + "NON EMPTY Crossjoin({[Time].[1997].[Q2].[4]}, [Customers].[Country].members) on columns,\n" + "NON EMPTY [Product].[All Products].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Portsmouth].children on rows\n" + "from sales", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Time].[1997].[Q2].[4], [Customers].[USA]}\n" + "Axis #2:\n" + "{[Product].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Portsmouth].[Portsmouth Imported Beer]}\n" + "{[Product].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Portsmouth].[Portsmouth Light Beer]}\n" + "Row #0: 3\n" + "Row #1: 21\n");
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class NonEmptyTest method testDependentSlicerMemberNonNative.
public void testDependentSlicerMemberNonNative() {
propSaver.set(MondrianProperties.instance().EnableNativeCrossJoin, false);
// Get a fresh connection; Otherwise the mondrian property setting
// is not refreshed for this parameter.
final TestContext context = getTestContext().withFreshConnection();
try {
context.assertQueryReturns("with set [p] as '[Product].[Product Family].members' " + "set [s] as '[Store].[Store Country].members' " + "set [ne] as 'nonemptycrossjoin([p],[s])' " + "set [nep] as 'Generate([ne],{[Product].CurrentMember})' " + "select [nep] on columns from sales " + "where ([Time].[1998])", "Axis #0:\n" + "{[Time].[1998]}\n" + "Axis #1:\n");
} finally {
context.close();
}
}
Aggregations