You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "gratus00 (via GitHub)" <gi...@apache.org> on 2026/04/30 00:48:33 UTC

[PR] refactor: return Result from fallible catalog and schema methods [datafusion]

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

   ## Which issue does this PR close?
   
   - Closes #21778.
   
   ## 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:
   ```bash
   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.
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #21944: refactor: return Result from fallible catalog and schema methods
URL: https://github.com/apache/datafusion/pull/21944


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "gratus00 (via GitHub)" <gi...@apache.org>.
gratus00 commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-5986527754

   Can I reopen this
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "gratus00 (via GitHub)" <gi...@apache.org>.
gratus00 commented on code in PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#discussion_r3471556308


##########
datafusion-examples/examples/data_io/catalog.rs:
##########
@@ -237,20 +237,20 @@ impl CatalogProvider for DirCatalog {
         Ok(Some(schema))
     }
 
-    fn schema_names(&self) -> Vec<String> {
+    fn schema_names(&self) -> Result<Vec<String>> {
         let schemas = self.schemas.read().unwrap();
-        schemas.keys().cloned().collect()
+        Ok(schemas.keys().cloned().collect())
     }
 
-    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);

Review Comment:
   Will look into both of these tomorrow! Glad you like the changes :) 



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#discussion_r3464613695


##########
datafusion-examples/examples/data_io/catalog.rs:
##########
@@ -237,20 +237,20 @@ impl CatalogProvider for DirCatalog {
         Ok(Some(schema))
     }
 
-    fn schema_names(&self) -> Vec<String> {
+    fn schema_names(&self) -> Result<Vec<String>> {
         let schemas = self.schemas.read().unwrap();
-        schemas.keys().cloned().collect()
+        Ok(schemas.keys().cloned().collect())
     }
 
-    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);

Review Comment:
   Small cleanup suggestion: this manual `if let Some` can be collapsed to the direct lookup result, since the map already stores `Arc<dyn SchemaProvider>`:
   
   ```rust
   Ok(schemas.get(name).cloned())
   ```



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#discussion_r3217967915


##########
datafusion/ffi/src/catalog_provider.rs:
##########
@@ -382,7 +384,9 @@ mod tests {
 
         let foreign_catalog: Arc<dyn CatalogProvider> = (&ffi_catalog).into();
 
-        let prior_schema_names = foreign_catalog.schema_names();
+        let prior_schema_names = foreign_catalog

Review Comment:
   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 `DataFusionError`s.
   
   That would give this PR's main contract some coverage at the FFI boundary too.



##########
datafusion-examples/examples/flight/sql_server.rs:
##########
@@ -176,12 +176,26 @@ impl FlightSqlServiceImpl {
         let mut names = vec![];
         let mut types = vec![];
         for catalog in ctx.catalog_names() {
-            let catalog_provider = ctx.catalog(&catalog).unwrap();
-            for schema in catalog_provider.schema_names() {
-                let schema_provider = catalog_provider.schema(&schema).unwrap();
-                for table in schema_provider.table_names() {
-                    let table_provider =
-                        schema_provider.table(&table).await.unwrap().unwrap();
+            let catalog_provider = ctx
+                .catalog(&catalog)
+                .expect("catalog listed by context should be retrievable");
+            for schema in catalog_provider
+                .schema_names()
+                .expect("schema names lookup should succeed")

Review Comment:
   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.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-4793501999

   I also added the api change to this PR


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "gratus00 (via GitHub)" <gi...@apache.org>.
gratus00 commented on code in PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#discussion_r3448898085


##########
datafusion/ffi/src/catalog_provider.rs:
##########
@@ -382,7 +384,9 @@ mod tests {
 
         let foreign_catalog: Arc<dyn CatalogProvider> = (&ffi_catalog).into();
 
-        let prior_schema_names = foreign_catalog.schema_names();
+        let prior_schema_names = foreign_catalog

Review Comment:
   See if you like these?



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-4766982253

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


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "gratus00 (via GitHub)" <gi...@apache.org>.
gratus00 commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-4435850290

   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!


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-4880706169

   hi @gratus00 
   Can you resolve the CI issues?


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-5519060643

   Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "kosiew (via GitHub) via github" <gi...@datafusion.apache.org>.
kosiew commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-6657134467

   @gratus00 
   You can raise a new PR after first checking that the issue is still not resolved.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: return Result from fallible catalog and schema methods [datafusion]

Posted by "gratus00 (via GitHub) via github" <gi...@datafusion.apache.org>.
gratus00 commented on PR #21944:
URL: https://github.com/apache/datafusion/pull/21944#issuecomment-6621214224

   @kosiew Hey, I unfortunately weren't able to merge this in on time. what would the procedure be if a PR got closed in this manner?


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org