fmeringdal commented on issue #12406:
URL: https://github.com/apache/datafusion/issues/12406#issuecomment-2366727670
It also seems to me that the read-only documentation is outdated. One way to
implement deletes is to provide your own planner that maps the logical plan for
delete to an execution plan. Something like the below pseudo-code:
```rs
struct PlannerWithDelete {
planner: DefaultPhysicalPlanner // The default physical planner that
datafusion uses
}
impl QueryPlanner for PlannerWithDelete {
async fn create_physical_plan(
&self,
logical_plan: &LogicalPlan,
session_state: &SessionState,
) -> Result<Arc<dyn ExecutionPlan>> {
match logical_plan {
LogicalPlan::Dml(dml) if dml.op == WriteOp::Delete => {
// Create the exec plan for the input (i.e. you can execute
this to get the data to delete)
let input_exec = self.planner.create_physical_plan(dml.input,
session_state).await;
// return an execution plan here to delete the data returned
from input_exec
}
// All other plans fallback to the default planner
logical_plan => self.planner.create_physical_plan(logical_plan,
session_state).await
}
}
}
// Use the custom query planner
let planner = PlannerWithDelete { planner: DefaultPhysicalPlanner::new() };
let state = SessionStateBuilder::new()
.with_query_planner(Arc::new(planner))
.with_default_features()
.build();
let ctx = SessionContext::new_with_state(state);
ctx.sql("DELETE FROM t1").await;
```
--
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]