Class JdbcSchema

java.lang.Object
org.apache.calcite.adapter.jdbc.JdbcBaseSchema
org.apache.calcite.adapter.jdbc.JdbcSchema
All Implemented Interfaces:
Schema, Wrapper

public class JdbcSchema extends JdbcBaseSchema implements Schema, Wrapper
Implementation of Schema that is backed by a JDBC data source.

The tables in the JDBC data source appear to be tables in this schema; queries against this schema are executed against those tables, pushing down as much as possible of the query logic to SQL.

  • Field Details

  • Constructor Details

    • JdbcSchema

      public JdbcSchema(DataSource dataSource, SqlDialect dialect, JdbcConvention convention, @Nullable String catalog, @Nullable String schema)
      Creates a JDBC schema.
      Parameters:
      dataSource - Data source
      dialect - SQL dialect
      convention - Calling convention
      catalog - Catalog name, or null
      schema - Schema name pattern
  • Method Details

    • create

      public static JdbcSchema create(SchemaPlus parentSchema, String name, DataSource dataSource, @Nullable String catalog, @Nullable String schema)
    • create

      public static JdbcSchema create(SchemaPlus parentSchema, String name, DataSource dataSource, SqlDialectFactory dialectFactory, @Nullable String catalog, @Nullable String schema)
    • create

      public static JdbcSchema create(SchemaPlus parentSchema, String name, Map<String,Object> operand)
      Creates a JdbcSchema, taking credentials from a map.
      Parameters:
      parentSchema - Parent schema
      name - Name
      operand - Map of property/value pairs
      Returns:
      A JdbcSchema
    • createDialect

      @Deprecated public static SqlDialect createDialect(DataSource dataSource)
      Returns a suitable SQL dialect for the given data source.
      Parameters:
      dataSource - The data source
    • createDialect

      public static SqlDialect createDialect(SqlDialectFactory dialectFactory, DataSource dataSource)
      Returns a suitable SQL dialect for the given data source.
    • dataSource

      public static DataSource dataSource(String url, @Nullable String driverClassName, @Nullable String username, @Nullable String password)
      Creates a JDBC data source with the given specification.
    • tables

      public Lookup<Table> tables()
      Description copied from interface: Schema
      Returns a lookup object to find tables.
      Specified by:
      tables in interface Schema
      Specified by:
      tables in class JdbcBaseSchema
      Returns:
      Lookup
    • subSchemas

      public Lookup<? extends Schema> subSchemas()
      Description copied from interface: Schema
      Returns a lookup object to find sub schemas.
      Specified by:
      subSchemas in interface Schema
      Specified by:
      subSchemas in class JdbcBaseSchema
      Returns:
      Lookup
    • isMutable

      public boolean isMutable()
      Description copied from interface: Schema
      Returns whether the user is allowed to create new tables, functions and sub-schemas in this schema, in addition to those returned automatically by methods such as Schema.getTable(String).

      Even if this method returns true, the maps are not modified. Calcite stores the defined objects in a wrapper object.

      Specified by:
      isMutable in interface Schema
      Overrides:
      isMutable in class JdbcBaseSchema
      Returns:
      Whether the user is allowed to create new tables, functions and sub-schemas in this schema
    • snapshot

      public Schema snapshot(SchemaVersion version)
      Description copied from interface: Schema
      Returns the snapshot of this schema as of the specified time. The contents of the schema snapshot should not change over time.
      Specified by:
      snapshot in interface Schema
      Overrides:
      snapshot in class JdbcBaseSchema
      Parameters:
      version - The current schema version
      Returns:
      the schema snapshot.
    • getDataSource

      public DataSource getDataSource()
    • getExpression

      public Expression getExpression(@Nullable SchemaPlus parentSchema, String name)
      Description copied from interface: Schema
      Returns the expression by which this schema can be referenced in generated code.
      Specified by:
      getExpression in interface Schema
      Overrides:
      getExpression in class JdbcBaseSchema
      Parameters:
      parentSchema - Parent schema
      name - Name of this schema
      Returns:
      Expression by which this schema can be referenced in generated code
    • unwrap

      public <T> @Nullable T unwrap(Class<T> clazz)
      Description copied from interface: Wrapper
      Finds an instance of an interface implemented by this object, or returns null if this object does not support that interface.
      Specified by:
      unwrap in interface Wrapper