fix: alter table update table column default (#6155)

* fix: alter table update table column default

* fix: fuzz test also cast default value

* chore: more testcase

* test: non-zero value

* refactor: per review

* tests: unexpected alter result(WIP on fix)

* ub

* ub more

* test: update sqlness
This commit is contained in:
discord9
2025-05-27 17:42:27 +08:00
committed by GitHub
parent 40bfa98d4b
commit 53752e4f6c
6 changed files with 419 additions and 49 deletions

View File

@@ -15,6 +15,7 @@
use std::sync::Arc;
use common_query::AddColumnLocation;
use datatypes::types::cast;
use partition::partition::PartitionDef;
use rand::Rng;
use snafu::{ensure, OptionExt};
@@ -22,6 +23,7 @@ use snafu::{ensure, OptionExt};
use crate::error::{self, Result};
use crate::generator::Random;
use crate::ir::alter_expr::{AlterTableOperation, AlterTableOption};
use crate::ir::create_expr::ColumnOption;
use crate::ir::{AlterTableExpr, Column, CreateTableExpr, Ident};
pub type TableContextRef = Arc<TableContext>;
@@ -138,7 +140,12 @@ impl TableContext {
}
AlterTableOperation::ModifyDataType { column } => {
if let Some(idx) = self.columns.iter().position(|col| col.name == column.name) {
self.columns[idx].column_type = column.column_type;
self.columns[idx].column_type = column.column_type.clone();
for opt in self.columns[idx].options.iter_mut() {
if let ColumnOption::DefaultValue(value) = opt {
*value = cast(value.clone(), &column.column_type).unwrap();
}
}
}
Ok(self)
}