quill_sql/plan/logical_planner/
plan_drop.rs1use 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 }
30
31 Ok(LogicalPlan::DropTable(DropTable {
32 name: table_ref,
33 if_exists,
34 }))
35 }
36
37 pub fn plan_drop_index(
38 &self,
39 names: &[sqlparser::ast::ObjectName],
40 if_exists: bool,
41 cascade: bool,
42 purge: bool,
43 ) -> QuillSQLResult<LogicalPlan> {
44 if cascade {
45 return Err(QuillSQLError::NotSupport(
46 "DROP INDEX ... CASCADE is not supported".to_string(),
47 ));
48 }
49 if purge {
50 return Err(QuillSQLError::NotSupport(
51 "DROP INDEX ... PURGE is not supported".to_string(),
52 ));
53 }
54 if names.len() != 1 {
55 return Err(QuillSQLError::NotSupport(
56 "DROP INDEX only supports a single target".to_string(),
57 ));
58 }
59
60 let parts = &names[0].0;
61 let (catalog, schema, name) = match parts.as_slice() {
62 [ident] => (None, None, ident.value.clone()),
63 [schema, ident] => (None, Some(schema.value.clone()), ident.value.clone()),
64 [catalog, schema, ident] => (
65 Some(catalog.value.clone()),
66 Some(schema.value.clone()),
67 ident.value.clone(),
68 ),
69 _ => {
70 return Err(QuillSQLError::Plan(format!(
71 "DROP INDEX name '{}' has too many qualifiers",
72 names[0]
73 )))
74 }
75 };
76
77 Ok(LogicalPlan::DropIndex(DropIndex {
78 name,
79 schema,
80 catalog,
81 if_exists,
82 }))
83 }
84}