-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alter table #104
Alter table #104
Conversation
…e_aggregation cause index scan error
47e81cd
to
8b54b7c
Compare
src/binder/alter_table.rs
Outdated
) -> Result<LogicalPlan, BindError> { | ||
let table_name: Arc<String> = Arc::new(split_name(&lower_case_name(name))?.1.to_string()); | ||
|
||
// we need convert ColumnDef to ColumnCatalog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it has been used below, so this comment is probably unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this annotation is deprecated, I forget remove it
src/binder/insert.rs
Outdated
@@ -42,7 +42,7 @@ impl<'a, T: Transaction> Binder<'a, T> { | |||
} | |||
} | |||
let mut rows = Vec::with_capacity(expr_rows.len()); | |||
|
|||
println!("{:?}", expr_rows); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that I forgot to remove it during debugging.
src/planner/operator/alter_table.rs
Outdated
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum AlterTableOperator { | ||
AddColumn(AddColumn), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert these enumerations into their corresponding Operators so that they can correspond better when writing execution operators, otherwise they will be coupled together. Maybe the Alert-related Operators can be placed in a directory to categorize them.
src/storage/kip.rs
Outdated
@@ -161,6 +162,64 @@ impl Transaction for KipTransaction { | |||
Ok(()) | |||
} | |||
|
|||
fn alter_table(&mut self, op: &AlterTableOperator) -> Result<(), StorageError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same to AlertOperator Comment
@@ -0,0 +1,19 @@ | |||
statement ok | |||
create table alter_table(id int primary key, v1 int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, the field defaults to Not Null. This probably also explains that when filling the Null value in https://github.com/KipData/KipSQL/pull/104/files#diff-ef2e7111e3dcf8c93251d804dcf4416c7fcc6a99a00aa5fd137a822d90f35eb4, you need to check whether it is allowed to be Null and throw an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check in there: https://github.com/KipData/KipSQL/pull/104/files#diff-f2254317cf50142c53882a4e2cbe4715cf85b403c38071ed0edfa7b53a42d986R177
It should be necessary to determine whether there is a default value here. When it is not nullable but has a default value, it is probably allowed to execute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, it can be declared as tests/slt/alter_table/add_column.slt
src/planner/operator/alter_table.rs
Outdated
use crate::catalog::{ColumnCatalog, TableName}; | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub struct AddColumnOperator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For alert functions that contain multiple operators, you can change the file name to add_column and wrap it in the alert folder.
storage::Transaction, | ||
}; | ||
|
||
pub struct AddColumn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For alert functions that contain multiple operators, you can change the file name to add_column and wrap it in the alert folder.
src/storage/kip.rs
Outdated
// we need catalog generate col_id && index_id | ||
// generally catalog is immutable, so do not worry it changed when alter table going on | ||
if let Some(mut catalog) = self.table(table_name.clone()).cloned() { | ||
// not yet supported default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already supported
let col_id = catalog.add_column(column.clone())?; | ||
|
||
if column.desc.is_unique { | ||
let meta = IndexMeta { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for me: Creating IndexMeta this way is not beautiful
let column = catalog.get_column_by_id(&col_id).unwrap(); | ||
let (key, value) = TableCodec::encode_column(&table_name, column)?; | ||
self.tx.set(key, value); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since many operations require TableCatalog to read metainformation, there is a dedicated cache for the catalog in Transaction, and the catalog in the cache should be updated here. Tips: Transaction is executed serially
src/storage/kip.rs
Outdated
if_not_exists, | ||
column, | ||
} = op; | ||
// we need catalog generate col_id && index_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for me
everything looks good! thx ;) |
What problem does this PR solve?
Add corresponding issue link with summary if exists -->
Issue link: #101
What is changed and how it works?
Code changes
Check List
Tests
Side effects
Note for reviewer