kosiew commented on code in PR #27644:
URL: https://github.com/apache/datafusion/pull/27644#discussion_r4691696602


##########
datafusion/core/src/execution/context/mod.rs:
##########
@@ -1523,10 +1523,10 @@ impl SessionContext {
         let maybe_schema = {
             let state = self.state.read();
             let resolved = state.resolve_table_ref(table_ref.clone());
-            state
-                .catalog_list()
-                .catalog(&resolved.catalog)
-                .and_then(|c| c.schema(&resolved.schema))
+            match state.catalog_list().catalog(&resolved.catalog) {
+                Some(catalog) => catalog.schema(&resolved.schema)?,

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



##########
datafusion/core/src/execution/session_state.rs:
##########
@@ -438,7 +438,7 @@ impl SessionState {
         }
 
         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 {

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



##########
datafusion/ffi/src/schema_provider.rs:
##########
@@ -362,8 +365,8 @@ impl SchemaProvider for ForeignSchemaProvider {
     }
 
     /// 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> {

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



##########
datafusion/catalog/src/memory/catalog.rs:
##########
@@ -111,11 +111,14 @@ impl CatalogProvider for MemoryCatalogProvider {
         name: &str,
         cascade: bool,
     ) -> Result<Option<Arc<dyn SchemaProvider>>> {
-        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()?;

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



##########
datafusion/session/src/schema.rs:
##########
@@ -70,7 +70,7 @@ pub trait SchemaProvider: Any + Debug + Sync + Send {
     }
 
     /// 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>;

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



##########
docs/source/library-user-guide/upgrading/57.0.0.md:
##########
@@ -168,3 +168,48 @@ schema.
 has the names and types of the columns that it reads from the body. The
 optimizer runs this check after each rule in debug builds, so a custom rule
 that does not remap the scans now fails with an error that names the rule.
+
+### `CatalogProvider` and `SchemaProvider` lookup methods now return `Result`
+
+The following methods could not report errors, so implementations backed by a
+remote catalog had to return an empty list, `None`, or `false` when a request
+failed. That was indistinguishable from "no schemas", "schema not found", or
+"table not found". They now return `Result`:
+
+| Trait             | Method           | 56.0.0                            | 
57.0.0                                    |
+| ----------------- | ---------------- | --------------------------------- | 
----------------------------------------- |
+| `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>`                            |
+
+Implementations that cannot fail can wrap their existing return value in `Ok`:
+
+```rust
+// 56.0.0
+fn table_exist(&self, name: &str) -> bool {
+    self.tables.contains_key(name)
+}
+
+// 57.0.0
+fn table_exist(&self, name: &str) -> Result<bool> {
+    Ok(self.tables.contains_key(name))
+}
+```
+
+Callers need to handle the error, typically with `?`:
+
+```rust
+// 56.0.0
+if let Some(schema) = catalog.schema("public") {
+    for table in schema.table_names() { /* ... */ }
+}
+
+// 57.0.0
+if let Some(schema) = catalog.schema("public")? {
+    for table in schema.table_names()? { /* ... */ }
+}
+```
+
+The FFI wrappers (`FFI_CatalogProvider` and `FFI_SchemaProvider`) carry these

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



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