Skip to content

refactor: return Result from fallible catalog and schema methods#21944

Open
gratus00 wants to merge 4 commits into
apache:mainfrom
gratus00:fix-21778-catalog-schema-result
Open

refactor: return Result from fallible catalog and schema methods#21944
gratus00 wants to merge 4 commits into
apache:mainfrom
gratus00:fix-21778-catalog-schema-result

Conversation

@gratus00

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

Several CatalogProvider and SchemaProvider methods are fallible in practice, but their signatures do not currently return Result. That forces implementations and callers to either hide errors or treat fallible operations as infallible.

This change makes those fallible paths explicit so errors can be propagated correctly through the catalog API and its downstream callers.

What changes are included in this PR?

This PR updates the following methods to return Result:

  • CatalogProvider::schema_names
  • CatalogProvider::schema
  • SchemaProvider::table_names
  • SchemaProvider::table_exist

It also propagates those signature changes through the relevant implementations and call sites, including:

  • in-memory and listing catalog/schema providers
  • async catalog/schema wrappers
  • information schema and dynamic file catalog code
  • session/context catalog access paths
  • FFI catalog/schema wrappers
  • sqllogictest and example code
  • affected tests

Are these changes tested?

Yes.

The following commands were run locally:

cargo fmt --all
TMPDIR=/tmp cargo check -p datafusion-catalog -p datafusion-ffi -p datafusion-cli -p datafusion-examples -p datafusion-sqllogictest -p datafusion
TMPDIR=/tmp cargo test -p datafusion-catalog --lib
TMPDIR=/tmp cargo test -p datafusion-ffi --lib
TMPDIR=/tmp cargo test -p datafusion memory_catalog_dereg_nonempty_schema
TMPDIR=/tmp cargo test -p datafusion test_mem_provider
TMPDIR=/tmp cargo check -p datafusion-examples --example udf
TMPDIR=/tmp cargo clippy -p datafusion --lib -- -D warnings

Are there any user-facing changes?

There are no end-user SQL or CLI behavior changes.

This is a public API change for implementers of CatalogProvider and SchemaProvider, so the api change label should be added.

@github-actions github-actions Bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) catalog Related to the catalog crate ffi Changes to the ffi crate labels Apr 30, 2026

@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 working on this.
I left a couple of small suggestions around error propagation and FFI coverage.

.expect("catalog listed by context should be retrievable");
for schema in catalog_provider
.schema_names()
.expect("schema names lookup should succeed")

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.

Nice update here. One small follow-up: this example still turns the newly fallible catalog, schema, and table name lookups into panics via expect.

Since this endpoint already returns Result<_, Status>, it might be worth changing tables to return Result<RecordBatch, Status> and mapping these errors to Status::internal(...) with ?. That would keep the example aligned with the PR's invariant that catalog failures propagate to callers instead of aborting the server.

let foreign_catalog: Arc<dyn CatalogProvider> = (&ffi_catalog).into();

let prior_schema_names = foreign_catalog.schema_names();
let prior_schema_names = foreign_catalog

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 FFI round-trip tests cover the successful path after the ABI changed to FFI_Result, which is great. It would also be helpful to have a small failing provider test that asserts failures from schema_names and schema cross the FFI boundary as DataFusionErrors.

That would give this PR's main contract some coverage at the FFI boundary too.

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.

See if you like these?

@gratus00

Copy link
Copy Markdown
Author

Hi @kosiew, thank you for your review! I'll take a look at this hopefully next week if there doesn't seem to be a rush!

@kosiew

kosiew commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

@gratus00
I will review this again after resolution of the conflicts.

@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 the work here. I think this needs one upgrade-guide note before it lands, since the public provider trait signatures are changing and downstream implementors will need a clear migration path.

fn schema(&self, name: &str) -> Option<Arc<dyn SchemaProvider>> {
fn schema(&self, name: &str) -> Result<Option<Arc<dyn SchemaProvider>>> {
let schemas = self.schemas.read().unwrap();
let maybe_schema = schemas.get(name);

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.

Small cleanup suggestion: this manual if let Some can be collapsed to the direct lookup result, since the map already stores Arc<dyn SchemaProvider>:

Ok(schemas.get(name).cloned())

@alamb alamb added the api change Changes the API exposed to users of the crate label Jun 24, 2026
@alamb

alamb commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I also added the api change to this PR

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