Search in sources :

Example 1 with SqlPattern

use of mondrian.test.SqlPattern in project mondrian by pentaho.

the class TestAggregationManager method testCountDistinctAggMatch.

public void testCountDistinctAggMatch() {
    if (!(MondrianProperties.instance().UseAggregates.get() && MondrianProperties.instance().ReadAggregates.get())) {
        return;
    }
    CellRequest request = createRequest("Sales", "[Measures].[Customer Count]", new String[] { "time_by_day", "time_by_day", "time_by_day" }, new String[] { "the_year", "quarter", "month_of_year" }, new String[] { "1997", "Q1", "1" });
    String accessSql = "select " + "`agg_c_10_sales_fact_1997`.`the_year` as `c0`, " + "`agg_c_10_sales_fact_1997`.`quarter` as `c1`, " + "`agg_c_10_sales_fact_1997`.`month_of_year` as `c2`, " + "`agg_c_10_sales_fact_1997`.`customer_count` as `m0` " + "from " + "`agg_c_10_sales_fact_1997` as `agg_c_10_sales_fact_1997` " + "where " + "`agg_c_10_sales_fact_1997`.`the_year` = 1997 and " + "`agg_c_10_sales_fact_1997`.`quarter` = 'Q1' and " + "`agg_c_10_sales_fact_1997`.`month_of_year` = 1";
    SqlPattern[] patterns = { new SqlPattern(Dialect.DatabaseProduct.ACCESS, accessSql, 26) };
    assertRequestSql(new CellRequest[] { request }, patterns);
}
Also used : SqlPattern(mondrian.test.SqlPattern)

Example 2 with SqlPattern

use of mondrian.test.SqlPattern in project mondrian by pentaho.

the class TestAggregationManager method _testMultipleMeasures_withAgg.

/**
 * As {@link #testMultipleMeasures()}, but with aggregate tables switched
 * on.
 *
 * TODO: Enable this test.
 */
private void _testMultipleMeasures_withAgg() {
    CellRequest[] requests = new CellRequest[] { createRequest("Sales", "[Measures].[Unit Sales]", new String[] { "customer", "store" }, new String[] { "gender", "store_state" }, new String[] { "F", "CA" }), createRequest("Sales", "[Measures].[Store Sales]", new String[] { "customer", "store" }, new String[] { "gender", "store_state" }, new String[] { "M", "CA" }), createRequest("Sales", "[Measures].[Unit Sales]", new String[] { "customer", "store" }, new String[] { "gender", "store_state" }, new String[] { "F", "OR" }) };
    SqlPattern[] patterns = { new SqlPattern(ACCESS_MYSQL, "select `customer`.`gender` as `c0`," + " `store`.`store_state` as `c1`," + " sum(`agg_l_05_sales_fact_1997`.`unit_sales`) as `m0`," + " sum(`agg_l_05_sales_fact_1997`.`store_sales`) as `m1` " + "from `customer` as `customer`," + " `agg_l_05_sales_fact_1997` as `agg_l_05_sales_fact_1997`," + " `store` as `store` " + "where `agg_l_05_sales_fact_1997`.`customer_id` = `customer`.`customer_id`" + " and `agg_l_05_sales_fact_1997`.`store_id` = `store`.`store_id`" + " and `store`.`store_state` in ('CA', 'OR') " + "group by `customer`.`gender`, `store`.`store_state`", 26) };
    assertRequestSql(requests, patterns);
}
Also used : SqlPattern(mondrian.test.SqlPattern)

Example 3 with SqlPattern

use of mondrian.test.SqlPattern in project mondrian by pentaho.

the class TestAggregationManager method testCollapsedChildren.

/**
 * this test verifies the collapsed children code in SqlMemberSource
 */
public void testCollapsedChildren() {
    if (!(MondrianProperties.instance().UseAggregates.get() && MondrianProperties.instance().ReadAggregates.get())) {
        return;
    }
    if (!(MondrianProperties.instance().EnableNativeCrossJoin.get())) {
        return;
    }
    // flush cache to be sure sql is executed
    TestContext.instance().flushSchemaCache();
    SqlPattern[] patterns = { new SqlPattern(ACCESS_MYSQL, "select " + "`agg_g_ms_pcat_sales_fact_1997`.`gender` as `c0` " + "from `agg_g_ms_pcat_sales_fact_1997` " + "as `agg_g_ms_pcat_sales_fact_1997` " + "group by " + "`agg_g_ms_pcat_sales_fact_1997`.`gender`" + " order by ISNULL(`agg_g_ms_pcat_sales_fact_1997`.`gender`) ASC, `agg_g_ms_pcat_sales_fact_1997`.`gender` ASC", null) };
    String query = "select non empty [Gender].Children on columns\n" + "from [Sales]";
    assertQuerySqlOrNot(getTestContext(), query, patterns, false, false, false);
    assertQueryReturns(query, "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Gender].[F]}\n" + "{[Gender].[M]}\n" + "Row #0: 131,558\n" + "Row #0: 135,215\n");
}
Also used : SqlPattern(mondrian.test.SqlPattern)

Example 4 with SqlPattern

use of mondrian.test.SqlPattern in project mondrian by pentaho.

the class TestAggregationManager method testOrdinalExprAggTuplesAndChildren.

/**
 * Test case for
 * <a href="http://jira.pentaho.com/browse/MONDRIAN-663">bug MONDRIAN-663,
 * "Improve metadata query (TupleReader) support for aggregation tables to
 * include dimensions defining more than one column"</a>.
 */
public void testOrdinalExprAggTuplesAndChildren() {
    // this verifies that we can load properties, ordinals, etc out of
    // agg tables in member lookups (tuples and children)
    propSaver.set(propSaver.properties.GenerateFormattedSql, true);
    if (!(MondrianProperties.instance().UseAggregates.get() && MondrianProperties.instance().ReadAggregates.get())) {
        return;
    }
    if (!(MondrianProperties.instance().EnableNativeCrossJoin.get())) {
        return;
    }
    TestContext.instance().flushSchemaCache();
    String cube = "<Cube name=\"Sales_Prod_Ord\">\n" + "  <Table name=\"sales_fact_1997\"/>\n" + "  <Dimension name=\"Product\" foreignKey=\"product_id\">\n" + "    <Hierarchy hasAll=\"true\" primaryKey=\"product_id\" primaryKeyTable=\"product\">\n" + "      <Join leftKey=\"product_class_id\" rightKey=\"product_class_id\">\n" + "        <Table name=\"product\"/>\n" + "        <Table name=\"product_class\"/>\n" + "      </Join>\n" + "      <Level name=\"Product Family\" table=\"product_class\" column=\"product_family\"\n" + "          uniqueMembers=\"true\"/>\n" + "      <Level name=\"Product Department\" table=\"product_class\" column=\"product_department\"\n" + "          uniqueMembers=\"false\"/>\n" + "      <Level name=\"Product Category\" table=\"product_class\" captionColumn=\"product_family\" column=\"product_category\"\n" + "          uniqueMembers=\"false\"/>\n" + "      <Level name=\"Product Subcategory\" table=\"product_class\" column=\"product_subcategory\"\n" + "          uniqueMembers=\"false\"/>\n" + "      <Level name=\"Brand Name\" table=\"product\" column=\"brand_name\" uniqueMembers=\"false\"/>\n" + "      <Level name=\"Product Name\" table=\"product\" column=\"product_name\"\n" + "          uniqueMembers=\"true\"/>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "  <Dimension name=\"Gender\" foreignKey=\"customer_id\">\n" + "    <Hierarchy hasAll=\"false\" 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" + "      formatString=\"Standard\" visible=\"false\"/>\n" + "  <Measure name=\"Store Cost\" column=\"store_cost\" aggregator=\"sum\"\n" + "      formatString=\"#,###.00\"/>\n" + "</Cube>";
    TestContext testContext = TestContext.instance().create(null, cube, null, null, null, null);
    String query = "select {[Measures].[Unit Sales]} on columns, " + "non empty CrossJoin({[Product].[Food].[Deli].[Meat]},{[Gender].[M]}) on rows " + "from [Sales_Prod_Ord] ";
    // first check that the sql is generated correctly
    SqlPattern[] patterns = { new SqlPattern(ACCESS_MYSQL, "select\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`product_family` as `c0`,\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`product_department` as `c1`,\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`product_category` as `c2`,\n" + "    `product_class`.`product_family` as `c3`,\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`gender` as `c4`\n" + "from\n" + "    `agg_g_ms_pcat_sales_fact_1997` as `agg_g_ms_pcat_sales_fact_1997`,\n" + "    `product_class` as `product_class`\n" + "where\n" + "    `product_class`.`product_category` = `agg_g_ms_pcat_sales_fact_1997`.`product_category`\n" + "and\n" + "    (`agg_g_ms_pcat_sales_fact_1997`.`product_category` = 'Meat' and `agg_g_ms_pcat_sales_fact_1997`.`product_department` = 'Deli' and `agg_g_ms_pcat_sales_fact_1997`.`product_family` = 'Food')\n" + "and\n" + "    (`agg_g_ms_pcat_sales_fact_1997`.`gender` = 'M')\n" + "group by\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`product_family`,\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`product_department`,\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`product_category`,\n" + "    `product_class`.`product_family`,\n" + "    `agg_g_ms_pcat_sales_fact_1997`.`gender`\n" + "order by\n" + "    ISNULL(`agg_g_ms_pcat_sales_fact_1997`.`product_family`) ASC, `agg_g_ms_pcat_sales_fact_1997`.`product_family` ASC,\n" + "    ISNULL(`agg_g_ms_pcat_sales_fact_1997`.`product_department`) ASC, `agg_g_ms_pcat_sales_fact_1997`.`product_department` ASC,\n" + "    ISNULL(`agg_g_ms_pcat_sales_fact_1997`.`product_category`) ASC, `agg_g_ms_pcat_sales_fact_1997`.`product_category` ASC,\n" + "    ISNULL(`agg_g_ms_pcat_sales_fact_1997`.`gender`) ASC, `agg_g_ms_pcat_sales_fact_1997`.`gender` ASC", null) };
    assertQuerySqlOrNot(testContext, query, patterns, false, false, false);
    testContext.assertQueryReturns(query, "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n" + "{[Product].[Food].[Deli].[Meat], [Gender].[M]}\n" + "Row #0: 4,705\n");
    Result result = testContext.executeQuery(query);
    // this verifies that the caption for meat is Food
    assertEquals("Meat", result.getAxes()[1].getPositions().get(0).get(0).getName());
    assertEquals("Food", result.getAxes()[1].getPositions().get(0).get(0).getCaption());
    // Test children
    query = "select {[Measures].[Unit Sales]} on columns, " + "non empty [Product].[Food].[Deli].Children on rows " + "from [Sales_Prod_Ord] ";
    testContext.assertQueryReturns(query, "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n" + "{[Product].[Food].[Deli].[Meat]}\n" + "{[Product].[Food].[Deli].[Side Dishes]}\n" + "Row #0: 4,728\n" + "Row #1: 1,262\n");
}
Also used : TestContext(mondrian.test.TestContext) SqlPattern(mondrian.test.SqlPattern)

Example 5 with SqlPattern

use of mondrian.test.SqlPattern in project mondrian by pentaho.

the class TestAggregationManager method testNonCollapsedAggregateAllLevelsPresentInQuery.

public void testNonCollapsedAggregateAllLevelsPresentInQuery() throws Exception {
    // MONDRIAN-1072
    propSaver.set(MondrianProperties.instance().UseAggregates, true);
    propSaver.set(MondrianProperties.instance().ReadAggregates, true);
    final String cube = "<Schema name=\"AMC\"><Cube name=\"Foo\" defaultMeasure=\"Unit Sales\">\n" + "  <Table name=\"sales_fact_1997\">\n" + "    <AggExclude name=\"agg_g_ms_pcat_sales_fact_1997\"/>" + "    <AggExclude name=\"agg_c_14_sales_fact_1997\"/>" + "    <AggExclude name=\"agg_pl_01_sales_fact_1997\"/>" + "    <AggExclude name=\"agg_ll_01_sales_fact_1997\"/>" + "    <AggExclude name=\"agg_l_03_sales_fact_1997\"/>" + "    <AggExclude name=\"agg_lc_06_sales_fact_1997\"/>" + "    <AggExclude name=\"agg_l_04_sales_fact_1997\"/>" + "    <AggExclude name=\"agg_c_10_sales_fact_1997\"/>" + "    <AggName name=\"agg_l_05_sales_fact_1997\">" + "        <AggFactCount column=\"fact_count\"/>\n" + "        <AggIgnoreColumn column=\"customer_id\"/>\n" + "        <AggIgnoreColumn column=\"store_id\"/>\n" + "        <AggIgnoreColumn column=\"promotion_id\"/>\n" + " <AggForeignKey factColumn=\"promotion_id\" aggColumn=\"promotion_id\"/>" + "        <AggMeasure name=\"[Measures].[Store Cost]\" column=\"store_cost\" />\n" + "        <AggMeasure name=\"[Measures].[Store Sales]\" column=\"store_sales\" />\n" + "        <AggMeasure name=\"[Measures].[Unit Sales]\" column=\"unit_sales\" />\n" + "    </AggName>\n" + "</Table>\n" + "  <Dimension name=\"Promotions\" foreignKey=\"promotion_id\">\n" + "    <Hierarchy hasAll=\"true\" allMemberName=\"All Promotions\" primaryKey=\"promotion_id\" defaultMember=\"[All Promotions]\">\n" + "      <Table name=\"promotion\"/>\n" + "      <Level name=\"Media Type\" column=\"media_type\" uniqueMembers=\"true\"/>\n" + "    </Hierarchy>\n" + "  </Dimension>" + "<Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n" + "      formatString=\"Standard\"/>\n" + "<Measure name=\"Customer Count\" column=\"customer_id\" aggregator=\"distinct-count\"\n" + "      formatString=\"Standard\"/>\n" + "<Measure name=\"Store Sales\" column=\"store_sales\" aggregator=\"sum\"\n" + "      formatString=\"Standard\"/>\n" + "<Measure name=\"Store Cost\" column=\"store_cost\" aggregator=\"sum\"\n" + "      formatString=\"Standard\"/>\n" + "</Cube></Schema>\n";
    final TestContext context = TestContext.instance().withSchema(cube);
    final String mdx = "select \n" + "{ " + "[Promotions].[Media Type].members } on rows, {[Measures].[Unit Sales]} on columns from [Foo]";
    context.assertQueryReturns(mdx, "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n" + "{[Promotions].[Bulk Mail]}\n" + "{[Promotions].[Cash Register Handout]}\n" + "{[Promotions].[Daily Paper]}\n" + "{[Promotions].[Daily Paper, Radio]}\n" + "{[Promotions].[Daily Paper, Radio, TV]}\n" + "{[Promotions].[In-Store Coupon]}\n" + "{[Promotions].[No Media]}\n" + "{[Promotions].[Product Attachment]}\n" + "{[Promotions].[Radio]}\n" + "{[Promotions].[Street Handout]}\n" + "{[Promotions].[Sunday Paper]}\n" + "{[Promotions].[Sunday Paper, Radio]}\n" + "{[Promotions].[Sunday Paper, Radio, TV]}\n" + "{[Promotions].[TV]}\n" + "Row #0: 4,320\n" + "Row #1: 6,697\n" + "Row #2: 7,738\n" + "Row #3: 6,891\n" + "Row #4: 9,513\n" + "Row #5: 3,798\n" + "Row #6: 195,448\n" + "Row #7: 7,544\n" + "Row #8: 2,454\n" + "Row #9: 5,753\n" + "Row #10: 4,339\n" + "Row #11: 5,945\n" + "Row #12: 2,726\n" + "Row #13: 3,607\n");
    final String sqlMysql = "select `promotion`.`media_type` as `c0`, sum(`agg_c_special_sales_fact_1997`.`unit_sales_sum`) as `m0` from `promotion` as `promotion`, `agg_c_special_sales_fact_1997` as `agg_c_special_sales_fact_1997` where `agg_c_special_sales_fact_1997`.`promotion_id` = `promotion`.`promotion_id` group by `promotion`.`media_type`";
    assertQuerySqlOrNot(context, mdx, new SqlPattern[] { new SqlPattern(Dialect.DatabaseProduct.MYSQL, sqlMysql, sqlMysql.length()) }, false, false, true);
}
Also used : TestContext(mondrian.test.TestContext) SqlPattern(mondrian.test.SqlPattern)

Aggregations

SqlPattern (mondrian.test.SqlPattern)107 TestContext (mondrian.test.TestContext)37 Dialect (mondrian.spi.Dialect)8 CellRequest (mondrian.rolap.agg.CellRequest)7 AggStar (mondrian.rolap.aggmatcher.AggStar)3 PrintWriter (java.io.PrintWriter)1 Axis (mondrian.olap.Axis)1 Connection (mondrian.olap.Connection)1 Query (mondrian.olap.Query)1 Result (mondrian.olap.Result)1 RolapAxis (mondrian.rolap.RolapAxis)1 Execution (mondrian.server.Execution)1 Locus (mondrian.server.Locus)1