Search in sources :

Example 6 with TestContext

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

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMembers2.

// test with a placeholder member
public void testExpandSupportedCalculatedMembers2() {
    final TestContext testContext = TestContext.instance();
    final Connection connection = testContext.getConnection();
    final String queryText = "SELECT {[Measures].[Customer Count]} ON 0 " + "FROM [Sales] " + "WHERE [Time].[1997]";
    final Query query = connection.parseQuery(queryText);
    final QueryAxis querySlicerAxis = query.getSlicerAxis();
    final Member slicerMember = ((MemberExpr) querySlicerAxis.getSet()).getMember();
    final RolapHierarchy slicerHierarchy = ((RolapCube) query.getCube()).getTimeHierarchy(null);
    final Execution execution = new Execution(query.getStatement(), 0L);
    final RolapEvaluatorRoot rolapEvaluatorRoot = new RolapEvaluatorRoot(execution);
    final RolapEvaluator rolapEvaluator = new RolapEvaluator(rolapEvaluatorRoot);
    final Member expectedMember = slicerMember;
    rolapEvaluator.setSlicerContext(expectedMember);
    RolapResult.CompoundSlicerRolapMember placeHolderMember = Mockito.mock(RolapResult.CompoundSlicerRolapMember.class);
    Mockito.doReturn(slicerHierarchy).when(placeHolderMember).getHierarchy();
    Member endMember0 = makeNoncalculatedMember("0");
    // (0, placeholder)
    Member[] argMembers = new Member[] { endMember0, placeHolderMember };
    Member[] expectedMembers = new Member[] { endMember0, slicerMember };
    Member[] expectedMembersOnDisjoin = new Member[] { endMember0 };
    assertApartExpandSupportedCalculatedMembers("(0, placeholder)", expectedMembers, expectedMembersOnDisjoin, argMembers, rolapEvaluator);
}
Also used : Query(mondrian.olap.Query) TestContext(mondrian.test.TestContext) Connection(mondrian.olap.Connection) Execution(mondrian.server.Execution) MemberExpr(mondrian.mdx.MemberExpr) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember) QueryAxis(mondrian.olap.QueryAxis)

Example 7 with TestContext

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

the class TestAggregationManager method testNoNullPtrInCellRequest.

/**
 * This test case tests for a null pointer that was being thrown
 * inside of CellRequest.
 */
public void testNoNullPtrInCellRequest() {
    TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", "<Dimension name=\"Store2\" foreignKey=\"store_id\">\n" + "  <Hierarchy hasAll=\"true\" primaryKey=\"store_id\" allMemberName=\"All Stores\">" + "    <Table name=\"store\"/>\n" + "    <Level name=\"Store Country\" column=\"store_country\" uniqueMembers=\"true\"/>\n" + "    <Level name=\"Store State\"   column=\"store_state\"   uniqueMembers=\"true\"/>\n" + "    <Level name=\"Store City\"    column=\"store_city\"    uniqueMembers=\"false\"/>\n" + "    <Level name=\"Store Type\"    column=\"store_type\"    uniqueMembers=\"false\"/>\n" + "    <Level name=\"Store Name\"    column=\"store_name\"    uniqueMembers=\"true\"/>\n" + "  </Hierarchy>\n" + "</Dimension>");
    testContext.assertQueryReturns("select {[Measures].[Unit Sales]} on columns, " + "Filter ({ " + "[Store2].[All Stores].[USA].[CA].[Beverly Hills], " + "[Store2].[All Stores].[USA].[CA].[Beverly Hills].[Gourmet Supermarket] " + "},[Measures].[Unit Sales] > 0) on rows " + "from [Sales] " + "where [Store Type].[Store Type].[Small Grocery]", "Axis #0:\n" + "{[Store Type].[Small Grocery]}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n");
}
Also used : TestContext(mondrian.test.TestContext)

Example 8 with TestContext

use of mondrian.test.TestContext 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 9 with TestContext

use of mondrian.test.TestContext 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)

Example 10 with TestContext

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

the class TestAggregationManager method testAggStarWithUnusedColumnsRequiresRollup.

public void testAggStarWithUnusedColumnsRequiresRollup() {
    propSaver.set(propSaver.properties.ReadAggregates, true);
    propSaver.set(propSaver.properties.UseAggregates, true);
    propSaver.set(propSaver.properties.GenerateFormattedSql, true);
    final TestContext context = TestContext.instance().withSchema("<Schema name=\"FoodMart\">" + "<Cube name=\"Sales\" defaultMeasure=\"Unit Sales\">\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>\n" + "  <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n" + "      formatString=\"Standard\"/>\n" + "</Cube>\n" + "</Schema>");
    RolapStar star = context.getConnection().getSchemaReader().getSchema().getStar("sales_fact_1997");
    AggStar aggStarSpy = spy(getAggStar(star, "agg_c_special_sales_fact_1997"));
    // make sure the test AggStar will be prioritized first
    when(aggStarSpy.getSize()).thenReturn(0l);
    context.getConnection().getSchemaReader().getSchema().getStar("sales_fact_1997").addAggStar(aggStarSpy);
    boolean[] rollup = { false };
    AggStar returnedStar = AggregationManager.findAgg(star, aggStarSpy.getLevelBitKey(), aggStarSpy.getMeasureBitKey(), rollup);
    assertTrue("Rollup should be true since AggStar has ignored columns ", rollup[0]);
    assertEquals(aggStarSpy, returnedStar);
    assertTrue("Unused columns are present, should be marked as " + "having ignored columns.", aggStarSpy.hasIgnoredColumns());
    String sqlOra = "select\n" + "    \"customer\".\"gender\" as \"c0\",\n" + "    sum(\"agg_c_special_sales_fact_1997\".\"unit_sales_sum\") as \"m0\"\n" + "from\n" + "    \"customer\" \"customer\",\n" + "    \"agg_c_special_sales_fact_1997\" \"agg_c_special_sales_fact_1997\"\n" + "where\n" + "    \"agg_c_special_sales_fact_1997\".\"customer_id\" = \"customer\".\"customer_id\"\n" + "group by\n" + "    \"customer\".\"gender\"";
    String sqlMysql = "select\n" + "    `customer`.`gender` as `c0`,\n" + "    sum(`agg_c_special_sales_fact_1997`.`unit_sales_sum`) as `m0`\n" + "from\n" + "    `customer` as `customer`,\n" + "    `agg_c_special_sales_fact_1997` as `agg_c_special_sales_fact_1997`\n" + "where\n" + "    `agg_c_special_sales_fact_1997`.`customer_id` = `customer`.`customer_id`\n" + "group by\n" + "    `customer`.`gender`";
    assertQuerySqlOrNot(context, "select gender.gender.members on 0 from sales", new SqlPattern[] { new SqlPattern(Dialect.DatabaseProduct.MYSQL, sqlMysql, sqlMysql.length()), new SqlPattern(Dialect.DatabaseProduct.ORACLE, sqlOra, sqlOra.length()) }, false, false, true);
}
Also used : TestContext(mondrian.test.TestContext) SqlPattern(mondrian.test.SqlPattern) AggStar(mondrian.rolap.aggmatcher.AggStar)

Aggregations

TestContext (mondrian.test.TestContext)167 SqlPattern (mondrian.test.SqlPattern)37 Result (mondrian.olap.Result)4 Member (mondrian.olap.Member)3 AggStar (mondrian.rolap.aggmatcher.AggStar)3 MemberExpr (mondrian.mdx.MemberExpr)2 Connection (mondrian.olap.Connection)2 Query (mondrian.olap.Query)2 QueryAxis (mondrian.olap.QueryAxis)2 TestMember (mondrian.olap.fun.TestMember)2 Execution (mondrian.server.Execution)2 Dialect (mondrian.spi.Dialect)2 SoftReference (java.lang.ref.SoftReference)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 mondrian.olap (mondrian.olap)1 Axis (mondrian.olap.Axis)1 MondrianException (mondrian.olap.MondrianException)1 Position (mondrian.olap.Position)1