-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't delete Hive and Iceberg schema locations with nonempty subdirectories #10485
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,51 +54,68 @@ public void testCreateDropSchema() | |
} | ||
|
||
@Test | ||
public void testDropSchemaWithLocationWithoutExternalFiles() | ||
public void testDropSchemaFiles() | ||
{ | ||
String schemaName = "schema_with_empty_location_" + randomTableSuffix(); | ||
String schemaDir = warehouseDirectory + "/schema-with-empty-location/"; | ||
String schemaName = "schema_without_location_" + randomTableSuffix(); | ||
String schemaDir = format("%s/%s.db/", warehouseDirectory, schemaName); | ||
|
||
onTrino().executeQuery(format("CREATE SCHEMA %s WITH (location = '%s')", schemaName, schemaDir)); | ||
onTrino().executeQuery(format("CREATE SCHEMA %s", schemaName)); | ||
assertFileExistence(schemaDir, true, "schema directory exists after creating schema"); | ||
onTrino().executeQuery("DROP SCHEMA " + schemaName); | ||
assertFileExistence(schemaDir, false, "schema directory exists after dropping schema"); | ||
} | ||
|
||
@Test | ||
public void testDropSchemaFilesWithoutLocation() | ||
public void testDropSchemaFilesWithLocation() | ||
{ | ||
String schemaName = "schema_without_location_" + randomTableSuffix(); | ||
String schemaDir = format("%s/%s.db/", warehouseDirectory, schemaName); | ||
String schemaName = "schema_with_empty_location_" + randomTableSuffix(); | ||
String schemaDir = warehouseDirectory + "/schema-with-empty-location/"; | ||
|
||
onTrino().executeQuery(format("CREATE SCHEMA %s", schemaName)); | ||
onTrino().executeQuery(format("CREATE SCHEMA %s WITH (location = '%s')", schemaName, schemaDir)); | ||
assertFileExistence(schemaDir, true, "schema directory exists after creating schema"); | ||
onTrino().executeQuery("DROP SCHEMA " + schemaName); | ||
assertFileExistence(schemaDir, false, "schema directory exists after dropping schema"); | ||
} | ||
|
||
@Test | ||
public void testDropSchemaFilesWithLocationWithExternalFile() | ||
@Test // specified location, external file in subdir | ||
public void testDropWithExternalFilesInSubdirectory() | ||
{ | ||
String schemaName = "schema_with_nonempty_location_" + randomTableSuffix(); | ||
String schemaDir = warehouseDirectory + "/schema-with-nonempty-location/"; | ||
// Use subdirectory to make sure file check is recursive | ||
String subDir = schemaDir + "subdir/"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there case with EMPTY subdirectory also covered (that it does not prevent schema from being deleted)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed that behavior so empty directories won't be deleted, and I added a test for that as well. |
||
String externalFile = subDir + "external-file"; | ||
|
||
// Create file in schema directory before creating schema | ||
String externalFile = schemaDir + "external-file"; | ||
hdfsClient.createDirectory(schemaDir); | ||
// Create file below schema directory before creating schema | ||
hdfsClient.createDirectory(subDir); | ||
hdfsClient.saveFile(externalFile, ""); | ||
|
||
onTrino().executeQuery(format("CREATE SCHEMA %s WITH (location = '%s')", schemaName, schemaDir)); | ||
assertFileExistence(schemaDir, true, "schema directory exists after creating schema"); | ||
assertFileExistence(externalFile, true, "external file exists after creating schema"); | ||
onTrino().executeQuery("DROP SCHEMA " + schemaName); | ||
assertFileExistence(schemaDir, true, "schema directory exists after dropping schema"); | ||
assertFileExistence(externalFile, true, "external file exists after dropping schema"); | ||
|
||
hdfsClient.delete(externalFile); | ||
hdfsClient.delete(schemaDir); | ||
} | ||
|
||
// Tests create/drop schema transactions with default schema location | ||
@Test | ||
@Test // default location, empty external subdir | ||
public void testDropSchemaFilesWithEmptyExternalSubdir() | ||
{ | ||
String schemaName = "schema_with_empty_subdirectory_" + randomTableSuffix(); | ||
String schemaDir = format("%s/%s.db/", warehouseDirectory, schemaName); | ||
String externalSubdir = schemaDir + "external-subdir/"; | ||
|
||
hdfsClient.createDirectory(externalSubdir); | ||
|
||
onTrino().executeQuery("CREATE SCHEMA " + schemaName); | ||
assertFileExistence(externalSubdir, true, "external subdirectory exists after creating schema"); | ||
onTrino().executeQuery("DROP SCHEMA " + schemaName); | ||
assertFileExistence(externalSubdir, true, "external subdirectory exists after dropping schema"); | ||
|
||
hdfsClient.delete(schemaDir); | ||
} | ||
|
||
@Test // default location, transactions without external files | ||
public void testDropSchemaFilesTransactions() | ||
{ | ||
String schemaName = "schema_directory_transactions_" + randomTableSuffix(); | ||
|
@@ -122,8 +139,8 @@ public void testDropSchemaFilesTransactions() | |
assertFileExistence(schemaDir, false, "schema directory exists after dropping schema"); | ||
} | ||
|
||
@Test | ||
public void testDropSchemaFilesTransactionsWithExternalFile() | ||
@Test // specified location, transaction with top-level external file | ||
public void testDropTransactionsWithExternalFiles() | ||
{ | ||
String schemaName = "schema_transactions_with_external_files_" + randomTableSuffix(); | ||
String schemaDir = warehouseDirectory + "/schema-transactions-with-external-files/"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines aren't actually changed; I just switched the order of this test and the next after renaming them, and they're so similar that git didn't realize.