use of mondrian.spi.impl.JdbcStatisticsProvider 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();
}
}
Aggregations