Class SchemaUtilities
java.lang.Object
org.apache.drill.exec.planner.sql.SchemaUtilities
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.apache.drill.shaded.guava.com.google.common.base.Joiner
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.calcite.schema.SchemaPlus
findSchema
(org.apache.calcite.schema.SchemaPlus defaultSchema, String schemaPath) Same utility asfindSchema(SchemaPlus, List)
except the search schema path given here is complete path instead of list.static org.apache.calcite.schema.SchemaPlus
findSchema
(org.apache.calcite.schema.SchemaPlus defaultSchema, List<String> schemaPath) Search and return schema with given schemaPath.static String
getPrefixSchemaPath
(String defaultSchema, String schemaPath, boolean isCaseSensitive) Utility function to get the commonPrefix schema between two supplied schemas.static String
getSchemaPath
(List<String> schemaPath) Utility method to get the schema path for given list of schema path.static String
getSchemaPath
(org.apache.calcite.schema.SchemaPlus schema) Utility method to get the schema path for given schema instance.getSchemaPath
(org.apache.calcite.sql.SqlIdentifier tableIdentifier) Returns schema path which corresponds to the specified table identifier.getSchemaPathAsList
(String schemaPath) Utility method to get the list with schema path components for given schema path string.getSchemaPathAsList
(org.apache.calcite.schema.SchemaPlus schema) Utility method to get the schema path as list for given schema instance.static AbstractSchema
getTemporaryWorkspace
(org.apache.calcite.schema.SchemaPlus defaultSchema, DrillConfig config) Looks in schema tree for default temporary workspace instance.static boolean
isRootSchema
(org.apache.calcite.schema.SchemaPlus schema) static boolean
isTemporaryWorkspace
(String schemaPath, DrillConfig config) Checks that passed schema path is the same as temporary workspace path.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.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.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.resolveToValidTemporaryWorkspace
(AbstractSchema schema, DrillConfig config) Makes sure that passed workspace exists, is default temporary workspace, mutable and file-based (instance ofWorkspaceSchemaFactory.WorkspaceSchema
).static org.apache.calcite.schema.SchemaPlus
rootSchema
(org.apache.calcite.schema.SchemaPlus schema) Finds root of given schema.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 referencestatic void
throwSchemaNotFoundException
(org.apache.calcite.schema.SchemaPlus defaultSchema, String givenSchemaPath) Utility method to throwUserException
with context informationstatic void
throwSchemaNotFoundException
(org.apache.calcite.schema.SchemaPlus defaultSchema, List<String> givenSchemaPath) Utility method to throwUserException
with context informationstatic AbstractSchema
unwrapAsDrillSchemaInstance
(org.apache.calcite.schema.SchemaPlus schemaPlus) Unwrap given SchemaPlus instance as Drill schema instance (AbstractSchema).
-
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 asfindSchema(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 schemaschemaPath
- 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 schemaschemaPath
- current schema pathisCaseSensitive
- 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 aUserException
is thrown. -
getSchemaPath
Utility method to get the schema path for given schema instance. -
getSchemaPath
Utility method to get the schema path for given list of schema path. -
getSchemaPathAsList
Utility method to get the list with schema path components for given schema path string. -
getSchemaPathAsList
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 throwUserException
with context information -
throwSchemaNotFoundException
public static void throwSchemaNotFoundException(org.apache.calcite.schema.SchemaPlus defaultSchema, List<String> givenSchemaPath) Utility method to throwUserException
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. AUserException
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 schemaschemaPath
- 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. AUserException
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 schemaconfig
- drill config- Returns:
- default temporary workspace, null if workspace was not found
-
isTemporaryWorkspace
Checks that passed schema path is the same as temporary workspace path. Check is case-sensitive.- Parameters:
schemaPath
- schema pathconfig
- 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 ofWorkspaceSchemaFactory.WorkspaceSchema
).- Parameters:
schema
- drill schemaconfig
- 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 schemadefaultSchema
- default schemaconfig
- 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
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
-