quill_sql/plan/logical_planner/
plan_delete.rs1use crate::error::{QuillSQLError, QuillSQLResult};
2use crate::plan::logical_plan::{Delete, LogicalPlan};
3use crate::plan::LogicalPlanner;
4
5impl<'a> LogicalPlanner<'a> {
6 pub fn plan_delete(
7 &self,
8 table: &sqlparser::ast::TableWithJoins,
9 selection: &Option<sqlparser::ast::Expr>,
10 ) -> QuillSQLResult<LogicalPlan> {
11 if !table.joins.is_empty() {
12 return Err(QuillSQLError::Plan(
13 "DELETE with joins is not supported".to_string(),
14 ));
15 }
16
17 let table_ref = match &table.relation {
18 sqlparser::ast::TableFactor::Table { name, .. } => self.bind_table_name(name)?,
19 _ => {
20 return Err(QuillSQLError::Plan(format!(
21 "Table {} is not supported in DELETE",
22 table
23 )))
24 }
25 };
26
27 let table_heap = self.context.catalog.table_heap(&table_ref)?;
28 let table_schema = table_heap.schema.clone();
29
30 let predicate = match selection {
31 Some(expr) => Some(self.bind_expr(expr)?),
32 None => None,
33 };
34
35 Ok(LogicalPlan::Delete(Delete {
36 table: table_ref,
37 table_schema,
38 selection: predicate,
39 }))
40 }
41}