Search in sources :

Example 6 with StoragePlugin

use of org.apache.drill.exec.store.StoragePlugin in project drill by apache.

the class DescribeSchemaHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException {
    SqlIdentifier schema = unwrap(sqlNode, SqlDescribeSchema.class).getSchema();
    SchemaPlus schemaPlus = SchemaUtilites.findSchema(config.getConverter().getDefaultSchema(), schema.names);
    if (schemaPlus == null) {
        throw UserException.validationError().message("Invalid schema name [%s]", Joiner.on(".").join(schema.names)).build(logger);
    }
    AbstractSchema drillSchema = SchemaUtilites.unwrapAsDrillSchemaInstance(schemaPlus);
    StoragePlugin storagePlugin;
    try {
        storagePlugin = context.getStorage().getPlugin(drillSchema.getSchemaPath().get(0));
        if (storagePlugin == null) {
            throw new DrillRuntimeException(String.format("Unable to find storage plugin with the following name [%s].", drillSchema.getSchemaPath().get(0)));
        }
    } catch (PluginException e) {
        throw new DrillRuntimeException("Failure while retrieving storage plugin", e);
    }
    try {
        Map configMap = mapper.convertValue(storagePlugin.getConfig(), Map.class);
        if (storagePlugin instanceof FileSystemPlugin) {
            transformWorkspaces(drillSchema.getSchemaPath(), configMap);
        }
        String properties = mapper.writeValueAsString(configMap);
        return DirectPlan.createDirectPlan(context, new DescribeSchemaResult(drillSchema.getFullSchemaName(), properties));
    } catch (JsonProcessingException e) {
        throw new DrillRuntimeException("Error while trying to convert storage config to json string", e);
    }
}
Also used : FileSystemPlugin(org.apache.drill.exec.store.dfs.FileSystemPlugin) AbstractSchema(org.apache.drill.exec.store.AbstractSchema) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) 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.calcite.sql.SqlDescribeSchema) StoragePlugin(org.apache.drill.exec.store.StoragePlugin)

Aggregations

StoragePlugin (org.apache.drill.exec.store.StoragePlugin)6 SchemaPlus (org.apache.calcite.schema.SchemaPlus)5 IOException (java.io.IOException)3 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)3 SubSchemaWrapper (org.apache.drill.exec.store.SubSchemaWrapper)3 FileSystemPlugin (org.apache.drill.exec.store.dfs.FileSystemPlugin)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 SerializableString (com.fasterxml.jackson.core.SerializableString)2 Map (java.util.Map)2 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)2 SqlDescribeSchema (org.apache.calcite.sql.SqlDescribeSchema)2 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)2 PluginException (org.apache.drill.exec.store.StoragePluginRegistry.PluginException)2 ArrayList (java.util.ArrayList)1 FormatPluginConfig (org.apache.drill.common.logical.FormatPluginConfig)1 FormatPlugin (org.apache.drill.exec.store.dfs.FormatPlugin)1 FormatSelection (org.apache.drill.exec.store.dfs.FormatSelection)1 ParquetFormatConfig (org.apache.drill.exec.store.parquet.ParquetFormatConfig)1