Search in sources :

Example 6 with FileSystemPlugin

use of org.apache.drill.exec.store.dfs.FileSystemPlugin in project drill by apache.

the class DescribeSchemaHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) {
    SqlIdentifier schema = ((SqlDescribeSchema) sqlNode).getSchema();
    SchemaPlus drillSchema = SchemaUtilites.findSchema(config.getConverter().getDefaultSchema(), schema.names);
    if (drillSchema != null) {
        StoragePlugin storagePlugin;
        try {
            storagePlugin = context.getStorage().getPlugin(schema.names.get(0));
        } catch (ExecutionSetupException e) {
            throw new DrillRuntimeException("Failure while retrieving storage plugin", e);
        }
        String properties;
        try {
            final Map configMap = mapper.convertValue(storagePlugin.getConfig(), Map.class);
            if (storagePlugin instanceof FileSystemPlugin) {
                transformWorkspaces(schema.names, configMap);
            }
            properties = mapper.writeValueAsString(configMap);
        } catch (JsonProcessingException e) {
            throw new DrillRuntimeException("Error while trying to convert storage config to json string", e);
        }
        return DirectPlan.createDirectPlan(context, new DescribeSchemaResult(Joiner.on(".").join(schema.names), properties));
    }
    throw UserException.validationError().message(String.format("Invalid schema name [%s]", Joiner.on(".").join(schema.names))).build(logger);
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) FileSystemPlugin(org.apache.drill.exec.store.dfs.FileSystemPlugin) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SerializableString(com.fasterxml.jackson.core.SerializableString) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SqlDescribeSchema(org.apache.drill.exec.planner.sql.parser.SqlDescribeSchema) StoragePlugin(org.apache.drill.exec.store.StoragePlugin)

Aggregations

FileSystemPlugin (org.apache.drill.exec.store.dfs.FileSystemPlugin)6 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)3 WorkspaceConfig (org.apache.drill.exec.store.dfs.WorkspaceConfig)3 SchemaPlus (org.apache.calcite.schema.SchemaPlus)2 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SerializableString (com.fasterxml.jackson.core.SerializableString)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Table (org.apache.calcite.schema.Table)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 RelConversionException (org.apache.calcite.tools.RelConversionException)1 ValidationException (org.apache.calcite.tools.ValidationException)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 FormatPluginConfig (org.apache.drill.common.logical.FormatPluginConfig)1 DrillTable (org.apache.drill.exec.planner.logical.DrillTable)1 SqlDescribeSchema (org.apache.drill.exec.planner.sql.parser.SqlDescribeSchema)1 SqlRefreshMetadata (org.apache.drill.exec.planner.sql.parser.SqlRefreshMetadata)1 StoragePlugin (org.apache.drill.exec.store.StoragePlugin)1 StoragePluginRegistry (org.apache.drill.exec.store.StoragePluginRegistry)1