Search in sources :

Example 1 with Tables

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

the class TestIcebergTablesMetastoreConfigAndVersion method testVersionUpdate.

@Test
public void testVersionUpdate() {
    DrillConfig config = new DrillConfig(baseIcebergConfig(baseLocation.getRoot()));
    Tables tables = new IcebergMetastore(config).tables();
    Metadata metadata = tables.metadata();
    assertTrue(metadata.supportsVersioning());
    assertEquals(0, metadata.version());
    tables.modify().overwrite(TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataKey("dir0").build()).execute();
    assertNotEquals(0, metadata.version());
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) Metadata(org.apache.drill.metastore.operate.Metadata) Tables(org.apache.drill.metastore.components.tables.Tables) IcebergMetastore(org.apache.drill.metastore.iceberg.IcebergMetastore) Test(org.junit.Test) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest)

Example 2 with Tables

use of org.apache.drill.metastore.components.tables.Tables 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

Tables (org.apache.drill.metastore.components.tables.Tables)2 DrillConfig (org.apache.drill.common.config.DrillConfig)1 SqlDropTableMetadata (org.apache.drill.exec.planner.sql.parser.SqlDropTableMetadata)1 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)1 MetastoreTableInfo (org.apache.drill.metastore.components.tables.MetastoreTableInfo)1 MetastoreException (org.apache.drill.metastore.exceptions.MetastoreException)1 IcebergBaseTest (org.apache.drill.metastore.iceberg.IcebergBaseTest)1 IcebergMetastore (org.apache.drill.metastore.iceberg.IcebergMetastore)1 TableInfo (org.apache.drill.metastore.metadata.TableInfo)1 Metadata (org.apache.drill.metastore.operate.Metadata)1 Test (org.junit.Test)1