quill_sql/execution/physical_plan/
create_table.rs1use crate::catalog::SchemaRef;
2use crate::utils::table_ref::TableReference;
3use crate::{
4 catalog::Schema,
5 error::QuillSQLResult,
6 execution::{ExecutionContext, VolcanoExecutor},
7 storage::tuple::Tuple,
8};
9use std::sync::Arc;
10
11#[derive(derive_new::new, Debug)]
12pub struct PhysicalCreateTable {
13 pub table: TableReference,
14 pub schema: Schema,
15 pub if_not_exists: bool,
16}
17
18impl VolcanoExecutor for PhysicalCreateTable {
19 fn next(&self, context: &mut ExecutionContext) -> QuillSQLResult<Option<Tuple>> {
20 if self.if_not_exists && context.catalog.try_table_heap(&self.table).is_some() {
21 return Ok(None);
22 }
23
24 context
25 .catalog
26 .create_table(self.table.clone(), Arc::new(self.schema.clone()))?;
27 Ok(None)
28 }
29 fn output_schema(&self) -> SchemaRef {
30 Arc::new(self.schema.clone())
31 }
32}
33
34impl std::fmt::Display for PhysicalCreateTable {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 write!(f, "CreateTable: {}", self.table)
37 }
38}