Search in sources :

Example 16 with MetastoreTableInfo

use of org.apache.drill.metastore.components.tables.MetastoreTableInfo in project drill by apache.

the class MetastoreDropTableMetadataHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException {
    if (!context.getOptions().getOption(ExecConstants.METASTORE_ENABLED_VALIDATOR)) {
        throw UserException.validationError().message("Running ANALYZE TABLE DROP command when Metastore is disabled (`metastore.enabled` is set to false)").build(logger);
    }
    SqlDropTableMetadata dropTableMetadata = unwrap(sqlNode, SqlDropTableMetadata.class);
    AbstractSchema drillSchema = SchemaUtilites.resolveToDrillSchema(config.getConverter().getDefaultSchema(), dropTableMetadata.getSchemaPath());
    List<String> schemaPath = drillSchema.getSchemaPath();
    String pluginName = schemaPath.get(0);
    String workspaceName = Strings.join(schemaPath.subList(1, schemaPath.size()), AbstractSchema.SCHEMA_SEPARATOR);
    TableInfo tableInfo = TableInfo.builder().name(dropTableMetadata.getName()).storagePlugin(pluginName).workspace(workspaceName).build();
    try {
        Tables tables = context.getMetastoreRegistry().get().tables();
        MetastoreTableInfo metastoreTableInfo = tables.basicRequests().metastoreTableInfo(tableInfo);
        if (!metastoreTableInfo.isExists()) {
            if (dropTableMetadata.checkMetadataExistence()) {
                throw UserException.validationError().message("Metadata for table [%s] not found.", dropTableMetadata.getName()).build(logger);
            }
            return DirectPlan.createDirectPlan(context, false, String.format("Metadata for table [%s] does not exist.", dropTableMetadata.getName()));
        }
        tables.modify().delete(Delete.builder().metadataType(MetadataType.ALL).filter(tableInfo.toFilter()).build()).execute();
    } catch (MetastoreException e) {
        logger.error("Error when dropping metadata for table {}", dropTableMetadata.getName(), e);
        return DirectPlan.createDirectPlan(context, false, e.getMessage());
    }
    return DirectPlan.createDirectPlan(context, true, String.format("Metadata for table [%s] dropped.", dropTableMetadata.getName()));
}
Also used : MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) SqlDropTableMetadata(org.apache.drill.exec.planner.sql.parser.SqlDropTableMetadata) AbstractSchema(org.apache.drill.exec.store.AbstractSchema) MetastoreException(org.apache.drill.metastore.exceptions.MetastoreException) Tables(org.apache.drill.metastore.components.tables.Tables) TableInfo(org.apache.drill.metastore.metadata.TableInfo) MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo)

Aggregations

MetastoreTableInfo (org.apache.drill.metastore.components.tables.MetastoreTableInfo)16 Test (org.junit.Test)13 TableInfo (org.apache.drill.metastore.metadata.TableInfo)11 MetastoreTest (org.apache.drill.categories.MetastoreTest)9 SlowTest (org.apache.drill.categories.SlowTest)9 ClusterTest (org.apache.drill.test.ClusterTest)9 File (java.io.File)7 SchemaPath (org.apache.drill.common.expression.SchemaPath)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 BaseTableMetadata (org.apache.drill.metastore.metadata.BaseTableMetadata)5 FileMetadata (org.apache.drill.metastore.metadata.FileMetadata)5 ColumnStatistics (org.apache.drill.metastore.statistics.ColumnStatistics)5 Path (org.apache.hadoop.fs.Path)5 RowGroupMetadata (org.apache.drill.metastore.metadata.RowGroupMetadata)3 MetadataControllerContext (org.apache.drill.exec.metastore.analyze.MetadataControllerContext)2 TestMetastoreCommands.getBaseTableMetadata (org.apache.drill.exec.sql.TestMetastoreCommands.getBaseTableMetadata)2 TestMetastoreCommands.getColumnStatistics (org.apache.drill.exec.sql.TestMetastoreCommands.getColumnStatistics)2 AbstractBasicTablesRequestsTest (org.apache.drill.metastore.components.tables.AbstractBasicTablesRequestsTest)2