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


##########
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/catalog/InMemoryCatalog.java:
##########
@@ -111,12 +110,16 @@ 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 (database.equals(currentDatabase)) {
       currentDatabase = null;
     }
+    metaStores.remove(database);
     return removed;
   }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   If the database does not exist in the catalog, `dropDatabase` should return 
`false` immediately without executing any checks or modifying the catalog state 
(such as removing from `metaStores` or clearing `currentDatabase`). Checking 
`databases.contains(database)` at the beginning of the method prevents these 
unnecessary side effects and potential inconsistent states.
   
   ```java
     @Override
     public boolean dropDatabase(String database, boolean cascade) {
       if (!databases.contains(database)) {
         return false;
       }
   
       MetaStore metaStore = metaStores.get(database);
       if (!cascade && metaStore != null && !metaStore.getTables().isEmpty()) {
         throw new IllegalStateException("Database '" + database + "' is not 
empty.");
       }
   
       databases.remove(database);
       metaStores.remove(database);
       if (database.equals(currentDatabase)) {
         currentDatabase = null;
       }
       return true;
     }
   ```



-- 
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