Skip to main content

quill_sql/plan/logical_planner/
plan_delete.rs

1use 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_schema = self.context.catalog.table_schema(&table_ref)?;
28
29        let predicate = match selection {
30            Some(expr) => Some(self.bind_expr(expr)?),
31            None => None,
32        };
33
34        Ok(LogicalPlan::Delete(Delete {
35            table: table_ref,
36            table_schema,
37            selection: predicate,
38        }))
39    }
40}