Search in sources :

Example 16 with RolapConnection

use of mondrian.rolap.RolapConnection in project mondrian by pentaho.

the class BasicQueryTest method executeAndCancelAtSqlFetch.

private Long executeAndCancelAtSqlFetch(final String query, final String triggerSql, final String component) throws Exception {
    // avoid cache to ensure sql executes
    TestContext context = getTestContext().withFreshConnection();
    context.flushSchemaCache();
    RolapConnection conn = (RolapConnection) context.getConnection();
    final mondrian.server.Statement stmt = conn.getInternalStatement();
    // use the logger to block and trigger cancelation at the right time
    Logger sqlLog = RolapUtil.SQL_LOGGER;
    propSaver.set(sqlLog, org.apache.logging.log4j.Level.DEBUG);
    final Execution exec = new Execution(stmt, 50000);
    final CountDownLatch okToGo = new CountDownLatch(1);
    AtomicLong rows = new AtomicLong();
    Appender canceler = new SqlCancelingAppender(component, triggerSql, exec, okToGo, rows);
    stmt.setQuery(conn.parseQuery(query));
    // sqlLog.addAppender( canceler );
    Util.addAppender(canceler, sqlLog, null);
    try {
        conn.execute(exec);
        Assert.fail("Query not canceled.");
    } catch (QueryCanceledException e) {
        // 5 sec just in case it all goes wrong
        if (!okToGo.await(5, TimeUnit.SECONDS)) {
            Assert.fail("Timeout reading sql statement end from log.");
        }
        return rows.longValue();
    } finally {
        // sqlLog.removeAppender( canceler );
        Util.removeAppender(canceler, sqlLog);
        context.close();
    }
    return null;
}
Also used : Appender(org.apache.logging.log4j.core.Appender) AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) RolapConnection(mondrian.rolap.RolapConnection) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryCanceledException(mondrian.olap.QueryCanceledException) Execution(mondrian.server.Execution) Logger(org.apache.logging.log4j.Logger) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 17 with RolapConnection

use of mondrian.rolap.RolapConnection in project mondrian by pentaho.

the class NativeSetEvaluationTest method testNativeSetsCacheClearing.

/**
 * tests if cache associated with Native Sets is flushed.
 *
 * @see <a href="http://jira.pentaho.com/browse/MONDRIAN-2366">Jira issue</a>
 */
public void testNativeSetsCacheClearing() {
    if (MondrianProperties.instance().ReadAggregates.get() && MondrianProperties.instance().UseAggregates.get()) {
        return;
    }
    final String mdx = "select filter( gender.gender.members, measures.[Unit Sales] > 0) on 0 from sales ";
    final String query = "select\n" + "    `customer`.`gender` as `c0`\n" + "from\n" + "    `customer` as `customer`,\n" + "    `sales_fact_1997` as `sales_fact_1997`,\n" + "    `time_by_day` as `time_by_day`\n" + "where\n" + "    `sales_fact_1997`.`customer_id` = `customer`.`customer_id`\n" + "and\n" + "    `sales_fact_1997`.`time_id` = `time_by_day`.`time_id`\n" + "and\n" + "    `time_by_day`.`the_year` = 1997\n" + "group by\n" + "    `customer`.`gender`\n" + "having\n" + "    (sum(`sales_fact_1997`.`unit_sales`) > 0)\n" + "order by\n" + (TestContext.instance().getDialect().requiresOrderByAlias() ? "    ISNULL(`c0`) ASC, `c0` ASC" : "    ISNULL(`customer`.`gender`) ASC, `customer`.`gender` ASC");
    propSaver.set(propSaver.properties.GenerateFormattedSql, true);
    SqlPattern mysqlPattern = new SqlPattern(DatabaseProduct.MYSQL, query, null);
    mondrian.olap.Result rest = executeQuery(mdx);
    RolapCube cube = (RolapCube) rest.getQuery().getCube();
    RolapConnection con = (RolapConnection) rest.getQuery().getConnection();
    CacheControl cacheControl = con.getCacheControl(null);
    for (RolapHierarchy hier : cube.getHierarchies()) {
        if (hier.hasAll()) {
            cacheControl.flush(cacheControl.createMemberSet(hier.getAllMember(), true));
        }
    }
    SqlPattern[] patterns = new SqlPattern[] { mysqlPattern };
    if (propSaver.properties.EnableNativeFilter.get()) {
        assertQuerySqlOrNot(getTestContext(), mdx, patterns, false, false, false);
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) CacheControl(mondrian.olap.CacheControl) RolapCube(mondrian.rolap.RolapCube) Result(mondrian.olap.Result) RolapHierarchy(mondrian.rolap.RolapHierarchy)

Example 18 with RolapConnection

use of mondrian.rolap.RolapConnection in project pentaho-platform by pentaho.

the class OlapServiceImplTest method flushSingleSchemaCache.

@Test
public void flushSingleSchemaCache() throws Exception {
    OlapConnection connection = mock(OlapConnection.class);
    doReturn(connection).when(olapService).getConnection("schemaX", session);
    RolapConnection rc = mock(RolapConnection.class);
    doReturn(rc).when(connection).unwrap(RolapConnection.class);
    doReturn(cacheControl).when(rc).getCacheControl(nullable(PrintWriter.class));
    RolapSchema schema = mock(RolapSchema.class);
    doReturn(schema).when(rc).getSchema();
    olapService.flush(session, "schemaX");
    verify(cacheControl, times(1)).flushSchema(schema);
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) RolapSchema(mondrian.rolap.RolapSchema) OlapConnection(org.olap4j.OlapConnection) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 19 with RolapConnection

use of mondrian.rolap.RolapConnection in project pentaho-platform by pentaho.

the class OlapServiceImpl method flush.

/**
 * Flushes a single schema from the cache.
 */
public void flush(IPentahoSession session, String name) {
    final Lock writeLock = cacheLock.writeLock();
    writeLock.lock();
    try (OlapConnection connection = getConnection(name, session)) {
        final RolapConnection rc = connection.unwrap(RolapConnection.class);
        rc.getCacheControl(null).flushSchema(rc.getSchema());
    } catch (Exception e) {
        LOG.warn(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0019_FAILED_TO_FLUSH", name), e);
        throw new IOlapServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0019_FAILED_TO_FLUSH", name));
    } finally {
        writeLock.unlock();
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) OlapConnection(org.olap4j.OlapConnection) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileSystemException(org.apache.commons.vfs2.FileSystemException) OlapException(org.olap4j.OlapException) SQLException(java.sql.SQLException) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

RolapConnection (mondrian.rolap.RolapConnection)19 Locus (mondrian.server.Locus)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 DataSource (javax.sql.DataSource)3 ArrayList (java.util.ArrayList)2 MondrianException (mondrian.olap.MondrianException)2 Util (mondrian.olap.Util)2 RolapCube (mondrian.rolap.RolapCube)2 RolapSchema (mondrian.rolap.RolapSchema)2 Logger (org.apache.logging.log4j.Logger)2 Appender (org.apache.logging.log4j.core.Appender)2 OlapConnection (org.olap4j.OlapConnection)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1