Search in sources :

Example 86 with TestContext

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

the class FunctionTest method testTopPercentWithAlias.

/**
 * This is a test for
 * <a href="http://jira.pentaho.com/browse/MONDRIAN-2157">MONDRIAN-2157</a>
 * <p/>
 * <p>The results should be equivalent either we use aliases or not</p>
 */
public void testTopPercentWithAlias() {
    final String queryWithoutAlias = "select\n" + " {[Measures].[Store Cost]}on rows,\n" + " TopPercent([Product].[Brand Name].Members*[Time].[1997].children," + " 50, [Measures].[Unit Sales]) on columns\n" + "from Sales";
    String queryWithAlias = "with\n" + " set [*aaa] as '[Product].[Brand Name].Members*[Time].[1997].children'\n" + "select\n" + " {[Measures].[Store Cost]}on rows,\n" + " TopPercent([*aaa], 50, [Measures].[Unit Sales]) on columns\n" + "from Sales";
    final TestContext context = TestContext.instance();
    final Result result = context.executeQuery(queryWithoutAlias);
    context.assertQueryReturns(queryWithAlias, context.toString(result));
}
Also used : TestContext(mondrian.test.TestContext)

Example 87 with TestContext

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

the class QueryTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    TestContext testContext = getTestContext();
    ConnectionBase connection = (ConnectionBase) testContext.getConnection();
    final Statement statement = connection.getInternalStatement();
    try {
        queryWithCellProps = new Query(statement, formulas, axes, "Sales", null, cellProps, false);
        queryWithoutCellProps = new Query(statement, formulas, axes, "Sales", null, new QueryPart[0], false);
    } finally {
        statement.close();
    }
}
Also used : Statement(mondrian.server.Statement) TestContext(mondrian.test.TestContext)

Example 88 with TestContext

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

the class SqlConstraintUtilsTest method testReplaceCompoundSlicerPlaceholder.

public void testReplaceCompoundSlicerPlaceholder() {
    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();
    // tested call
    Member r = SqlConstraintUtils.replaceCompoundSlicerPlaceholder(placeHolderMember, rolapEvaluator);
    // test
    Assert.assertSame(expectedMember, r);
}
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 89 with TestContext

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

the class TestAggregationManager method testAggNameApproxRowCount.

/**
 * This is a test for MONDRIAN-918 and MONDRIAN-903. We have added
 * an attribute to AggName called approxRowCount so that the
 * aggregation manager can optimize the aggregation tables without
 * having to issue a select count() query.
 */
public void testAggNameApproxRowCount() {
    propSaver.set(MondrianProperties.instance().UseAggregates, true);
    propSaver.set(MondrianProperties.instance().ReadAggregates, true);
    final TestContext context = TestContext.instance().withSchema("<schema name=\"FooSchema\"><Cube name=\"Sales_Foo\" defaultMeasure=\"Unit Sales\">\n" + "  <Table name=\"sales_fact_1997\">\n" + " <AggName name=\"agg_pl_01_sales_fact_1997\" approxRowCount=\"86000\">\n" + "     <AggFactCount column=\"FACT_COUNT\"/>\n" + "     <AggForeignKey factColumn=\"product_id\" aggColumn=\"PRODUCT_ID\" />\n" + "     <AggForeignKey factColumn=\"customer_id\" aggColumn=\"CUSTOMER_ID\" />\n" + "     <AggForeignKey factColumn=\"time_id\" aggColumn=\"TIME_ID\" />\n" + "     <AggMeasure name=\"[Measures].[Unit Sales]\" column=\"UNIT_SALES_SUM\" />\n" + "     <AggMeasure name=\"[Measures].[Store Cost]\" column=\"STORE_COST_SUM\" />\n" + "     <AggMeasure name=\"[Measures].[Store Sales]\" column=\"STORE_SALES_SUM\" />\n" + " </AggName>\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" + "  </Table>\n" + "<Dimension name=\"Time\" type=\"TimeDimension\" foreignKey=\"time_id\">\n" + "    <Hierarchy hasAll=\"true\" name=\"Weekly\" 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=\"Week\" column=\"week_of_year\" type=\"Numeric\" uniqueMembers=\"false\"\n" + "          levelType=\"TimeWeeks\"/>\n" + "      <Level name=\"Day\" column=\"day_of_month\" uniqueMembers=\"false\" type=\"Numeric\"\n" + "          levelType=\"TimeDays\"/>\n" + "    </Hierarchy>\n" + "</Dimension>\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\" 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=\"Customers\" foreignKey=\"customer_id\">\n" + "    <Hierarchy hasAll=\"true\" allMemberName=\"All Customers\" primaryKey=\"customer_id\">\n" + "      <Table name=\"customer\"/>\n" + "      <Level name=\"Country\" column=\"country\" uniqueMembers=\"true\"/>\n" + "      <Level name=\"State Province\" column=\"state_province\" uniqueMembers=\"true\"/>\n" + "      <Level name=\"City\" column=\"city\" uniqueMembers=\"false\"/>\n" + "      <Level name=\"Name\" column=\"customer_id\" type=\"Numeric\" uniqueMembers=\"true\">\n" + "        <NameExpression>\n" + "          <SQL dialect=\"oracle\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"hive\">\n" + "`customer`.`fullname`\n" + "          </SQL>\n" + "          <SQL dialect=\"hsqldb\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"access\">\n" + "fname + ' ' + lname\n" + "          </SQL>\n" + "          <SQL dialect=\"postgres\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"mysql\">\n" + "CONCAT(`customer`.`fname`, ' ', `customer`.`lname`)\n" + "          </SQL>\n" + "          <SQL dialect=\"mssql\">\n" + "fname + ' ' + lname\n" + "          </SQL>\n" + "          <SQL dialect=\"derby\">\n" + "\"customer\".\"fullname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"db2\">\n" + "CONCAT(CONCAT(\"customer\".\"fname\", ' '), \"customer\".\"lname\")\n" + "          </SQL>\n" + "          <SQL dialect=\"luciddb\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"neoview\">\n" + "\"customer\".\"fullname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"teradata\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"generic\">\n" + "fullname\n" + "          </SQL>\n" + "        </NameExpression>\n" + "        <OrdinalExpression>\n" + "          <SQL dialect=\"oracle\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"hsqldb\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"access\">\n" + "fname + ' ' + lname\n" + "          </SQL>\n" + "          <SQL dialect=\"postgres\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"mysql\">\n" + "CONCAT(`customer`.`fname`, ' ', `customer`.`lname`)\n" + "          </SQL>\n" + "          <SQL dialect=\"mssql\">\n" + "fname + ' ' + lname\n" + "          </SQL>\n" + "          <SQL dialect=\"neoview\">\n" + "\"customer\".\"fullname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"derby\">\n" + "\"customer\".\"fullname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"db2\">\n" + "CONCAT(CONCAT(\"customer\".\"fname\", ' '), \"customer\".\"lname\")\n" + "          </SQL>\n" + "          <SQL dialect=\"luciddb\">\n" + "\"fname\" || ' ' || \"lname\"\n" + "          </SQL>\n" + "          <SQL dialect=\"generic\">\n" + "fullname\n" + "          </SQL>\n" + "        </OrdinalExpression>\n" + "        <Property name=\"Gender\" column=\"gender\"/>\n" + "        <Property name=\"Marital Status\" column=\"marital_status\"/>\n" + "        <Property name=\"Education\" column=\"education\"/>\n" + "        <Property name=\"Yearly Income\" column=\"yearly_income\"/>\n" + "      </Level>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "  <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n" + "      formatString=\"Standard\"/>\n" + "  <Measure name=\"Store Cost\" column=\"store_cost\" aggregator=\"sum\"\n" + "      formatString=\"#,###.00\"/>\n" + "  <Measure name=\"Store Sales\" column=\"store_sales\" aggregator=\"sum\"\n" + "      formatString=\"#,###.00\"/>\n" + "  <Measure name=\"Sales Count\" column=\"product_id\" aggregator=\"count\"\n" + "      formatString=\"#,###\"/>\n" + "  <Measure name=\"Customer Count\" column=\"customer_id\"\n" + "      aggregator=\"distinct-count\" formatString=\"#,###\"/>\n" + "</Cube></schema>\n");
    final String mdxQuery = "select {[Measures].[Unit Sales]} on columns, " + "non empty CrossJoin({[Time.Weekly].[1997].[1].[15]},CrossJoin({[Customers].[USA].[CA].[Lincoln Acres].[William Smith]}, {[Product].[Drink].[Beverages].[Carbonated Beverages].[Soda].[Washington].[Washington Diet Cola]})) on rows " + "from [Sales_Foo] ";
    final String sqlOracle = "select count(*) as \"c0\" from \"agg_pl_01_sales_fact_1997\" \"agg_pl_01_sales_fact_1997\"";
    final String sqlMysql = "select count(*) as `c0` from `agg_pl_01_sales_fact_1997` as `agg_pl_01_sales_fact_1997`";
    // If the approxRowcount is used, there should not be
    // a query like : select count(*) from agg_pl_01_sales_fact_1997
    assertQuerySqlOrNot(context, mdxQuery, new SqlPattern[] { new SqlPattern(Dialect.DatabaseProduct.ORACLE, sqlOracle, sqlOracle.length()), new SqlPattern(Dialect.DatabaseProduct.MYSQL, sqlMysql, sqlMysql.length()) }, true, false, false);
}
Also used : TestContext(mondrian.test.TestContext) SqlPattern(mondrian.test.SqlPattern)

Example 90 with TestContext

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

the class TestAggregationManager method testNonCollapsedAggregateAllLevelsPresentInQuerySnowflake.

public void testNonCollapsedAggregateAllLevelsPresentInQuerySnowflake() 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=\"product_id\" aggColumn=\"product_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=\"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\"/>" + "    </Hierarchy>\n" + "  </Dimension>\n" + "<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" + "{ " + "[Product].[Product Family].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" + "{[Product].[Drink]}\n" + "{[Product].[Food]}\n" + "{[Product].[Non-Consumable]}\n" + "Row #0: 24,597\n" + "Row #1: 191,940\n" + "Row #2: 50,236\n");
    final String sqlMysql = "select `product_class`.`product_family` as `c0`, sum(`agg_l_05_sales_fact_1997`.`unit_sales`) as `m0` from `product_class` as `product_class`, `product` as `product`, `agg_l_05_sales_fact_1997` as `agg_l_05_sales_fact_1997` where `agg_l_05_sales_fact_1997`.`product_id` = `product`.`product_id` and `product`.`product_class_id` = `product_class`.`product_class_id` group by `product_class`.`product_family`";
    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

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