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


##########
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 don't think this will work?
   
   ```rust
   fn execute(...) -> Result<SendableRecordBatchStream> {
     ...
     // I can't await here since fn execute() needs to remain sync
     // using tokio::Runtime block_on() seems weird?
     table_scan.to_arrow().await.unwrap()
     // also the return type is BoxStream<'static, Result<RecordBatch>>
     // which does not satisfy SendableRecordBatchStream since we need to
     // impl RecordBatchStream as well
   }
   ```
   
   ...so, how to avoid those issues? 
   
   We could try to impl RecordBatchStream on TableScan itself, this however 
would require us to have datafusion as a dependency in the core and we'd still 
have the async issue - so I don't think this would be a good solution. 
   
   Or we try the same approach as 
[delta-rs](https://github.com/delta-io/delta-rs/blob/main/crates/core/src/delta_datafusion/mod.rs#L627-L642),
 and create an actual datafusion physical plan and wrap this:
   
   ```rust
   struct IcebergTableScan {
     plan: Arc<dyn ExecutionPlan>
     ...
   }
   
   impl ExecutionPlan for IcebergTableScan {
     ...
     fn execute(...) -> Result<SendableRecordBatchStream> {
        self.plan.execute()  
     }
   }
   ```
   
   ... what do you think @liurenjie1024 ?
   



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