use of mondrian.spi.StatisticsProvider in project mondrian by pentaho.
the class JdbcDialectImpl method computeStatisticsProviders.
protected List<StatisticsProvider> computeStatisticsProviders() {
List<String> names = getStatisticsProviderNames();
if (names == null) {
return Collections.<StatisticsProvider>singletonList(new SqlStatisticsProvider());
}
final List<StatisticsProvider> providerList = new ArrayList<StatisticsProvider>();
for (String name : names) {
try {
StatisticsProvider provider = ClassResolver.INSTANCE.instantiateSafe(name);
providerList.add(provider);
} catch (Exception e) {
LOGGER.info("Error instantiating statistics provider (class=" + name + ")", e);
}
}
return providerList;
}
use of mondrian.spi.StatisticsProvider in project mondrian by pentaho.
the class RolapStatisticsCache method getQueryCardinality.
private long getQueryCardinality(String sql) {
long rowCount = -1;
if (queryMap.containsKey(sql)) {
rowCount = queryMap.get(sql);
} 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.getQueryCardinality(dialect, star.getDataSource(), sql, execution);
if (rowCount >= 0) {
break;
}
}
// Note: If all providers fail, we put -1 into the cache, to ensure
// that we won't try again.
queryMap.put(sql, rowCount);
}
return rowCount;
}
use of mondrian.spi.StatisticsProvider in project mondrian by pentaho.
the class RolapStatisticsCache method getTableCardinality.
private long getTableCardinality(String catalog, String schema, String table) {
final List<String> key = Arrays.asList(catalog, schema, table);
long rowCount = -1;
if (tableMap.containsKey(key)) {
rowCount = tableMap.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.getTableCardinality(dialect, star.getDataSource(), catalog, schema, table, execution);
if (rowCount >= 0) {
break;
}
}
// Note: If all providers fail, we put -1 into the cache, to ensure
// that we won't try again.
tableMap.put(key, rowCount);
}
return rowCount;
}
use of mondrian.spi.StatisticsProvider in project mondrian by pentaho.
the class BasicQueryTest method testStatistics.
/**
* Unit test for {@link StatisticsProvider} and implementations {@link JdbcStatisticsProvider} and
* {@link SqlStatisticsProvider}.
*/
public void testStatistics() {
final String product = getTestContext().getDialect().getDatabaseProduct().name();
final String dialectClassName = getTestContext().getDialect().getClass().getName();
propSaver.set(new StringProperty(MondrianProperties.instance(), MondrianProperties.instance().StatisticsProviders.getPath() + "." + product, null), MyJdbcStatisticsProvider.class.getName() + "," + SqlStatisticsProvider.class.getName());
final TestContext testContext = getTestContext().withFreshConnection();
try {
testContext.assertSimpleQuery();
// bypass dialect cache and always get a fresh dialect instance
// with our custom providers
Dialect dialect = DialectManager.createDialect(testContext.getConnection().getDataSource(), null, dialectClassName);
final List<StatisticsProvider> statisticsProviders = dialect.getStatisticsProviders();
assertEquals(2, statisticsProviders.size());
assertTrue(statisticsProviders.get(0) instanceof MyJdbcStatisticsProvider);
assertTrue(statisticsProviders.get(1) instanceof SqlStatisticsProvider);
for (StatisticsProvider statisticsProvider : statisticsProviders) {
long rowCount = statisticsProvider.getTableCardinality(dialect, testContext.getConnection().getDataSource(), null, null, "customer", new Execution(((RolapSchema) testContext.getConnection().getSchema()).getInternalConnection().getInternalStatement(), 0));
if (statisticsProvider instanceof SqlStatisticsProvider) {
assertTrue("Row count estimate: " + rowCount + " (actual 10281)", rowCount > 10000 && rowCount < 15000);
}
long valueCount = statisticsProvider.getColumnCardinality(dialect, testContext.getConnection().getDataSource(), null, null, "customer", "gender", new Execution(((RolapSchema) testContext.getConnection().getSchema()).getInternalConnection().getInternalStatement(), 0));
assertTrue("Value count estimate: " + valueCount + " (actual 2)", statisticsProvider instanceof JdbcStatisticsProvider ? valueCount == -1 : valueCount == 2);
}
} finally {
testContext.close();
}
}
use of mondrian.spi.StatisticsProvider 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;
}
Aggregations