Skip to content

refactor(catalog): return Result from fallible CatalogProvider and SchemaProvider methods - #27644

Open
gratus00 wants to merge 5 commits into
apache:mainfrom
gratus00:catalog-schema-result-v2
Open

gratus00 wants to merge 5 commits into
apache:mainfrom
gratus00:catalog-schema-result-v2

Conversation

@gratus00

@gratus00 gratus00 commented Nov 21, 2026 •

Copy link
Copy Markdown

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.

Which issue does this PR close?

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.

What changes are included 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?

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

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.

A broken catalog only causes an error for queries that need to read from it, and the query fails rather than returning partial results. With partition_information_schema enabled, information_schema queries only read the current catalog, so a broken catalog elsewhere doesn't affect them. SHOW TABLES reads every catalog, so it fails if any catalog fails.

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.

@github-actions github-actions Bot added documentation Improvements or additions to documentation core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) catalog Related to the catalog crate ffi Changes to the ffi crate labels Nov 21, 2026
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 apache#21778.
@gratus00
gratus00 force-pushed the catalog-schema-result-v2 branch from 9d1d2ad to 8fe4c4d Compare November 21, 2026 19:36
@gratus00

Copy link
Copy Markdown
Author

Hi @kosiew could you approve the ci workflows or do I need to do that? Thank you in advance!

@kosiew

kosiew commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@gratus00
Approved ci workflows to run.

@gratus00

Copy link
Copy Markdown
Author

Thanks @kosiew! CI is green now. This changes the public CatalogProvider/SchemaProvider signatures and the datafusion-ffi, so it probably needs the api change label. Would you (or someone familiar with the catalog API) be able to review and add the api label when you have time? Do you think you could point me to someone who could review if you don't have capacity at the moment?

@kosiew kosiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gratus00,

Thanks for making these lookup methods fallible. The new Result contract is appropriate for distinguishing provider failures from confirmed absence.

SQL planning and DROP handlers still mask lookup failures. Cascading schema removal also introduces an unnecessary dependency on successful table enumeration. These issues need to be addressed before approval.


let catalog = self.resolve_catalog(catalog_name)?;
let Some(schema) = catalog.schema(&resolved_ref.schema) else {
let Some(schema) = catalog.schema(&resolved_ref.schema)? else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Planning still converts schema lookup failures into table-not-found errors. Preserve Ok(None) for missing catalogs or schemas and Err for provider failures at the resolution boundary. Add SQL regression tests for both outcomes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a try_schema_for_ref helper that returns Ok(None) or Err depending on missing catalogue or provider failures. statement_to_plan now uses that instead of if let Ok(...). This way genuine misses still reach the planner's "table not found" error. schema_for_ref keeps its existing errors and provider errors are returned

Added tests in datafusion/core/tests/catalog/failing_provider.rs as well for behavior documentation

.catalog(&resolved.catalog)
.and_then(|c| c.schema(&resolved.schema))
match state.catalog_list().catalog(&resolved.catalog) {
Some(catalog) => catalog.schema(&resolved.schema)?,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The drop_table and drop_view handlers still mask schema lookup failures. Propagate Err and let IF EXISTS suppress only Ok(false). Add regression tests for provider failures and genuine misses in both handlers.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check again please

if let Some(schema) = self.schema(name) {
let table_names = schema.table_names();
if let Some(schema) = self.schema(name)? {
let table_names = schema.table_names()?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CASCADE unnecessarily depends on successful table enumeration. Call table_names() only when cascade is false, and test that a failing listing prevents non-cascading removal but does not prevent cascading removal.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch; I added memory_catalog_drop_schema_that_cannot_list_tables which should address the edge case you outlined

/// Returns true if table exist in the schema provider, false otherwise.
fn table_exist(&self, name: &str) -> bool {
unsafe { (self.0.table_exist)(&self.0, name.into()) }
fn table_exist(&self, name: &str) -> Result<bool> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider mirroring the failing catalog provider test for table_names() and table_exist(). Force the foreign adapter path and verify the Ffi error variant and original message.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if test_ffi_schema_provider_propagates_failures is a sufficient parallel to the catalog provider tests

}
```

The FFI wrappers (`FFI_CatalogProvider` and `FFI_SchemaProvider`) carry these

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document that the callback return types break ABI compatibility. Hosts and plugins must use matching FFI major versions, and existing plugins must be rebuilt when upgrading.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this note as well


/// Returns true if table exist in the schema provider, false otherwise.
fn table_exist(&self, name: &str) -> bool;
fn table_exist(&self, name: &str) -> Result<bool>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document that Ok(false) means confirmed absence, while Err means the provider could not answer. Document the equivalent distinction for the other modified lookup methods.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these in session/src/schema.rs and session/src/catalog.rs

let me know if i've missed anything at all

@gratus00

Copy link
Copy Markdown
Author

@kosiew thank you for the review!

I tried addressing everything as best as I could, let me know if anything else should be changed; I'm learning about datafusion as I write these PRs so any and all feedback is welcome :)

@gratus00
gratus00 requested a review from kosiew November 27, 2026 01:47

@kosiew kosiew left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gratus00,

Thanks for addressing all the previous review findings. The implementation and regression coverage look good, with no remaining code blockers.

Please resolve the upgrade guide conflict with main before approval.

if let Some(schema) = catalog.schema(&schema_name) {
for table_name in schema.table_names() {
if let Some(schema) = catalog.schema(&schema_name)? {
for table_name in schema.table_names()? {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Could we add a SQL regression with partition_information_schema disabled, verifying that an unlistable schema causes information_schema.tables to return the provider error rather than partial results?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kosiew kosiew added the api change Changes the API exposed to users of the crate label Nov 29, 2026
@gratus00
gratus00 requested a review from kosiew November 29, 2026 20:54
@gratus00

gratus00 commented Dec 1, 2026

Copy link
Copy Markdown
Author

Hi @kosiew waiting for automation and your response, I think I made a unit test that covers the case you pointed out

@kosiew kosiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gratus00,

Thanks for addressing all the review feedback. The fallible lookup contract is consistently propagated, and the regression tests cover the previously identified concerns.

One non-blocking suggestion: clarify in the PR description that direct information_schema queries respect catalog partitioning, whereas SHOW TABLES enumerates all registered catalogs. Lookup failures affect only catalogs visited by the listing.

@@ -372,3 +372,55 @@ simplify expressions such as `col IS NULL` on them.
Row values are unchanged, but schema inspection can differ: code that compares
the resulting schema against a hand-written one with `nullable: true` for
every field needs to be updated.

### `CatalogProvider` and `SchemaProvider` lookup methods now return `Result`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good change

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @alamb!

The FFI wrappers (`FFI_CatalogProvider` and `FFI_SchemaProvider`) carry these
errors across the FFI boundary instead of dropping them.

**This breaks `datafusion-ffi` ABI compatibility.** The `schema_names`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be honest, I think this impacts FFI in general not just this PR (aka datafusion-ffi ABI compatibility is designed for compatability between processes with the same datafusion version, not different datafusion versions)

However, I found this is not documented so I will make a PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see. Should I wait until your adjustment is merged before merging this change? Or remove my comment related to ABI after your PR lands?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally recommend removing the FFI specific comment in this PR (and the general doc update in #27929 (comment) will cover it)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped!

@alamb

alamb commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

This is a nice improvement - thank you @gratus00 and @kosiew

@gratus00

gratus00 commented Dec 2, 2026

Copy link
Copy Markdown
Author

@alamb Thank you! Feels like a good place to start contributing too

@kosiew Thanks for all your help as well with the suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate catalog Related to the catalog crate core Core DataFusion crate documentation Improvements or additions to documentation ffi Changes to the ffi crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Result return types to CatalogProvider / SchemaProvider fallible methods

3 participants