QuakeWang commented on code in PR #176:
URL: https://github.com/apache/paimon-rust/pull/176#discussion_r3025575338


##########
crates/integrations/datafusion/src/catalog.rs:
##########
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Paimon catalog integration for DataFusion.
+
+use std::any::Any;
+use std::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use datafusion::catalog::{CatalogProvider, SchemaProvider};
+use datafusion::datasource::TableProvider;
+use datafusion::error::Result as DFResult;
+use paimon::catalog::{Catalog, Identifier};
+
+use crate::error::to_datafusion_error;
+use crate::table::PaimonTableProvider;
+
+/// Provides an interface to manage and access multiple schemas (databases)
+/// within a Paimon [`Catalog`].
+///
+/// This provider uses lazy loading - databases and tables are fetched
+/// on-demand from the catalog, ensuring data is always fresh.
+pub struct PaimonCatalogProvider {
+    /// Reference to the Paimon catalog.
+    catalog: Arc<dyn Catalog>,
+}
+
+impl Debug for PaimonCatalogProvider {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("PaimonCatalogProvider").finish()
+    }
+}
+
+impl PaimonCatalogProvider {
+    /// Creates a new [`PaimonCatalogProvider`].
+    ///
+    /// All data is loaded lazily when accessed.
+    pub fn new(catalog: Arc<dyn Catalog>) -> Self {
+        PaimonCatalogProvider { catalog }
+    }
+}
+
+impl CatalogProvider for PaimonCatalogProvider {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn schema_names(&self) -> Vec<String> {
+        futures::executor::block_on(async {
+            self.catalog.list_databases().await.unwrap_or_default()
+        })
+    }
+
+    fn schema(&self, name: &str) -> Option<Arc<dyn SchemaProvider>> {

Review Comment:
   `schema()` currently returns `Some(...)` for any name, which makes a 
non-existent database look like a resolvable schema. On the DataFusion side, 
the expected behavior is to return `None` when the schema does not exist. 
Otherwise, downstream code ends up turning “missing schema” into “table not 
found” or an empty schema. 
   
   I reproduced this locally with a missing database. It would be better to 
check whether the database exists first and return None if it does not.



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

Reply via email to