gemini-code-assist[bot] commented on code in PR #38952:
URL: https://github.com/apache/beam/pull/38952#discussion_r3406119229


##########
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/catalog/InMemoryCatalog.java:
##########
@@ -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;
     }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   When the active database is dropped, `currentDatabase` is set to `null`. 
This can cause unhandled `NullPointerException`s in subsequent catalog 
operations (such as `getTable` or `createTable`) that access the active 
database. A more robust approach is to reset `currentDatabase` to the default 
database (if it still exists), or to throw a clear, user-friendly exception 
(e.g., `IllegalStateException("No database selected")`) in operations that 
require an active database.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to