liurenjie1024 commented on code in PR #324:
URL: https://github.com/apache/iceberg-rust/pull/324#discussion_r1579601294


##########
crates/integrations/datafusion/src/table.rs:
##########
@@ -0,0 +1,79 @@
+// 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.
+
+use std::sync::Arc;
+
+use datafusion::datasource::TableProvider;
+use iceberg::{table::Table, Catalog, NamespaceIdent, Result, TableIdent};
+
+pub(crate) struct IcebergTableProvider {
+    _inner: Table,
+}
+
+impl IcebergTableProvider {
+    pub(crate) async fn try_new(
+        client: Arc<dyn Catalog>,
+        namespace: NamespaceIdent,
+        name: impl Into<String>,
+    ) -> Result<Self> {
+        let name = name.into();
+        let ident = TableIdent::new(namespace, name);
+        let table = client.load_table(&ident).await?;
+
+        Ok(IcebergTableProvider { _inner: table })
+    }
+}
+
+impl TableProvider for IcebergTableProvider {
+    fn as_any(&self) -> &dyn std::any::Any {
+        self
+    }
+
+    fn schema(&self) -> datafusion::arrow::datatypes::SchemaRef {
+        todo!()
+    }
+
+    fn table_type(&self) -> datafusion::datasource::TableType {
+        todo!()
+    }
+
+    fn scan<'life0, 'life1, 'life2, 'life3, 'async_trait>(

Review Comment:
   We should remove these auto generate lifetimes



##########
crates/integrations/datafusion/README.md:
##########
@@ -0,0 +1,22 @@
+<!--
+  ~ 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.
+-->
+
+# Apache Iceberg Integrations
+
+This crate contains the official Native Rust implementation of Apache Iceberg 
Integrations.

Review Comment:
   ```suggestion
   This crate contains integration of apache datafusion and apache iceberg.
   ```



##########
crates/integrations/datafusion/Cargo.toml:
##########
@@ -0,0 +1,46 @@
+# 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.
+
+[package]
+name = "iceberg-integrations-datafusion"
+version = { workspace = true }
+edition = { workspace = true }
+homepage = { workspace = true }
+rust-version = { workspace = true }
+
+categories = ["database"]
+description = "Apache Iceberg Integrations Datafusion"
+repository = { workspace = true }
+license = { workspace = true }
+keywords = ["iceberg", "integrations", "datfusion"]
+
+[features]
+default = []
+datafusion = ["dep:datafusion"]

Review Comment:
   Sorry I'm a little confusing here, as a crate for integration with 
datafusion, why this is a feature rather enabled by default?



##########
crates/integrations/datafusion/Cargo.toml:
##########
@@ -0,0 +1,46 @@
+# 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.
+
+[package]
+name = "iceberg-integrations-datafusion"

Review Comment:
   ```suggestion
   name = "iceberg-datafusion"
   ```
   How about just this?



##########
crates/integrations/datafusion/src/schema.rs:
##########
@@ -0,0 +1,102 @@
+// 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.
+
+use std::{any::Any, sync::Arc};
+
+use dashmap::DashMap;
+use datafusion::{
+    catalog::schema::SchemaProvider, datasource::TableProvider, 
error::DataFusionError,
+};
+use futures::{future::try_join_all, FutureExt};
+use iceberg::{Catalog, NamespaceIdent, Result};
+
+use crate::table::IcebergTableProvider;
+
+pub(crate) struct IcebergSchemaProvider {
+    tables: DashMap<String, Arc<dyn TableProvider>>,
+}
+
+impl IcebergSchemaProvider {
+    pub(crate) async fn try_new(
+        client: Arc<dyn Catalog>,
+        namespace: NamespaceIdent,
+    ) -> Result<Self> {
+        let table_names: Vec<String> = client
+            .list_tables(&namespace)
+            .await?
+            .iter()
+            .map(|t| t.name().to_owned())
+            .collect();
+
+        let futures: Vec<_> = table_names
+            .iter()
+            .map(|name| IcebergTableProvider::try_new(client.clone(), 
namespace.clone(), name))
+            .collect();
+
+        let providers = try_join_all(futures).await?;
+
+        let mut tables = Vec::new();
+        for (name, provider) in 
table_names.into_iter().zip(providers.into_iter()) {
+            let provider = Arc::new(provider) as Arc<dyn TableProvider>;
+            tables.push((name, provider));
+        }
+
+        Ok(IcebergSchemaProvider {
+            tables: tables.into_iter().collect(),
+        })
+    }
+}
+
+impl SchemaProvider for IcebergSchemaProvider {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn table_names(&self) -> Vec<String> {
+        self.tables.iter().map(|c| c.key().clone()).collect()
+    }
+
+    fn table_exist(&self, name: &str) -> bool {
+        self.tables.get(name).is_some()
+    }
+
+    fn table<'life0, 'life1, 'async_trait>(

Review Comment:
   We should remove these auto generated lifetimes to make it more readable.



##########
crates/integrations/datafusion/src/catalog.rs:
##########
@@ -0,0 +1,73 @@
+// 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.
+
+use std::{any::Any, sync::Arc};
+
+use dashmap::DashMap;
+use datafusion::catalog::{schema::SchemaProvider, CatalogProvider};
+use futures::future::try_join_all;
+use iceberg::{Catalog, NamespaceIdent, Result};
+
+use crate::schema::IcebergSchemaProvider;
+
+pub struct IcebergCatalogProvider {
+    schemas: DashMap<String, Arc<dyn SchemaProvider>>,
+}
+
+impl IcebergCatalogProvider {
+    pub async fn try_new(client: Arc<dyn Catalog>) -> Result<Self> {
+        let schema_names: Vec<String> = client
+            .list_namespaces(None)
+            .await?
+            .iter()
+            .flat_map(|ns| ns.as_ref().clone())

Review Comment:
   I'm not sure if datafusion allows nested namespace here, if not, maybe we 
should check namespace name.



##########
crates/integrations/datafusion/src/table.rs:
##########
@@ -0,0 +1,79 @@
+// 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.
+
+use std::sync::Arc;
+
+use datafusion::datasource::TableProvider;
+use iceberg::{table::Table, Catalog, NamespaceIdent, Result, TableIdent};
+
+pub(crate) struct IcebergTableProvider {
+    _inner: Table,
+}
+
+impl IcebergTableProvider {
+    pub(crate) async fn try_new(
+        client: Arc<dyn Catalog>,
+        namespace: NamespaceIdent,
+        name: impl Into<String>,
+    ) -> Result<Self> {
+        let name = name.into();
+        let ident = TableIdent::new(namespace, name);
+        let table = client.load_table(&ident).await?;
+
+        Ok(IcebergTableProvider { _inner: table })
+    }
+}
+
+impl TableProvider for IcebergTableProvider {
+    fn as_any(&self) -> &dyn std::any::Any {
+        self
+    }
+
+    fn schema(&self) -> datafusion::arrow::datatypes::SchemaRef {
+        todo!()

Review Comment:
   I think the convertion between iceberg schema and arrow schema has been 
implemented?



##########
crates/integrations/datafusion/src/table.rs:
##########
@@ -0,0 +1,79 @@
+// 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.
+
+use std::sync::Arc;
+
+use datafusion::datasource::TableProvider;
+use iceberg::{table::Table, Catalog, NamespaceIdent, Result, TableIdent};
+
+pub(crate) struct IcebergTableProvider {
+    _inner: Table,
+}
+
+impl IcebergTableProvider {
+    pub(crate) async fn try_new(
+        client: Arc<dyn Catalog>,
+        namespace: NamespaceIdent,
+        name: impl Into<String>,
+    ) -> Result<Self> {
+        let name = name.into();
+        let ident = TableIdent::new(namespace, name);
+        let table = client.load_table(&ident).await?;
+
+        Ok(IcebergTableProvider { _inner: table })
+    }
+}
+
+impl TableProvider for IcebergTableProvider {
+    fn as_any(&self) -> &dyn std::any::Any {
+        self
+    }
+
+    fn schema(&self) -> datafusion::arrow::datatypes::SchemaRef {
+        todo!()
+    }
+
+    fn table_type(&self) -> datafusion::datasource::TableType {
+        todo!()

Review Comment:
   I think `TableType::Base` is the answer.



##########
crates/integrations/datafusion/src/table.rs:
##########
@@ -0,0 +1,79 @@
+// 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.
+
+use std::sync::Arc;
+
+use datafusion::datasource::TableProvider;
+use iceberg::{table::Table, Catalog, NamespaceIdent, Result, TableIdent};
+
+pub(crate) struct IcebergTableProvider {
+    _inner: Table,
+}
+
+impl IcebergTableProvider {
+    pub(crate) async fn try_new(
+        client: Arc<dyn Catalog>,
+        namespace: NamespaceIdent,
+        name: impl Into<String>,
+    ) -> Result<Self> {
+        let name = name.into();
+        let ident = TableIdent::new(namespace, name);
+        let table = client.load_table(&ident).await?;
+
+        Ok(IcebergTableProvider { _inner: table })
+    }
+}
+
+impl TableProvider for IcebergTableProvider {
+    fn as_any(&self) -> &dyn std::any::Any {
+        self
+    }
+
+    fn schema(&self) -> datafusion::arrow::datatypes::SchemaRef {
+        todo!()
+    }
+
+    fn table_type(&self) -> datafusion::datasource::TableType {
+        todo!()
+    }
+
+    fn scan<'life0, 'life1, 'life2, 'life3, 'async_trait>(
+        &'life0 self,
+        _state: &'life1 datafusion::execution::context::SessionState,
+        _projection: Option<&'life2 Vec<usize>>,
+        _filters: &'life3 [datafusion::prelude::Expr],
+        _limit: Option<usize>,
+    ) -> core::pin::Pin<
+        Box<
+            dyn core::future::Future<
+                    Output = datafusion::error::Result<
+                        Arc<dyn datafusion::physical_plan::ExecutionPlan>,
+                    >,
+                > + core::marker::Send
+                + 'async_trait,
+        >,
+    >
+    where
+        'life0: 'async_trait,
+        'life1: 'async_trait,
+        'life2: 'async_trait,
+        'life3: 'async_trait,
+        Self: 'async_trait,
+    {
+        todo!()

Review Comment:
   I think this could be implemented with current scan api without filter 
pushdown?



-- 
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: issues-unsubscr...@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to