comphead commented on code in PR #5520:
URL: https://github.com/apache/arrow-datafusion/pull/5520#discussion_r1131325147


##########
datafusion/core/src/datasource/datasource.rs:
##########
@@ -97,6 +97,16 @@ pub trait TableProvider: Sync + Send {
     fn statistics(&self) -> Option<Statistics> {
         None
     }
+
+    /// Insert into this table
+    async fn insert_into(
+        &self,
+        _state: &SessionState,
+        _input: &LogicalPlan,
+    ) -> Result<()> {
+        let msg = "Insertion not implemented for this table".to_owned();

Review Comment:
   if the table has name, its likely better to return it to the user in error 
message instead of `this`



##########
datafusion/core/src/datasource/memory.rs:
##########
@@ -143,22 +147,95 @@ impl TableProvider for MemTable {
         _filters: &[Expr],
         _limit: Option<usize>,
     ) -> Result<Arc<dyn ExecutionPlan>> {
+        let batches = &self.batches.read().await;
         Ok(Arc::new(MemoryExec::try_new(
-            &self.batches.clone(),
+            batches,
             self.schema(),
             projection.cloned(),
         )?))
     }
+
+    /// Inserts the execution results of a given [LogicalPlan] into this 
[MemTable].
+    /// The `LogicalPlan` must have the same schema as this `MemTable`.
+    ///
+    /// # Arguments
+    ///
+    /// * `state` - The [SessionState] containing the context for executing 
the plan.
+    /// * `input` - The [LogicalPlan] to execute and insert.
+    ///
+    /// # Returns
+    ///
+    /// * A `Result` indicating success or failure.
+    async fn insert_into(&self, state: &SessionState, input: &LogicalPlan) -> 
Result<()> {
+        // Create a physical plan from the logical plan.
+        let plan = state.create_physical_plan(input).await?;
+
+        // Check that the schema of the plan matches the schema of this table.

Review Comment:
   could you please elaborate why exactly this check is needed? 



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