NoahKusaba opened a new pull request, #166:
URL: https://github.com/apache/datafusion-iceberg/pull/166

   ## Which issue does this PR close?
   
   Part of #24: the follow-up promised in [this 
comment](https://github.com/apache/datafusion-iceberg/issues/24#issuecomment-7057713220).
 Namespaces have the same problem but can't be fixed this way; that's #165. 
This PR is also what #165's fixes build on: a namespace found later has no 
listed tables, so its tables must be found through the catalog.
   
   ## Rationale for this change
   
   A catalog built with `IcebergCatalogProvider::catalog_builder` lists each 
namespace's tables once, when it's built, and `table()` returned `None` for any 
name not in that list. In a long-lived session (a server, a notebook):
   
   - Tables other clients create after the build are never found.
   - A table another client drops stays listed, and every lookup of it fails 
with `TableNotFound`. `information_schema.columns` calls `table()` for every 
listed name, so one dropped table makes it fail for the whole catalog.
   - Recreating a table another client dropped fails with "Table … already 
exists", because `register_table` checked the same list.
   
   ## What changes are included in this PR?
   
   The catalog, not the list taken at build time, now decides whether a table 
exists:
   
   - **`table()`**: in a namespace built by listing the catalog, a name that 
isn't listed is loaded from the catalog too. Every lookup through the catalog 
returns `None` when the catalog reports `TableNotFound` or `NamespaceNotFound`. 
Fixed sets (`with_fixed_tables`, static catalogs) keep their membership.
   - **`register_table`** no longer checks the list; the catalog reports real 
duplicates itself.
   - **`deregister_table`** loads the table from the catalog instead of 
checking the list. This is needed with the `table()` change: `DROP TABLE` looks 
the table up with `table()`, then calls `deregister_table` and ignores its 
result, so a list check would have reported success for a table found only 
through the catalog, and dropped nothing.
   - Both reject names containing `$`, which `table()` reads as a metadata 
table (`t$snapshots`). The list checks used to stop some of these by accident. 
On `main`, `CREATE TABLE c.ns."x$snapshots"` with no table `x` creates a table 
that can never be read.
   
   Not changed:
   
   - `table_names()` (`SHOW TABLES`, `information_schema.tables`) is 
synchronous, so it still lists the tables found at build time plus DDL run 
through this provider.
   - Namespaces are still listed once (#165).
   - The Hive Metastore catalog reports a missing table as `Unexpected`, not 
`TableNotFound`, so there a dropped table still fails its lookup. REST, SQL, 
Glue, S3 Tables and the in-memory catalog report `TableNotFound`.
   
   ## Are these changes tested?
   
   Yes, in `tests/table_lookup.rs`, through SQL with a second client of the 
same catalog:
   
   - `uses_a_table_another_client_created`: read, insert into, query 
`t$snapshots`, `CREATE TABLE` (fails) and `CREATE TABLE IF NOT EXISTS` (no-op), 
then `DROP TABLE`.
   - `forgets_a_table_another_client_dropped`: `information_schema.columns` 
still works, `SELECT` and `DROP TABLE` report "not found", `DROP TABLE IF 
EXISTS` succeeds, and the table can be created again.
   - `refuses_to_create_a_table_named_like_a_metadata_table` and 
`refuses_to_drop_a_metadata_table`.
   
   The first two fail on `main`, and so does the `CREATE` test; the `DROP` test 
fails if the `$` check is removed.
   
   ## Are there any user-facing changes?
   
   Yes, behaviour only, with no API changes:
   
   - Tables other clients create are visible without rebuilding the catalog.
   - Looking up a table another client dropped returns "not found" instead of 
an error.
   - `CREATE TABLE` and `DROP TABLE` reject names containing `$`.
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to