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;
}
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);
}
}
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);
}
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();
}
}
Aggregations