org.apache.calcite.materialize.SqlStatisticProvider Java Examples

The following examples show how to use org.apache.calcite.materialize.SqlStatisticProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Frameworks.java    From calcite with Apache License 2.0 5 votes vote down vote up
StdFrameworkConfig(Context context,
    SqlRexConvertletTable convertletTable,
    SqlOperatorTable operatorTable,
    ImmutableList<Program> programs,
    ImmutableList<RelTraitDef> traitDefs,
    SqlParser.Config parserConfig,
    SqlValidator.Config sqlValidatorConfig,
    SqlToRelConverter.Config sqlToRelConverterConfig,
    SchemaPlus defaultSchema,
    RelOptCostFactory costFactory,
    RelDataTypeSystem typeSystem,
    RexExecutor executor,
    boolean evolveLattice,
    SqlStatisticProvider statisticProvider,
    RelOptTable.ViewExpander viewExpander) {
  this.context = context;
  this.convertletTable = convertletTable;
  this.operatorTable = operatorTable;
  this.programs = programs;
  this.traitDefs = traitDefs;
  this.parserConfig = parserConfig;
  this.sqlValidatorConfig = sqlValidatorConfig;
  this.sqlToRelConverterConfig = sqlToRelConverterConfig;
  this.defaultSchema = defaultSchema;
  this.costFactory = costFactory;
  this.typeSystem = typeSystem;
  this.executor = executor;
  this.evolveLattice = evolveLattice;
  this.statisticProvider = statisticProvider;
  this.viewExpander = viewExpander;
}
 
Example #2
Source File: SqlStatisticProviderTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testQueryProviderWithCache() {
  Cache<List, Object> cache = CacheBuilder.newBuilder()
      .expireAfterAccess(5, TimeUnit.MINUTES)
      .build();
  final AtomicInteger counter = new AtomicInteger();
  QuerySqlStatisticProvider provider =
      new QuerySqlStatisticProvider(sql -> counter.incrementAndGet());
  final SqlStatisticProvider cachingProvider =
      new CachingSqlStatisticProvider(provider, cache);
  check(cachingProvider);
  final int expectedQueryCount = 6;
  assertThat(counter.get(), is(expectedQueryCount));
  check(cachingProvider);
  assertThat(counter.get(), is(expectedQueryCount)); // no more queries
}
 
Example #3
Source File: SqlStatisticProviderTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
private void check(SqlStatisticProvider provider) {
  final RelBuilder relBuilder = RelBuilder.create(config().build());
  final RelNode productScan = relBuilder.scan("product").build();
  final RelOptTable productTable = productScan.getTable();
  final RelNode salesScan = relBuilder.scan("sales_fact_1997").build();
  final RelOptTable salesTable = salesScan.getTable();
  final RelNode employeeScan = relBuilder.scan("employee").build();
  final RelOptTable employeeTable = employeeScan.getTable();
  assertThat(provider.tableCardinality(productTable), is(1_560.0d));
  assertThat(
      provider.isKey(productTable, columns(productTable, "product_id")),
      is(true));
  assertThat(
      provider.isKey(salesTable, columns(salesTable, "product_id")),
      is(false));
  assertThat(
      provider.isForeignKey(salesTable, columns(salesTable, "product_id"),
          productTable, columns(productTable, "product_id")),
      is(true));
  // Not a foreign key; product has some ids that are not referenced by any
  // sale
  assertThat(
      provider.isForeignKey(
          productTable, columns(productTable, "product_id"),
          salesTable, columns(salesTable, "product_id")),
      is(false));
  // There is one supervisor_id, 0, which is not an employee_id
  assertThat(
      provider.isForeignKey(
          employeeTable, columns(employeeTable, "supervisor_id"),
          employeeTable, columns(employeeTable, "employee_id")),
      is(false));
}
 
Example #4
Source File: MycatCalciteDataContext.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public SqlStatisticProvider getStatisticProvider() {
    return MycatCalciteSupport.INSTANCE.config.getStatisticProvider();
}
 
Example #5
Source File: Frameworks.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlStatisticProvider getStatisticProvider() {
  return statisticProvider;
}
 
Example #6
Source File: CachingSqlStatisticProvider.java    From calcite with Apache License 2.0 4 votes vote down vote up
public CachingSqlStatisticProvider(SqlStatisticProvider provider,
    Cache<List, Object> cache) {
  super();
  this.provider = provider;
  this.cache = cache;
}
 
Example #7
Source File: FrameworkConfig.java    From Bats with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the source of statistics about tables and columns to be used
 * by the lattice suggester to deduce primary keys, foreign keys, and the
 * direction of relationships.
 */
SqlStatisticProvider getStatisticProvider();
 
Example #8
Source File: FrameworkConfig.java    From calcite with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the source of statistics about tables and columns to be used
 * by the lattice suggester to deduce primary keys, foreign keys, and the
 * direction of relationships.
 */
SqlStatisticProvider getStatisticProvider();