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