Search in sources :

Example 11 with TestContext

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

the class TestAggregationManager method testAggStarWithIgnoredColumnsRequiresRollup.

public void testAggStarWithIgnoredColumnsRequiresRollup() {
    propSaver.set(propSaver.properties.GenerateFormattedSql, true);
    propSaver.set(propSaver.properties.ReadAggregates, true);
    propSaver.set(propSaver.properties.UseAggregates, true);
    final TestContext context = TestContext.instance().withSchema("<Schema name=\"FoodMart\">" + "  <Dimension name=\"Time\" type=\"TimeDimension\">\n" + "    <Hierarchy hasAll=\"false\" primaryKey=\"time_id\">\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" + "    </Hierarchy>\n" + "  </Dimension>\n" + "<Cube name=\"Sales\" defaultMeasure=\"Unit Sales\">\n" + "  <Table name=\"sales_fact_1997\">\n" + "    <AggExclude name=\"agg_c_special_sales_fact_1997\" />\n" + "    <AggExclude name=\"agg_lc_100_sales_fact_1997\" />\n" + "    <AggExclude name=\"agg_lc_10_sales_fact_1997\" />\n" + "    <AggExclude name=\"agg_pc_10_sales_fact_1997\" />\n" + "    <AggName name=\"agg_c_10_sales_fact_1997\">\n" + "        <AggFactCount column=\"FACT_COUNT\"/>\n" + "        <AggIgnoreColumn column=\"Quarter\"/>\n" + "        <AggIgnoreColumn column=\"MONTH_OF_YEAR\"/>\n" + "        <AggMeasure name=\"[Measures].[Unit Sales]\" column=\"unit_sales\" />\n" + "        <AggLevel name=\"[Time].[Year]\" column=\"the_year\" />\n" + "    </AggName>\n" + "  </Table>\n" + "  <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\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_10_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("Columns marked with AggIgnoreColumn, so AggStar " + ".hasIgnoredColumns() should be true", aggStarSpy.hasIgnoredColumns());
    String sqlMysql = "select\n" + "    `agg_c_10_sales_fact_1997`.`the_year` as `c0`,\n" + "    sum(`agg_c_10_sales_fact_1997`.`unit_sales`) as `m0`\n" + "from\n" + "    `agg_c_10_sales_fact_1997` as `agg_c_10_sales_fact_1997`\n" + "where\n" + "    `agg_c_10_sales_fact_1997`.`the_year` = 1997\n" + "group by\n" + "    `agg_c_10_sales_fact_1997`.`the_year`";
    String sqlOra = "select\n" + "    \"agg_c_10_sales_fact_1997\".\"the_year\" as \"c0\",\n" + "    sum(\"agg_c_10_sales_fact_1997\".\"unit_sales\") as \"m0\"\n" + "from\n" + "    \"agg_c_10_sales_fact_1997\" \"agg_c_10_sales_fact_1997\"\n" + "where\n" + "    \"agg_c_10_sales_fact_1997\".\"the_year\" = 1997\n" + "group by\n" + "    \"agg_c_10_sales_fact_1997\".\"the_year\"";
    assertQuerySqlOrNot(context, "select Time.[1997] 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)

Example 12 with TestContext

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

the class TopCountWithTwoParamsVersusHeadTest method assertResultsAreEqual.

private void assertResultsAreEqual(String testCase, String topCountQuery) {
    if (!topCountQuery.contains("TOPCOUNT")) {
        throw new IllegalArgumentException("'TOPCOUNT' was not found. Please ensure you are using upper case:\n\t\t" + topCountQuery);
    }
    String headQuery = topCountQuery.replace("TOPCOUNT", "HEAD");
    TestContext ctx = getTestContext();
    Result topCountResult = ctx.executeQuery(topCountQuery);
    ctx.flushSchemaCache();
    Result headResult = ctx.executeQuery(headQuery);
    assertEquals(String.format("[%s]: TOPCOUNT() and HEAD() results of the query differ. The query:\n\t\t%s", testCase, topCountQuery), TestContext.toString(topCountResult), TestContext.toString(headResult));
}
Also used : TestContext(mondrian.test.TestContext) Result(mondrian.olap.Result)

Example 13 with TestContext

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

the class VirtualCubeTest method testVirtualCubeRecursiveMember.

/**
 * <p>MONDRIAN-1061</p>
 * <p>The idea is that [recurse] is a calculated member uses
 * <br>
 * <code>CoalesceEmpty((Measures.[Unit Sales], [Time].CurrentMember ) ,
 * (Measures.[recurse],[Time].CurrentMember.PrevMember)))</code>
 * <br>
 *  ...calculation.
 * Food mart have no data for 1998 quarter,
 * So this way we expect:
 * <ul>
 * <li>not to fall into StackOverflow for recursive calculation when member
 * is referenced in VirtualCube.
 * <li>check that CoalesceEmpty calculated correctly (repeatable values from
 * previous not null result)
 * </ul></p>
 */
public void testVirtualCubeRecursiveMember() {
    final String schema = "<Schema name=\"FoodMart\">" + "<Dimension type=\"TimeDimension\" highCardinality=\"false\" name=\"Time\">" + "<Hierarchy visible=\"true\" hasAll=\"false\" primaryKey=\"time_id\">" + "<Table name=\"time_by_day\">" + "</Table>" + "<Level name=\"Year\" column=\"the_year\" type=\"Numeric\" uniqueMembers=\"true\" levelType=\"TimeYears\">" + "</Level>" + "<Level name=\"Quarter\" column=\"quarter\" type=\"String\" uniqueMembers=\"false\" levelType=\"TimeQuarters\">" + "</Level>" + "</Hierarchy>" + "</Dimension>" + "<Cube name=\"Sales\" visible=\"true\" defaultMeasure=\"Unit Sales\" >" + "<Table name=\"sales_fact_1997\">" + "<AggName name=\"agg_c_special_sales_fact_1997\">" + "<AggFactCount column=\"FACT_COUNT\">" + "</AggFactCount>" + "<AggMeasure column=\"UNIT_SALES_SUM\" name=\"[Measures].[Unit Sales]\">" + "</AggMeasure>" + "<AggLevel column=\"TIME_YEAR\" name=\"[Time].[Year]\">" + "</AggLevel>" + "</AggName>" + "</Table>" + "<DimensionUsage source=\"Time\" name=\"Time\" foreignKey=\"time_id\" highCardinality=\"false\">" + "</DimensionUsage>" + "<Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\">" + "</Measure>" + "<CalculatedMember name=\"recurse\" dimension=\"Measures\" visible=\"true\">" + "<Formula>" + "<![CDATA[(CoalesceEmpty((Measures.[Unit Sales], [Time].CurrentMember ) ," + "(Measures.[recurse],[Time].CurrentMember.PrevMember)))]]>" + "</Formula>" + "</CalculatedMember>" + "</Cube>" + "<VirtualCube enabled=\"true\" name=\"Warehouse and Sales\" defaultMeasure=\"Store Sales\" visible=\"true\">" + "<VirtualCubeDimension visible=\"true\" highCardinality=\"false\" name=\"Time\">" + "</VirtualCubeDimension>" + "<VirtualCubeMeasure cubeName=\"Sales\" name=\"[Measures].[recurse]\" visible=\"true\">" + "</VirtualCubeMeasure>" + "</VirtualCube>" + "</Schema>";
    TestContext context = getTestContext().withSchema(schema);
    final String query = "SELECT {[Time].[1998].Children} on columns," + " {[recurse]} on rows " + "FROM [Warehouse and Sales]";
    final String expected = "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Time].[1998].[Q1]}\n" + "{[Time].[1998].[Q2]}\n" + "{[Time].[1998].[Q3]}\n" + "{[Time].[1998].[Q4]}\n" + "Axis #2:\n" + "{[Measures].[recurse]}\n" + "Row #0: 72,024\n" + "Row #0: 72,024\n" + "Row #0: 72,024\n" + "Row #0: 72,024\n";
    context.assertQueryReturns(query, expected);
}
Also used : TestContext(mondrian.test.TestContext)

Example 14 with TestContext

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

the class VirtualCubeTest method testNoTimeDimension.

/**
 * Test case for bug <a href="http://jira.pentaho.com/browse/MONDRIAN-163">
 * MONDRIAN-163, "VirtualCube SegmentArrayQuerySpec.addMeasure assert"</a>.
 */
public void testNoTimeDimension() {
    TestContext testContext = TestContext.instance().create(null, null, "<VirtualCube name=\"Sales vs Warehouse\">\n" + "<VirtualCubeDimension name=\"Product\"/>\n" + "<VirtualCubeMeasure cubeName=\"Warehouse\" name=\"[Measures].[Warehouse Sales]\"/>\n" + "<VirtualCubeMeasure cubeName=\"Sales\" name=\"[Measures].[Unit Sales]\"/>\n" + "</VirtualCube>", null, null, null);
    checkXxx(testContext);
}
Also used : TestContext(mondrian.test.TestContext)

Example 15 with TestContext

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

the class VirtualCubeTest method testVirtualCubeMeasureCaption.

/**
 * Test case for bug <a href="http://jira.pentaho.com/browse/MONDRIAN-352">
 * MONDRIAN-352, "Caption is not set on RolapVirtualCubeMesure"</a>.
 */
public void testVirtualCubeMeasureCaption() {
    TestContext testContext = TestContext.instance().create(null, "<Cube name=\"TestStore\">\n" + "  <Table name=\"store\"/>\n" + "  <Dimension name=\"HCB\" caption=\"Has coffee bar caption\">\n" + "    <Hierarchy hasAll=\"true\">\n" + "      <Level name=\"Has coffee bar\" column=\"coffee_bar\" uniqueMembers=\"true\"\n" + "          type=\"Boolean\"/>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "  <Measure name=\"Store Sqft\" caption=\"Store Sqft Caption\" column=\"store_sqft\" aggregator=\"sum\" formatString=\"#,###\"/>\n" + "</Cube>\n", "<VirtualCube name=\"VirtualTestStore\">\n" + "  <VirtualCubeDimension cubeName=\"TestStore\" name=\"HCB\"/>\n" + "  <VirtualCubeMeasure   cubeName=\"TestStore\" name=\"[Measures].[Store Sqft]\"/>\n" + "</VirtualCube>", null, null, null);
    Result result = testContext.executeQuery("select {[Measures].[Store Sqft]} ON COLUMNS," + "{[HCB]} ON ROWS " + "from [VirtualTestStore]");
    Axis[] axes = result.getAxes();
    List<Position> positions = axes[0].getPositions();
    Member m0 = positions.get(0).get(0);
    String caption = m0.getCaption();
    assertEquals("Store Sqft Caption", caption);
}
Also used : Position(mondrian.olap.Position) TestContext(mondrian.test.TestContext) Member(mondrian.olap.Member) Axis(mondrian.olap.Axis) Result(mondrian.olap.Result)

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