Skip to content
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

Merged
merged 17 commits into from
Dec 5, 2023
Merged

Alter table #104

merged 17 commits into from
Dec 5, 2023

Conversation

guojidan
Copy link
Contributor

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

  • Has Rust code change
  • Has CI related scripts change

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Note for reviewer

@KKould KKould self-requested a review November 27, 2023 09:08
@KKould KKould added the enhancement New feature or request label Nov 27, 2023
) -> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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?

Copy link
Contributor Author

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

@@ -42,7 +42,7 @@ impl<'a, T: Transaction> Binder<'a, T> {
}
}
let mut rows = Vec::with_capacity(expr_rows.len());

println!("{:?}", expr_rows);
Copy link
Member

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.


#[derive(Debug, PartialEq, Clone)]
pub enum AlterTableOperator {
AddColumn(AddColumn),
Copy link
Member

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.

@@ -161,6 +162,64 @@ impl Transaction for KipTransaction {
Ok(())
}

fn alter_table(&mut self, op: &AlterTableOperator) -> Result<(), StorageError> {
Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Member

@KKould KKould Dec 4, 2023

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

use crate::catalog::{ColumnCatalog, TableName};

#[derive(Debug, PartialEq, Clone)]
pub struct AddColumnOperator {
Copy link
Member

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 {
Copy link
Member

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.

// 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
Copy link
Member

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 {
Copy link
Member

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);

Copy link
Member

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

if_not_exists,
column,
} = op;
// we need catalog generate col_id && index_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for me

@KKould
Copy link
Member

KKould commented Dec 5, 2023

everything looks good! thx ;)

@KKould KKould merged commit eb9ab5a into KipData:main Dec 5, 2023
3 checks passed
@KKould KKould mentioned this pull request Dec 16, 2023
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants