Repository navigation
Conversation
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.
9d1d2ad to
8fe4c4d
Compare
|
Hi @kosiew could you approve the ci workflows or do I need to do that? Thank you in advance! |
|
@gratus00 |
|
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
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?, |
There was a problem hiding this comment.
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.
| 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()?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
|
||
| /// 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>; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I added these in session/src/schema.rs and session/src/catalog.rs
let me know if i've missed anything at all
…; skip table listing on CASCADE
|
@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 :) |
| 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()? { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
see if this is satisfactory please
|
Hi @kosiew waiting for automation and your response, I think I made a unit test that covers the case you pointed out |
kosiew
left a comment
There was a problem hiding this comment.
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` | |||
| 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`, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Proposed doc PR:
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I personally recommend removing the FFI specific comment in this PR (and the general doc update in #27929 (comment) will cover it)
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?
This replaces refactor: return Result from fallible catalog and schema methods #21944, which was closed after going stale. It is the same change, rebased onto current
mainand updated for the move ofCatalogProvider/SchemaProviderintodatafusion-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, orfalse. 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:CatalogProviderschema_names()Vec<String>Result<Vec<String>>CatalogProviderschema()Option<Arc<dyn SchemaProvider>>Result<Option<Arc<dyn SchemaProvider>>>SchemaProvidertable_names()Vec<String>Result<Vec<String>>SchemaProvidertable_exist()boolResult<bool>The change is carried through:
datafusion-sessionSessionState/SessionContextcatalog resolution, where errors now propagate with?datafusion-cli, examples, and sqllogictest test providersFFI_CatalogProvider/FFI_SchemaProviderfunction pointers now returnFFI_Result<...>, so errors cross the FFI boundary instead of being dropped. This changes the FFI struct layout.catalogs.mduser guide examples, which are compiled as doctestsupgrading/57.0.0.mddescribing the migrationDesign note: errors propagate, including in
information_schemaA missing schema or table is still
Ok(None)/Ok(false)and produces the usual "not found" error. Only a catalog that cannot answer returnsErr, and that error is propagated with?.One trade-off for reviewers: the
information_schematables (andSHOW 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 fouradd_*helpers ininformation_schema.rs, so it is an easy follow-up if reviewers prefer it.What is the testing strategy for this PR?
create_droptests are updated for the new signatures.datafusion/ffi/src/catalog_provider.rs:test_ffi_catalog_provider_propagates_failureschecks that an error raised by the producer reaches the consumer through the FFI wrapper.datafusion/ffi/integration-tests/tests/cases/catalog.rs: newtest_catalog_schema_lookupscalls all four methods on a catalog loaded from the separately compiled cdylib, covering both found and not-found cases.catalogs.mddoctests pass with the new signatures.Run locally:
cargo fmt --all,cargo clippy --all-targets --all-features -- -D warnings, the FFI unit and integration tests, thecatalogs.mddoctests,./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_schemaenabled,information_schemaqueries only read the current catalog, so a broken catalog elsewhere doesn't affect them.SHOW TABLESreads 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 thedatafusion-ffiABI, so it needs theapi changelabel. Migration notes are indocs/source/library-user-guide/upgrading/57.0.0.md.