Search in sources :

Example 21 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class BatchTestCase method getMeasure.

protected RolapStar.Measure getMeasure(String cube, String measureName) {
    final Connection connection = getFoodMartConnection();
    final boolean fail = true;
    Cube salesCube = connection.getSchema().lookupCube(cube, fail);
    Member measure = salesCube.getSchemaReader(null).getMemberByUniqueName(Util.parseIdentifier(measureName), fail);
    return RolapStar.getStarMeasure(measure);
}
Also used : Cube(mondrian.olap.Cube) Connection(mondrian.olap.Connection) Member(mondrian.olap.Member)

Example 22 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class BasicQueryTest method testUnparse.

public void testUnparse() {
    Connection connection = getConnection();
    Query query = connection.parseQuery("with member [Measures].[Rendite] as \n" + " '(([Measures].[Store Sales] - [Measures].[Store Cost])) / [Measures].[Store Cost]',\n" + " format_string = iif(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost] * 100 > \n" + "     Parameter (\"UpperLimit\", NUMERIC, 151, \"Obere Grenze\"), \n" + "   \"|#.00%|arrow='up'\",\n" + "   iif(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost] * 100 < \n" + "       Parameter(\"LowerLimit\", NUMERIC, 150, \"Untere Grenze\"),\n" + "     \"|#.00%|arrow='down'\",\n" + "     \"|#.00%|arrow='right'\"))\n" + "select {[Measures].members} on columns\n" + "from Sales");
    final String s = Util.unparse(query);
    // Parentheses are added to reflect operator precedence, but that's ok.
    // Note that the doubled parentheses in line #2 of the query have been
    // reduced to a single level.
    TestContext.assertEqualsVerbose("with member [Measures].[Rendite] as '(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost])', " + "format_string = IIf((((([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost]) * 100) > Parameter(\"UpperLimit\", NUMERIC, 151, \"Obere Grenze\")), " + "\"|#.00%|arrow='up'\", " + "IIf((((([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost]) * 100) < Parameter(\"LowerLimit\", NUMERIC, 150, \"Untere Grenze\")), " + "\"|#.00%|arrow='down'\", \"|#.00%|arrow='right'\"))\n" + "select {[Measures].Members} ON COLUMNS\n" + "from [Sales]\n", s);
}
Also used : Connection(mondrian.olap.Connection) RolapConnection(mondrian.rolap.RolapConnection)

Example 23 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class BasicQueryTest method runMondrian1506.

private void runMondrian1506(Mondrian1506Lambda lambda) throws Exception {
    if (getTestContext().getDialect().getDatabaseProduct() != Dialect.DatabaseProduct.MYSQL) {
        // This only works on MySQL because of Sleep()
        return;
    }
    final TestContext context = getTestContext().withSchema("<Schema name=\"Foo\">\n" + "  <Cube name=\"Bar\">\n" + "    <Table name=\"warehouse\">\n" + "      <SQL>sleep(0.1) = 0</SQL>\n" + "    </Table>   \n" + " <Dimension name=\"Dim\">\n" + "   <Hierarchy hasAll=\"true\">\n" + "     <Level name=\"Level\" column=\"warehouse_id\"/>\n" + "      </Hierarchy>\n" + " </Dimension>\n" + " <Measure name=\"Measure\" aggregator=\"sum\">\n" + "   <MeasureExpression>\n" + "     <SQL>1</SQL>\n" + "   </MeasureExpression>\n" + " </Measure>\n" + "  </Cube>\n" + "</Schema>\n");
    final String mdx = "select {[Measures].[Measure]} on columns from [Bar]";
    // A service to execute stuff in the background.
    final ExecutorService exec = Util.getExecutorService(2, 2, 1000, "BasicQueryTest.testMondrian1506", new RejectedExecutionHandler() {

        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            throw new RuntimeException();
        }
    });
    // We are testing the old Query API.
    final Connection connection = context.getConnection();
    final Query q1 = connection.parseQuery(mdx);
    final Query q2 = connection.parseQuery(mdx);
    // Some flags to test.
    final AtomicBoolean fail = new AtomicBoolean(false);
    final AtomicBoolean success = new AtomicBoolean(false);
    final Runnable r1 = new Runnable() {

        public void run() {
            try {
                connection.execute(q1);
            } catch (Throwable t) {
                fail.set(true);
            }
        }
    };
    final Runnable r2 = new Runnable() {

        public void run() {
            try {
                connection.execute(q2);
                success.set(true);
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    };
    try {
        lambda.run(exec, q1, fail, success, r1, r2);
    } finally {
        exec.shutdownNow();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Connection(mondrian.olap.Connection) RolapConnection(mondrian.rolap.RolapConnection)

Example 24 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class BasicQueryTest method testMembersOfLargeDimensionTheHardWay.

public void testMembersOfLargeDimensionTheHardWay() {
    // Avoid this test if memory is scarce.
    if (Bug.avoidMemoryOverflow(TestContext.instance().getDialect())) {
        return;
    }
    final Connection connection = TestContext.instance().getConnection();
    String queryString = "select {[Measures].[Unit Sales]} on columns,\n" + "{[Customers].members} on rows\n" + "from Sales";
    Query query = connection.parseQuery(queryString);
    Result result = connection.execute(query);
    assertEquals(10407, result.getAxes()[1].getPositions().size());
}
Also used : Connection(mondrian.olap.Connection) RolapConnection(mondrian.rolap.RolapConnection)

Example 25 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class BasicQueryTest method testUnparse2.

public void testUnparse2() {
    Connection connection = getConnection();
    Query query = connection.parseQuery("with member [Measures].[Foo] as '1', " + "format_string='##0.00', " + "funny=IIf(1=1,\"x\"\"y\",\"foo\") " + "select {[Measures].[Foo]} on columns from Sales");
    final String s = query.toString();
    // The "format_string" property, a string literal, is now delimited by
    // double-quotes. This won't work in MSOLAP, but for Mondrian it's
    // consistent with the fact that property values are expressions,
    // not enclosed in single-quotes.
    TestContext.assertEqualsVerbose("with member [Measures].[Foo] as '1', " + "format_string = \"##0.00\", " + "funny = IIf((1 = 1), \"x\"\"y\", \"foo\")\n" + "select {[Measures].[Foo]} ON COLUMNS\n" + "from [Sales]\n", s);
}
Also used : Connection(mondrian.olap.Connection) RolapConnection(mondrian.rolap.RolapConnection)

Aggregations

Connection (mondrian.olap.Connection)38 RolapConnection (mondrian.rolap.RolapConnection)8 Util (mondrian.olap.Util)5 MondrianException (mondrian.olap.MondrianException)4 Result (mondrian.olap.Result)4 Member (mondrian.olap.Member)3 Query (mondrian.olap.Query)3 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)3 MemberExpr (mondrian.mdx.MemberExpr)2 Cube (mondrian.olap.Cube)2 QueryAxis (mondrian.olap.QueryAxis)2 TestMember (mondrian.olap.fun.TestMember)2 Execution (mondrian.server.Execution)2 FoodMartTestCase (mondrian.test.FoodMartTestCase)2 TestContext (mondrian.test.TestContext)2 OlapConnection (org.olap4j.OlapConnection)2 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)2 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)2 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1