Class AbstractSchema

java.lang.Object
org.apache.drill.exec.store.AbstractSchema
All Implemented Interfaces:
AutoCloseable, org.apache.calcite.schema.Schema, SchemaPartitionExplorer
Direct Known Subclasses:
CapitalizingJdbcSchema, CassandraDrillSchema, CassandraRootDrillSchema, ClickhouseCatalogSchema, DrillPluginSchema, DruidSchemaFactory.DruidDataSources, DynamicRootSchema.RootSchema, ElasticsearchDrillSchema, FileSystemSchemaFactory.FileSystemSchema, GoogleSheetsDrillSchema, GoogleSheetsRootSchema, HiveDatabaseSchema, HttpAPIConnectionSchema, HttpSchemaFactory.HttpSchema, KafkaMessageSchema, MongoDatabaseSchema, SplunkSchema, SubSchemaWrapper, WorkspaceSchemaFactory.WorkspaceSchema

public abstract class AbstractSchema extends Object implements org.apache.calcite.schema.Schema, SchemaPartitionExplorer, AutoCloseable
  • Field Details

  • Constructor Details

    • AbstractSchema

      public AbstractSchema(List<String> parentSchemaPath, String name)
  • Method Details

    • getSubPartitions

      public Iterable<String> getSubPartitions(String table, List<String> partitionColumns, List<String> partitionValues) throws PartitionNotFoundException
      Description copied from interface: SchemaPartitionExplorer
      Get a list of sub-partitions of a particular table and the partitions specified by partition columns and values. Individual storage plugins will assign specific meaning to the parameters and return values.

      For more info see docs in PartitionExplorer.

      Specified by:
      getSubPartitions in interface SchemaPartitionExplorer
      partitionColumns - a list of partitions to match
      partitionValues - list of values of each partition (corresponding to the partition column list)
      Returns:
      list of sub-partitions, will be empty if a there is no further level of sub-partitioning below, i.e. hit a leaf partition
      Throws:
      PartitionNotFoundException - when the partition does not exist in the given workspace
    • getName

      public String getName()
    • getSchemaPath

      public List<String> getSchemaPath()
    • getFullSchemaName

      public String getFullSchemaName()
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • getTypeName

      public abstract String getTypeName()
      Returns string describing schema type which shows where the schema came from. Good practice here is to return json type name of storage plugin's config.
      Returns:
      schema type name
    • getDefaultSchema

      public org.apache.calcite.schema.Schema getDefaultSchema()
      The schema can be a top level schema which doesn't have its own tables, but refers to one of the default sub schemas for table look up.

      Default implementation returns itself.

      Ex. "dfs" schema refers to the tables in "default" workspace when querying for tables in "dfs" schema.

      Returns:
      Return the default schema where tables are created or retrieved from.
    • createView

      public boolean createView(View view) throws IOException
      Create a new view given definition.
      Parameters:
      view - View info including name, definition etc.
      Returns:
      Returns true if an existing view is replaced with the given view. False otherwise.
      Throws:
      IOException - in case of error creating a view
    • dropView

      public void dropView(String viewName) throws IOException
      Drop the view with given name.
      Parameters:
      viewName - view name
      Throws:
      IOException - in case of error dropping the view
    • createNewTable

      public CreateTableEntry createNewTable(String tableName, List<String> partitionColumns, StorageStrategy storageStrategy)
      Creates table entry using table name, list of partition columns and storage strategy used to create table folder and files
      Parameters:
      tableName - : new table name.
      partitionColumns - : list of partition columns. Empty list if there is no partition columns.
      storageStrategy - : storage strategy used to create table folder and files
      Returns:
      create table entry
    • modifyTable

      public ModifyTableEntry modifyTable(String tableName)
      Returns table entry using table name to insert records into the table.
      Parameters:
      tableName - : new table name.
      Returns:
      insert table entry
    • createNewTable

      public CreateTableEntry createNewTable(String tableName, List<String> partitionColumns)
      Creates table entry using table name and list of partition columns if any. Table folder and files will be created using persistent storage strategy.
      Parameters:
      tableName - : new table name.
      partitionColumns - : list of partition columns. Empty list if there is no partition columns.
      Returns:
      create table entry
    • createStatsTable

      public CreateTableEntry createStatsTable(String tableName)
      Create stats table entry for given tableName.
      Parameters:
      tableName - table name
      Returns:
      instance of create table entry
    • appendToStatsTable

      public CreateTableEntry appendToStatsTable(String tableName)
      Create an append statistics table entry for given tableName. If there is not existing statistics table, a new one is created.
      Parameters:
      tableName - table name
      Returns:
      instance of create table entry
    • getStatsTable

      public org.apache.calcite.schema.Table getStatsTable(String tableName)
      Get the statistics table for given tableName
      Parameters:
      tableName - table name
      Returns:
      instance of statistics table
    • showInInformationSchema

      public boolean showInInformationSchema()
      Reports whether to show items from this schema in INFORMATION_SCHEMA tables. (Controls ... TODO: Doc.: Mention what this typically controls or affects.)

      This base implementation returns true.

    • getFunctions

      public Collection<org.apache.calcite.schema.Function> getFunctions(String name)
      For the given table names returns list of acceptable table functions which are common for all Drill schemas. When overriding this method, parent functions must be included first to be evaluated first. If not included, parent functions won't be taken into account when creating table instance.
      Specified by:
      getFunctions in interface org.apache.calcite.schema.Schema
      Parameters:
      name - table name
      Returns:
      list of table functions
    • getFunctionParameters

      public List<TableParamDef> getFunctionParameters()
      Returns of common table function parameters that can be used all Drill schema implementations.
      Returns:
      list of table function parameters
    • applyFunctionParameters

      public DrillTable applyFunctionParameters(DrillTable drillTable, List<TableParamDef> paramDefs, List<Object> values)
      For the given list of parameters definitions executes action for the corresponding value.
      Parameters:
      drillTable - Drill table instance
      paramDefs - parameter definitions
      values - parameter values
      Returns:
      updated Drill table instance
    • getTypeMap

      protected Map<String,org.apache.calcite.rel.type.RelProtoDataType> getTypeMap()
      Returns a map of types in this schema by name.

      The implementations of getTypeNames() and getType(String) depend on this map. The default implementation of this method returns the empty map. Override this method to change their behavior.

      Returns:
      Map of types in this schema by name
    • getTypeNames

      public Set<String> getTypeNames()
      Specified by:
      getTypeNames in interface org.apache.calcite.schema.Schema
    • getType

      public org.apache.calcite.rel.type.RelProtoDataType getType(String name)
      Specified by:
      getType in interface org.apache.calcite.schema.Schema
    • getFunctionNames

      public Set<String> getFunctionNames()
      Specified by:
      getFunctionNames in interface org.apache.calcite.schema.Schema
    • getSubSchema

      public org.apache.calcite.schema.Schema getSubSchema(String name)
      Specified by:
      getSubSchema in interface org.apache.calcite.schema.Schema
    • getSubSchemaNames

      public Set<String> getSubSchemaNames()
      Specified by:
      getSubSchemaNames in interface org.apache.calcite.schema.Schema
    • isMutable

      public boolean isMutable()
      Specified by:
      isMutable in interface org.apache.calcite.schema.Schema
    • getTable

      public org.apache.calcite.schema.Table getTable(String name)
      Specified by:
      getTable in interface org.apache.calcite.schema.Schema
    • getTableNames

      public Set<String> getTableNames()
      Specified by:
      getTableNames in interface org.apache.calcite.schema.Schema
    • getExpression

      public org.apache.calcite.linq4j.tree.Expression getExpression(org.apache.calcite.schema.SchemaPlus parentSchema, String name)
      Specified by:
      getExpression in interface org.apache.calcite.schema.Schema
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • snapshot

      public org.apache.calcite.schema.Schema snapshot(org.apache.calcite.schema.SchemaVersion version)
      Specified by:
      snapshot in interface org.apache.calcite.schema.Schema
    • dropTable

      public void dropTable(String tableName)
    • getTablesByNames

      public List<org.apache.commons.lang3.tuple.Pair<String,? extends org.apache.calcite.schema.Table>> getTablesByNames(Set<String> tableNames)
      Get the collection of Table tables specified in the tableNames.
      Parameters:
      tableNames - the requested tables, specified by the table names
      Returns:
      the collection of requested tables
    • getTableNamesAndTypes

      public Collection<Map.Entry<String,org.apache.calcite.schema.Schema.TableType>> getTableNamesAndTypes()
      Used by InfoSchemaRecordGenerator.Tables for getting all table objects along with type for every requested schema. It's desired for this method to work fast because it impacts SHOW TABLES query.
      Returns:
      collection of table names and types
    • areTableNamesCaseSensitive

      public boolean areTableNamesCaseSensitive()
      Indicates if table names in schema are case sensitive. By default they are. If schema implementation claims its table names are case insensitive, it is responsible for making case insensitive look up by table name.
      Returns:
      true if table names are case sensitive
    • getUser

      public String getUser(String impersonated, String notImpersonated)
      Parameters:
      impersonated - User whom to impersonate. Usually SchemaConfig.getUserName()
      notImpersonated - Regular user (table owner for Views or Drillbit process user for Tables)
      Returns:
      endUser
    • needToImpersonateReadingData

      public boolean needToImpersonateReadingData()
      Does Drill needs to impersonate as user connected to Drill when reading data from DataSource?
      Returns:
      True when both Drill impersonation and DataSource impersonation are enabled.