Search in sources :

Example 1 with JdbcStatisticsProvider

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();
    }
}
Also used : SqlStatisticsProvider(mondrian.spi.impl.SqlStatisticsProvider) Execution(mondrian.server.Execution) JdbcStatisticsProvider(mondrian.spi.impl.JdbcStatisticsProvider) Dialect(mondrian.spi.Dialect) StringProperty(org.eigenbase.util.property.StringProperty) JdbcStatisticsProvider(mondrian.spi.impl.JdbcStatisticsProvider) StatisticsProvider(mondrian.spi.StatisticsProvider) SqlStatisticsProvider(mondrian.spi.impl.SqlStatisticsProvider)

Aggregations

Execution (mondrian.server.Execution)1 Dialect (mondrian.spi.Dialect)1 StatisticsProvider (mondrian.spi.StatisticsProvider)1 JdbcStatisticsProvider (mondrian.spi.impl.JdbcStatisticsProvider)1 SqlStatisticsProvider (mondrian.spi.impl.SqlStatisticsProvider)1 StringProperty (org.eigenbase.util.property.StringProperty)1