Class JdbcSchema

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

public class JdbcSchema extends Object implements Schema
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.
    • 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
      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
      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
      Parameters:
      parentSchema - Parent schema
      name - Name of this schema
      Returns:
      Expression by which this schema can be referenced in generated code
    • getFunctions

      protected com.google.common.collect.Multimap<String,Function> getFunctions()
    • getFunctions

      public final Collection<Function> getFunctions(String name)
      Description copied from interface: Schema
      Returns a list of functions in this schema with the given name, or an empty list if there is no such function.
      Specified by:
      getFunctions in interface Schema
      Parameters:
      name - Name of function
      Returns:
      List of functions with given name, or empty list
    • getFunctionNames

      public final Set<String> getFunctionNames()
      Description copied from interface: Schema
      Returns the names of the functions in this schema.
      Specified by:
      getFunctionNames in interface Schema
      Returns:
      Names of the functions in this schema
    • getTable

      public @Nullable Table getTable(String name)
      Description copied from interface: Schema
      Returns a table with a given name, or null if not found.
      Specified by:
      getTable in interface Schema
      Parameters:
      name - Table name
      Returns:
      Table, or null
    • getTableNames

      public Set<String> getTableNames()
      Description copied from interface: Schema
      Returns the names of the tables in this schema.
      Specified by:
      getTableNames in interface Schema
      Returns:
      Names of the tables in this schema
    • getTypes

      protected Map<String,RelProtoDataType> getTypes()
    • getType

      public @Nullable RelProtoDataType getType(String name)
      Description copied from interface: Schema
      Returns a type with a given name, or null if not found.
      Specified by:
      getType in interface Schema
      Parameters:
      name - Table name
      Returns:
      Table, or null
    • getTypeNames

      public Set<String> getTypeNames()
      Description copied from interface: Schema
      Returns the names of the types in this schema.
      Specified by:
      getTypeNames in interface Schema
      Returns:
      Names of the tables in this schema
    • getSubSchema

      public @Nullable Schema getSubSchema(String name)
      Description copied from interface: Schema
      Returns a sub-schema with a given name, or null.
      Specified by:
      getSubSchema in interface Schema
      Parameters:
      name - Sub-schema name
      Returns:
      Sub-schema with a given name, or null
    • getSubSchemaNames

      public Set<String> getSubSchemaNames()
      Description copied from interface: Schema
      Returns the names of this schema's child schemas.
      Specified by:
      getSubSchemaNames in interface Schema
      Returns:
      Names of this schema's child schemas