use of mondrian.server.Execution 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.log4j.Level.DEBUG);
final Execution exec = new Execution(stmt, 50000);
final CountDownLatch okToGo = new CountDownLatch(1);
SqlCancelingAppender canceler = new SqlCancelingAppender(component, triggerSql, exec, okToGo);
stmt.setQuery(conn.parseQuery(query));
sqlLog.addAppender(canceler);
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 canceler.rows;
} finally {
sqlLog.removeAppender(canceler);
context.close();
}
return null;
}
use of mondrian.server.Execution in project mondrian by pentaho.
the class RolapStatisticsCache method getColumnCardinality.
private long getColumnCardinality(String catalog, String schema, String table, String column) {
final List<String> key = Arrays.asList(catalog, schema, table, column);
long rowCount = -1;
if (columnMap.containsKey(key)) {
rowCount = columnMap.get(key);
} else {
final Dialect dialect = star.getSqlQueryDialect();
final List<StatisticsProvider> statisticsProviders = dialect.getStatisticsProviders();
final Execution execution = new Execution(star.getSchema().getInternalConnection().getInternalStatement(), 0);
for (StatisticsProvider statisticsProvider : statisticsProviders) {
rowCount = statisticsProvider.getColumnCardinality(dialect, star.getDataSource(), catalog, schema, table, column, execution);
if (rowCount >= 0) {
break;
}
}
// Note: If all providers fail, we put -1 into the cache, to ensure
// that we won't try again.
columnMap.put(key, rowCount);
}
return rowCount;
}
use of mondrian.server.Execution in project mondrian by pentaho.
the class SqlMemberSource method getMembers.
private List<RolapMember> getMembers(DataSource dataSource) {
Pair<String, List<SqlStatement.Type>> pair = makeKeysSql(dataSource);
final String sql = pair.left;
List<SqlStatement.Type> types = pair.right;
RolapLevel[] levels = (RolapLevel[]) hierarchy.getLevels();
SqlStatement stmt = RolapUtil.executeQuery(dataSource, sql, types, 0, 0, new SqlStatement.StatementLocus(null, "SqlMemberSource.getMembers", "while building member cache", SqlStatementEvent.Purpose.TUPLES, 0), -1, -1, null);
try {
final List<SqlStatement.Accessor> accessors = stmt.getAccessors();
List<RolapMember> list = new ArrayList<RolapMember>();
Map<MemberKey, RolapMember> map = new HashMap<MemberKey, RolapMember>();
RolapMember root = null;
if (hierarchy.hasAll()) {
root = hierarchy.getAllMember();
list.add(root);
}
int limit = MondrianProperties.instance().ResultLimit.get();
ResultSet resultSet = stmt.getResultSet();
Execution execution = Locus.peek().execution;
while (resultSet.next()) {
// Check if the MDX query was canceled.
CancellationChecker.checkCancelOrTimeout(++stmt.rowCount, execution);
if (limit > 0 && limit < stmt.rowCount) {
// result limit exceeded, throw an exception
throw stmt.handle(MondrianResource.instance().MemberFetchLimitExceeded.ex(limit));
}
int column = 0;
RolapMember member = root;
for (RolapLevel level : levels) {
if (level.isAll()) {
continue;
}
Object value = accessors.get(column).get();
if (value == null) {
value = RolapUtil.sqlNullValue;
}
RolapMember parent = member;
MemberKey key = new MemberKey(parent, value);
member = map.get(key);
if (member == null) {
RolapMemberBase memberBase = new RolapMemberBase(parent, level, value);
memberBase.setOrdinal(lastOrdinal++);
member = memberBase;
/*
RME is this right
if (level.getOrdinalExp() != level.getKeyExp()) {
member.setOrdinal(lastOrdinal++);
}
*/
if (value == RolapUtil.sqlNullValue) {
addAsOldestSibling(list, member);
} else {
list.add(member);
}
map.put(key, member);
}
column++;
if (!level.getOrdinalExp().equals(level.getKeyExp())) {
if (assignOrderKeys) {
Object orderKey = accessors.get(column).get();
setOrderKey((RolapMemberBase) member, orderKey);
}
column++;
}
Property[] properties = level.getProperties();
for (Property property : properties) {
// REVIEW emcdermid 9-Jul-2009:
// Should we also look up the value in the
// pool here, rather than setting it directly?
// Presumably the value is already in the pool
// as a result of makeMember().
member.setProperty(property.getName(), accessors.get(column).get());
column++;
}
}
}
return list;
} catch (SQLException e) {
throw stmt.handle(e);
} finally {
stmt.close();
}
}
Aggregations