use of mondrian.rolap.SqlStatement in project mondrian by pentaho.
the class SqlStatisticsProvider method getQueryCardinality.
public long getQueryCardinality(Dialect dialect, DataSource dataSource, String sql, Execution execution) {
final StringBuilder buf = new StringBuilder();
buf.append("select count(*) from (").append(sql).append(")");
if (dialect.requiresAliasForFromQuery()) {
if (dialect.allowsAs()) {
buf.append(" as ");
} else {
buf.append(" ");
}
dialect.quoteIdentifier(buf, "init");
}
final String countSql = buf.toString();
SqlStatement stmt = RolapUtil.executeQuery(dataSource, countSql, new Locus(execution, "SqlStatisticsProvider.getQueryCardinality", "Reading row count from query [" + sql + "]"));
try {
ResultSet resultSet = stmt.getResultSet();
if (resultSet.next()) {
++stmt.rowCount;
return resultSet.getInt(1);
}
// huh?
return -1;
} catch (SQLException e) {
throw stmt.handle(e);
} finally {
stmt.close();
}
}
use of mondrian.rolap.SqlStatement in project mondrian by pentaho.
the class SqlStatisticsProvider method getColumnCardinality.
public long getColumnCardinality(Dialect dialect, DataSource dataSource, String catalog, String schema, String table, String column, Execution execution) {
final String sql = generateColumnCardinalitySql(dialect, schema, table, column);
if (sql == null) {
return -1;
}
SqlStatement stmt = RolapUtil.executeQuery(dataSource, sql, new Locus(execution, "SqlStatisticsProvider.getColumnCardinality", "Reading cardinality for column " + Arrays.asList(catalog, schema, table, column)));
try {
ResultSet resultSet = stmt.getResultSet();
if (resultSet.next()) {
++stmt.rowCount;
return resultSet.getInt(1);
}
// huh?
return -1;
} catch (SQLException e) {
throw stmt.handle(e);
} finally {
stmt.close();
}
}
use of mondrian.rolap.SqlStatement in project mondrian by pentaho.
the class SqlStatisticsProvider method getTableCardinality.
public long getTableCardinality(Dialect dialect, DataSource dataSource, String catalog, String schema, String table, Execution execution) {
StringBuilder buf = new StringBuilder("select count(*) from ");
dialect.quoteIdentifier(buf, catalog, schema, table);
final String sql = buf.toString();
SqlStatement stmt = RolapUtil.executeQuery(dataSource, sql, new Locus(execution, "SqlStatisticsProvider.getTableCardinality", "Reading row count from table " + Arrays.asList(catalog, schema, table)));
try {
ResultSet resultSet = stmt.getResultSet();
if (resultSet.next()) {
++stmt.rowCount;
return resultSet.getInt(1);
}
// huh?
return -1;
} catch (SQLException e) {
throw stmt.handle(e);
} finally {
stmt.close();
}
}
Aggregations