COLDMANYU opened a new issue, #11408:
URL: https://github.com/apache/paimon/issues/11408

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/paimon/issues) 
and found nothing similar.
   
   ### Paimon version
   
   2.0.0, 2.1.0, and master `88792ed0d1`. 1.4.x and earlier are not affected.
   
   ### Compute Engine
   
   Java API (`HiveCatalog`). Found through Apache Gravitino, which drops Paimon 
tables through the catalog API.
   
   ### Minimal reproduce step
   
   Call `dropTable` on a Hive catalog for a table whose database does not 
exist. I added this test to `HiveCatalogTest` on master:
   
   ```java
   @Test
   public void testDropTableInMissingDatabase() {
       Identifier identifier = Identifier.create("missing_db", "t");
       // Both calls fail with RuntimeException.
       catalog.dropTable(identifier, false);
       catalog.dropTable(identifier, true);
   }
   ```
   
   Both calls fail with the same error:
   
   ```
   java.lang.RuntimeException: Can not get table 
Identifier{database='missing_db', object='t'} from metastore.
       at org.apache.paimon.hive.HiveCatalog.getTableLocation(HiveCatalog.java)
       at 
org.apache.paimon.catalog.AbstractCatalog.tableExists(AbstractCatalog.java)
       at org.apache.paimon.hive.HiveCatalog.tableExists(HiveCatalog.java)
       at 
org.apache.paimon.catalog.AbstractCatalog.dropTable(AbstractCatalog.java)
   Caused by: NoSuchObjectException(message:missing_db)
   ```
   
   `getTable` on the same identifier throws `TableNotExistException: Table 
missing_db.t does not exist.`
   
   In practice this happens when the database has already been dropped, for 
example by Spark `DROP DATABASE ... CASCADE`, and a client then drops one of 
its tables.
   
   ### What doesn't meet your expectations?
   
   A table in a missing database does not exist, so I expected:
   
   - `dropTable(identifier, true)` to return without error;
   - `dropTable(identifier, false)` to throw `TableNotExistException`, as 
`getTable` does.
   
   Before 2.0, `dropTable` behaved this way, because it started with 
`getTable`. #8130 added a `tableExists` check at the start of 
`AbstractCatalog.dropTable`. With the Hive catalog, `tableExists` first asks 
HMS whether the table exists and then calls `getTableLocation`. When the table 
is not in HMS, `getTableLocation` builds the table path from the database 
location with `client.getDatabase(databaseName)`, which throws 
`NoSuchObjectException` when the database is missing. The exception is wrapped 
in a `RuntimeException`, so `ignoreIfNotExists` is never checked.
   
   ### Anything else?
   
   I'll open a PR that makes `HiveCatalog.tableExists` return `false` when the 
database does not exist, before it builds the table location. Other callers of 
`getTableLocation` keep the current error.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!
   


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