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.try_table_heap(&self.table).is_some() {
21 return Ok(None);
22 }
23
24 context.create_table(self.table.clone(), Arc::new(self.schema.clone()))?;
25 Ok(None)
26 }
27 fn output_schema(&self) -> SchemaRef {
28 Arc::new(self.schema.clone())
29 }
30}
31
32impl std::fmt::Display for PhysicalCreateTable {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 write!(f, "CreateTable: {}", self.table)
35 }
36}