gratus00 opened a new pull request, #27644:
URL: https://github.com/apache/datafusion/pull/27644

   SchemaProvider::table_names and SchemaProvider::table_exist now return 
Result. Catalogs backed by remote services can report lookup failures 
(timeouts, auth errors) instead of returning an empty list, None or false, 
which callers could not tell apart from nothing existing. Closes #21778.
   
   > [!IMPORTANT]
   >
   > **Fork CI setup:** For pull requests from a fork to `main`, enable 
workflows in your fork's **Actions** tab before you push.
   > See the [fork CI setup 
guide](https://datafusion.apache.org/contributor-guide/#pull-requests-from-forks).
   
   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   - Closes #21778.
   This replaces #21944, which was closed after going stale. It is the same 
change, rebased onto current `main` and updated for the move of 
`CatalogProvider` / `SchemaProvider` into `datafusion-session`.
   
   ## Rationale for this change
   Catalogs backed by a remote service (for example paimon-rust or delta-rs 
Unity Catalog) have to make network calls when DataFusion asks which schemas or 
tables exist. When such a call fails (403, timeout, connection refused), the 
current trait signatures leave the implementation no way to report it: it has 
to return an empty list, `None`, or `false`. To the user, a failed request then 
looks the same as an empty catalog or a missing table, which makes these 
failures very hard to diagnose.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.
   
   Please explain the problem you are trying to solve in terms of the 
user-visible
   behavior, rather than the implementation.
   
   For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the
   implementation. "COUNT(DISTINCT) returns wrong results when the column 
contains
   nulls" is the user-visible problem.
   -->
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here, but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   These trait methods now return `Result`:
   
   | Trait             | Method           | Before                            | 
After                                     |
   | ----------------- | ---------------- | --------------------------------- | 
----------------------------------------- |
   | `CatalogProvider` | `schema_names()` | `Vec<String>`                     | 
`Result<Vec<String>>`                     |
   | `CatalogProvider` | `schema()`       | `Option<Arc<dyn SchemaProvider>>` | 
`Result<Option<Arc<dyn SchemaProvider>>>` |
   | `SchemaProvider`  | `table_names()`  | `Vec<String>`                     | 
`Result<Vec<String>>`                     |
   | `SchemaProvider`  | `table_exist()`  | `bool`                            | 
`Result<bool>`                            |
   
   The change is carried through:
   
   - the trait definitions in `datafusion-session`
   - the built-in providers: memory, listing, dynamic file, async/resolved, 
information schema
   - `SessionState` / `SessionContext` catalog resolution, where errors now 
propagate with `?`
   - `datafusion-cli`, examples, and sqllogictest test providers
   - the FFI wrappers: `FFI_CatalogProvider` / `FFI_SchemaProvider` function 
pointers now return `FFI_Result<...>`, so errors cross the FFI boundary instead 
of being dropped. **This changes the FFI struct layout.**
   - the `catalogs.md` user guide examples, which are compiled as doctests
   - a new section in `upgrading/57.0.0.md` describing the migration
   - 
   ### Design note: errors propagate, including in `information_schema`
   
   A missing schema or table is still `Ok(None)` / `Ok(false)` and produces the 
usual "not found" error. Only a catalog that *cannot answer* returns `Err`, and 
that error is propagated with `?`.
   
   One trade-off for reviewers: the `information_schema` tables (and `SHOW 
TABLES`) enumerate every registered catalog, so with this PR one unreachable 
catalog makes the whole listing query fail, where before it would silently 
appear empty.
   
   The alternative is to skip the failing catalog/schema with a `log::warn!` 
and keep listing the others. I chose to propagate because skipping reintroduces 
the original problem in a narrower form: the user gets an incomplete result 
with nothing in the result itself saying so. The skip-and-warn variant would 
only touch the four `add_*` helpers in `information_schema.rs`, so it is an 
easy follow-up if reviewers prefer it.
   
   ## What is the testing strategy for this PR?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   Briefly describe how this PR is tested, and point to the specific tests you 
added. For example: 'This new feature is covered by the `sqllogictest` cases 
added in `foo.slt`'.
   
   If this PR does not add tests, explain why. For example, if the change is 
already covered by existing tests, please mention it.
   
   You should also check the `codecov` bot reply on this PR to confirm the 
changed code is exercised.
   -->
   
   - Existing catalog, information schema, and `create_drop` tests are updated 
for the new signatures.
   - `datafusion/ffi/src/catalog_provider.rs`: 
`test_ffi_catalog_provider_propagates_failures` checks that an error raised by 
the producer reaches the consumer through the FFI wrapper.
   - `datafusion/ffi/integration-tests/tests/cases/catalog.rs`: new 
`test_catalog_schema_lookups` calls all four methods on a catalog loaded from 
the separately compiled cdylib, covering both found and not-found cases.
   - `catalogs.md` doctests pass with the new signatures.
   
   Run locally: `cargo fmt --all`, `cargo clippy --all-targets --all-features 
-- -D warnings`, the FFI unit and integration tests, the `catalogs.md` 
doctests, `./ci/scripts/doc_prettier_check.sh`, and the extended workspace test 
suite.
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   No change to SQL or CLI behavior when catalogs are healthy. When a catalog's 
lookup fails, the query now returns that error instead of treating the catalog 
as empty or the table as missing.
   
   This is a **breaking public API change** for implementers and callers of 
`CatalogProvider` / `SchemaProvider`, and it changes the `datafusion-ffi` ABI, 
so it needs the `api change` label. Migration notes are in 
`docs/source/library-user-guide/upgrading/57.0.0.md`.


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