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);
}
}
Aggregations