Skip to main content

quill_sql/plan/logical_planner/
plan_drop.rs

1use crate::error::{QuillSQLError, QuillSQLResult};
2use crate::plan::logical_plan::{DropIndex, DropTable, LogicalPlan};
3
4use super::LogicalPlanner;
5
6impl<'a> LogicalPlanner<'a> {
7    pub fn plan_drop_table(
8        &self,
9        names: &[sqlparser::ast::ObjectName],
10        if_exists: bool,
11        cascade: bool,
12        purge: bool,
13    ) -> QuillSQLResult<LogicalPlan> {
14        if purge {
15            return Err(QuillSQLError::NotSupport(
16                "DROP TABLE ... PURGE is not supported".to_string(),
17            ));
18        }
19        if names.len() != 1 {
20            return Err(QuillSQLError::NotSupport(
21                "DROP TABLE only supports a single target".to_string(),
22            ));
23        }
24
25        let table_ref = self.bind_table_name(&names[0])?;
26        if cascade {
27            // Table descriptors own index descriptors, so table drop removes them together.
28        }
29
30        Ok(LogicalPlan::DropTable(DropTable {
31            name: table_ref,
32            if_exists,
33        }))
34    }
35
36    pub fn plan_drop_index(
37        &self,
38        names: &[sqlparser::ast::ObjectName],
39        if_exists: bool,
40        cascade: bool,
41        purge: bool,
42    ) -> QuillSQLResult<LogicalPlan> {
43        if cascade {
44            return Err(QuillSQLError::NotSupport(
45                "DROP INDEX ... CASCADE is not supported".to_string(),
46            ));
47        }
48        if purge {
49            return Err(QuillSQLError::NotSupport(
50                "DROP INDEX ... PURGE is not supported".to_string(),
51            ));
52        }
53        if names.len() != 1 {
54            return Err(QuillSQLError::NotSupport(
55                "DROP INDEX only supports a single target".to_string(),
56            ));
57        }
58
59        let parts = &names[0].0;
60        let (catalog, schema, name) = match parts.as_slice() {
61            [ident] => (None, None, ident.value.clone()),
62            [schema, ident] => (None, Some(schema.value.clone()), ident.value.clone()),
63            [catalog, schema, ident] => (
64                Some(catalog.value.clone()),
65                Some(schema.value.clone()),
66                ident.value.clone(),
67            ),
68            _ => {
69                return Err(QuillSQLError::Plan(format!(
70                    "DROP INDEX name '{}' has too many qualifiers",
71                    names[0]
72                )))
73            }
74        };
75
76        Ok(LogicalPlan::DropIndex(DropIndex {
77            name,
78            schema,
79            catalog,
80            if_exists,
81        }))
82    }
83}