-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
239 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use crate::binder::BindError; | ||
use crate::execution::executor::{BoxedExecutor, Executor}; | ||
use crate::execution::ExecutorError; | ||
use crate::planner::operator::alter_table::drop_column::DropColumnOperator; | ||
use crate::storage::Transaction; | ||
use crate::types::tuple::Tuple; | ||
use crate::types::tuple_builder::TupleBuilder; | ||
use futures_async_stream::try_stream; | ||
use std::cell::RefCell; | ||
|
||
pub struct DropColumn { | ||
op: DropColumnOperator, | ||
input: BoxedExecutor, | ||
} | ||
|
||
impl From<(DropColumnOperator, BoxedExecutor)> for DropColumn { | ||
fn from((op, input): (DropColumnOperator, BoxedExecutor)) -> Self { | ||
Self { op, input } | ||
} | ||
} | ||
|
||
impl<T: Transaction> Executor<T> for DropColumn { | ||
fn execute(self, transaction: &RefCell<T>) -> BoxedExecutor { | ||
unsafe { self._execute(transaction.as_ptr().as_mut().unwrap()) } | ||
} | ||
} | ||
|
||
impl DropColumn { | ||
#[try_stream(boxed, ok = Tuple, error = ExecutorError)] | ||
async fn _execute<T: Transaction>(self, transaction: &mut T) { | ||
let DropColumnOperator { | ||
table_name, | ||
column_name, | ||
if_exists, | ||
} = &self.op; | ||
let mut option_column_index = None; | ||
|
||
#[for_await] | ||
for tuple in self.input { | ||
let mut tuple: Tuple = tuple?; | ||
|
||
if option_column_index.is_none() { | ||
if let Some((column_index, is_primary)) = tuple | ||
.columns | ||
.iter() | ||
.enumerate() | ||
.find(|(_, column)| column.name() == column_name) | ||
.map(|(i, column)| (i, column.desc.is_primary)) | ||
{ | ||
if is_primary { | ||
Err(BindError::InvalidColumn( | ||
"drop of primary key column is not allowed.".to_owned(), | ||
))?; | ||
} | ||
option_column_index = Some(column_index); | ||
} | ||
} | ||
if option_column_index.is_none() && *if_exists { | ||
return Ok(()); | ||
} | ||
let column_index = option_column_index | ||
.ok_or_else(|| BindError::InvalidColumn("not found column".to_string()))?; | ||
|
||
let _ = tuple.columns.remove(column_index); | ||
let _ = tuple.values.remove(column_index); | ||
|
||
transaction.append(table_name, tuple, true)?; | ||
} | ||
transaction.drop_column(table_name, column_name, *if_exists)?; | ||
|
||
let tuple_builder = TupleBuilder::new_result(); | ||
let tuple = tuple_builder.push_result("ALTER TABLE SUCCESS", "1")?; | ||
|
||
yield tuple; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod add_column; | ||
pub mod drop_column; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use crate::catalog::TableName; | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub struct DropColumnOperator { | ||
pub table_name: TableName, | ||
pub column_name: String, | ||
pub if_exists: bool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod add_column; | ||
pub mod drop_column; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.