Class SchemaUtilities

java.lang.Object
org.apache.drill.exec.planner.sql.SchemaUtilities

public class SchemaUtilities extends Object
  • Field Details

    • SCHEMA_PATH_JOINER

      public static final org.apache.drill.shaded.guava.com.google.common.base.Joiner SCHEMA_PATH_JOINER
  • Constructor Details

    • SchemaUtilities

      public SchemaUtilities()
  • Method Details

    • findSchema

      public static org.apache.calcite.schema.SchemaPlus findSchema(org.apache.calcite.schema.SchemaPlus defaultSchema, List<String> schemaPath)
      Search and return schema with given schemaPath. First search in schema tree starting from defaultSchema, if not found search starting from rootSchema. Root schema tree is derived from the defaultSchema reference.
      Parameters:
      defaultSchema - Reference to the default schema in complete schema tree.
      schemaPath - Schema path to search.
      Returns:
      SchemaPlus object from default or root schema, or null if not found.
    • findSchema

      public static org.apache.calcite.schema.SchemaPlus findSchema(org.apache.calcite.schema.SchemaPlus defaultSchema, String schemaPath)
      Same utility as findSchema(SchemaPlus, List) except the search schema path given here is complete path instead of list. Use "." separator to divided the schema into nested schema names.
      Parameters:
      defaultSchema - default schema
      schemaPath - current schema path
      Returns:
      found schema path
    • getPrefixSchemaPath

      public static String getPrefixSchemaPath(String defaultSchema, String schemaPath, boolean isCaseSensitive)
      Utility function to get the commonPrefix schema between two supplied schemas. Eg: if the defaultSchema: dfs and the schemaPath is dfs.tmp.`cicks.json` then this function returns dfs if (caseSensitive is not true otherwise it returns empty string.
      Parameters:
      defaultSchema - default schema
      schemaPath - current schema path
      isCaseSensitive - true if caseSensitive comparision is required.
      Returns:
      common prefix schemaPath
    • searchSchemaTree

      public static org.apache.calcite.schema.SchemaPlus searchSchemaTree(org.apache.calcite.schema.SchemaPlus schema, List<String> schemaPath)
      Utility method to search for schema path starting from the given schema reference
    • isRootSchema

      public static boolean isRootSchema(org.apache.calcite.schema.SchemaPlus schema)
      Parameters:
      schema - current schema
      Returns:
      true if the given schema is root schema. False otherwise.
    • unwrapAsDrillSchemaInstance

      public static AbstractSchema unwrapAsDrillSchemaInstance(org.apache.calcite.schema.SchemaPlus schemaPlus)
      Unwrap given SchemaPlus instance as Drill schema instance (AbstractSchema). Once unwrapped, return default schema from AbstractSchema. If the given schema is not an instance of AbstractSchema a UserException is thrown.
    • getSchemaPath

      public static String getSchemaPath(org.apache.calcite.schema.SchemaPlus schema)
      Utility method to get the schema path for given schema instance.
    • getSchemaPath

      public static String getSchemaPath(List<String> schemaPath)
      Utility method to get the schema path for given list of schema path.
    • getSchemaPathAsList

      public static List<String> getSchemaPathAsList(String schemaPath)
      Utility method to get the list with schema path components for given schema path string.
    • getSchemaPathAsList

      public static List<String> getSchemaPathAsList(org.apache.calcite.schema.SchemaPlus schema)
      Utility method to get the schema path as list for given schema instance.
    • throwSchemaNotFoundException

      public static void throwSchemaNotFoundException(org.apache.calcite.schema.SchemaPlus defaultSchema, String givenSchemaPath)
      Utility method to throw UserException with context information
    • throwSchemaNotFoundException

      public static void throwSchemaNotFoundException(org.apache.calcite.schema.SchemaPlus defaultSchema, List<String> givenSchemaPath)
      Utility method to throw UserException with context information
    • resolveToMutableDrillSchema

      public static AbstractSchema resolveToMutableDrillSchema(org.apache.calcite.schema.SchemaPlus defaultSchema, List<String> schemaPath)
      Given reference to default schema in schema tree, search for schema with given schemaPath. Once a schema is found resolve it into a mutable AbstractDrillSchema instance. A UserException is throws when:
    • No schema for given schemaPath is found.
    • Schema found for given schemaPath is a root schema.
    • Resolved schema is not a mutable schema.
    • Parameters:
      defaultSchema - default schema
      schemaPath - current schema path
      Returns:
      mutable schema, exception otherwise
    • resolveToDrillSchema

      public static AbstractSchema resolveToDrillSchema(org.apache.calcite.schema.SchemaPlus defaultSchema, List<String> schemaPath)
      Given reference to default schema in schema tree, search for schema with given schemaPath. Once a schema is found resolve it into a mutable AbstractDrillSchema instance. A UserException is throws when:
    • No schema for given schemaPath is found.
    • Schema found for given schemaPath is a root schema.
    • Parameters:
      defaultSchema -
      schemaPath -
      Returns:
      schema, if found. Otherwise, throws an UserException
    • getTemporaryWorkspace

      public static AbstractSchema getTemporaryWorkspace(org.apache.calcite.schema.SchemaPlus defaultSchema, DrillConfig config)
      Looks in schema tree for default temporary workspace instance.
      Parameters:
      defaultSchema - default schema
      config - drill config
      Returns:
      default temporary workspace, null if workspace was not found
    • isTemporaryWorkspace

      public static boolean isTemporaryWorkspace(String schemaPath, DrillConfig config)
      Checks that passed schema path is the same as temporary workspace path. Check is case-sensitive.
      Parameters:
      schemaPath - schema path
      config - drill config
      Returns:
      true is schema path corresponds to temporary workspace, false otherwise
    • resolveToValidTemporaryWorkspace

      public static WorkspaceSchemaFactory.WorkspaceSchema resolveToValidTemporaryWorkspace(AbstractSchema schema, DrillConfig config)
      Makes sure that passed workspace exists, is default temporary workspace, mutable and file-based (instance of WorkspaceSchemaFactory.WorkspaceSchema).
      Parameters:
      schema - drill schema
      config - drill config
      Returns:
      mutable & file-based workspace instance, otherwise throws validation error
    • resolveToTemporarySchema

      public static AbstractSchema resolveToTemporarySchema(List<String> tableSchema, org.apache.calcite.schema.SchemaPlus defaultSchema, DrillConfig config)
      If table schema is not indicated in sql call, returns temporary workspace. If schema is indicated, resolves to mutable table schema.
      Parameters:
      tableSchema - table schema
      defaultSchema - default schema
      config - drill config
      Returns:
      resolved schema
    • rootSchema

      public static org.apache.calcite.schema.SchemaPlus rootSchema(org.apache.calcite.schema.SchemaPlus schema)
      Finds root of given schema.
      Parameters:
      schema - current schema
      Returns:
      root schema
    • getSchemaPath

      public static List<String> getSchemaPath(org.apache.calcite.sql.SqlIdentifier tableIdentifier)
      Returns schema path which corresponds to the specified table identifier. If table identifier contains only table name, empty list will be returned.
      Parameters:
      tableIdentifier - table identifier
      Returns:
      schema path which corresponds to the specified table identifier