-
Notifications
You must be signed in to change notification settings - Fork 4.6k
SQL Database DDL & Usability Improvements #38952
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
Changes from all commits
262eea2
0a48715
4314fd8
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 |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
| package org.apache.beam.sdk.extensions.sql.meta.catalog; | ||
|
|
||
| import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; | ||
| import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkState; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
@@ -111,13 +110,20 @@ public Collection<String> databases() { | |
|
|
||
| @Override | ||
| public boolean dropDatabase(String database, boolean cascade) { | ||
| checkState(!cascade, "%s does not support CASCADE.", getClass().getSimpleName()); | ||
| MetaStore metaStore = metaStores.get(database); | ||
| if (!cascade && metaStore != null && !metaStore.getTables().isEmpty()) { | ||
| throw new IllegalStateException("Database '" + database + "' is not empty."); | ||
| } | ||
|
|
||
| boolean removed = databases.remove(database); | ||
| if (!removed) { | ||
| return false; | ||
| } | ||
| if (database.equals(currentDatabase)) { | ||
| currentDatabase = null; | ||
| } | ||
|
damccorm marked this conversation as resolved.
|
||
| return removed; | ||
| metaStores.remove(database); | ||
| return true; | ||
| } | ||
|
damccorm marked this conversation as resolved.
Comment on lines
112
to
127
Contributor
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. To ensure robust defensive programming and prevent potential public boolean dropDatabase(String database, boolean cascade) {
if (database == null) {
return false;
}
MetaStore metaStore = metaStores.get(database);
if (!cascade && metaStore != null && !metaStore.getTables().isEmpty()) {
throw new IllegalStateException("Database '" + database + "' is not empty.");
}
boolean removed = databases.remove(database);
if (!removed) {
return false;
}
if (database.equals(currentDatabase)) {
currentDatabase = null;
}
metaStores.remove(database);
return true;
} |
||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.