Skip to main content

dbx_core/sql/planner/logical/
delete.rs

1//! DELETE statement planning
2
3use crate::error::{DbxError, DbxResult};
4use crate::sql::planner::types::*;
5use sqlparser::ast::Statement;
6
7use super::LogicalPlanner;
8
9impl LogicalPlanner {
10    /// DELETE → LogicalPlan 변환
11    pub(super) fn plan_delete(&self, statement: &Statement) -> DbxResult<LogicalPlan> {
12        if let Statement::Delete(delete) = statement {
13            // Extract tables from FromTable enum
14            let tables = match &delete.from {
15                sqlparser::ast::FromTable::WithFromKeyword(t) => t,
16                sqlparser::ast::FromTable::WithoutKeyword(t) => t,
17            };
18            let table_name = tables
19                .first()
20                .map(|t| t.relation.to_string())
21                .unwrap_or_default();
22
23            // Parse WHERE clause (optional)
24            let filter = if let Some(sel) = &delete.selection {
25                Some(self.plan_expr(sel)?)
26            } else {
27                None
28            };
29
30            Ok(LogicalPlan::Delete {
31                table: table_name,
32                filter,
33            })
34        } else {
35            Err(DbxError::SqlNotSupported {
36                feature: "DELETE statement".to_string(),
37                hint: "Expected DELETE statement".to_string(),
38            })
39        }
40    }
41}