public class QuerySqlStatisticProvider extends java.lang.Object implements SqlStatisticProvider
SqlStatisticProvider
that generates and executes
SQL queries.Modifier and Type | Class and Description |
---|---|
private static interface |
QuerySqlStatisticProvider.BuilderAction<R>
Performs an action with a
RelBuilder . |
Modifier and Type | Field and Description |
---|---|
static SqlStatisticProvider |
SILENT_CACHING_INSTANCE
Instance that uses SQL to compute statistics,
does not log SQL statements,
and caches up to 1,024 results for up to 30 minutes.
|
private java.util.function.Consumer<java.lang.String> |
sqlConsumer |
static SqlStatisticProvider |
VERBOSE_CACHING_INSTANCE
As
SILENT_CACHING_INSTANCE but prints SQL statements to
System.out . |
Constructor and Description |
---|
QuerySqlStatisticProvider(java.util.function.Consumer<java.lang.String> sqlConsumer)
Creates a QuerySqlStatisticProvider.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.RuntimeException |
handle(java.sql.SQLException e,
java.lang.String sql) |
boolean |
isForeignKey(RelOptTable fromTable,
java.util.List<java.lang.Integer> fromColumns,
RelOptTable toTable,
java.util.List<java.lang.Integer> toColumns)
Returns whether a join is a foreign key; that is, whether every row in
the referencing table is matched by at least one row in the referenced
table.
|
boolean |
isKey(RelOptTable table,
java.util.List<java.lang.Integer> columns)
Returns whether a collection of columns is a unique (or primary) key.
|
double |
tableCardinality(RelOptTable table)
Returns an estimate of the number of rows in
table . |
protected java.lang.String |
toSql(RelNode rel,
SqlDialect dialect) |
private <R> R |
withBuilder(JdbcSchema jdbcSchema,
QuerySqlStatisticProvider.BuilderAction<R> action) |
public static final SqlStatisticProvider SILENT_CACHING_INSTANCE
public static final SqlStatisticProvider VERBOSE_CACHING_INSTANCE
SILENT_CACHING_INSTANCE
but prints SQL statements to
System.out
.private final java.util.function.Consumer<java.lang.String> sqlConsumer
public QuerySqlStatisticProvider(java.util.function.Consumer<java.lang.String> sqlConsumer)
sqlConsumer
- Called when each SQL statement is generatedpublic double tableCardinality(RelOptTable table)
SqlStatisticProvider
table
.tableCardinality
in interface SqlStatisticProvider
public boolean isForeignKey(RelOptTable fromTable, java.util.List<java.lang.Integer> fromColumns, RelOptTable toTable, java.util.List<java.lang.Integer> toColumns)
SqlStatisticProvider
For example, isForeignKey(EMP, [DEPTNO], DEPT, [DEPTNO])
returns true.
To change "at least one" to "exactly one", you also need to call
SqlStatisticProvider.isKey(org.apache.calcite.plan.RelOptTable, java.util.List<java.lang.Integer>)
.
isForeignKey
in interface SqlStatisticProvider
public boolean isKey(RelOptTable table, java.util.List<java.lang.Integer> columns)
SqlStatisticProvider
For example, isKey(EMP, [DEPTNO]
returns true;
For example, isKey(DEPT, [DEPTNO]
returns false.
isKey
in interface SqlStatisticProvider
private java.lang.RuntimeException handle(java.sql.SQLException e, java.lang.String sql)
protected java.lang.String toSql(RelNode rel, SqlDialect dialect)
private <R> R withBuilder(JdbcSchema jdbcSchema, QuerySqlStatisticProvider.BuilderAction<R> action)
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.