From d6173d2bfd3926db6f5e686f6c9af06a2209d16f Mon Sep 17 00:00:00 2001 From: Yang Jiang <37145547+Ted-Jiang@users.noreply.github.com> Date: Tue, 17 May 2022 17:08:49 +0800 Subject: [PATCH] binder: primary key should by-default be non-null (#649) * binder: primary key should by-default be non-null Signed-off-by: yangjiang * fix ut Signed-off-by: yangjiang --- src/binder/statement/create_table.rs | 3 ++- src/catalog/column.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/binder/statement/create_table.rs b/src/binder/statement/create_table.rs index a23c980e..58a5cc1e 100644 --- a/src/binder/statement/create_table.rs +++ b/src/binder/statement/create_table.rs @@ -77,6 +77,7 @@ impl Binder { // // Remove this line and change `columns` above to immut. for &index in &ordered_pk_ids { columns[index as usize].set_primary(true); + columns[index as usize].set_nullable(false); } Ok(BoundCreateTable { @@ -299,7 +300,7 @@ mod tests { ColumnCatalog::new( 0, DataTypeKind::Int(None) - .nullable() + .not_null() .to_column_primary_key("a".into()), ), ColumnCatalog::new(1, DataTypeKind::Int(None).nullable().to_column("b".into())), diff --git a/src/catalog/column.rs b/src/catalog/column.rs index 60c4ec84..c3658ce4 100644 --- a/src/catalog/column.rs +++ b/src/catalog/column.rs @@ -29,6 +29,10 @@ impl ColumnDesc { self.is_primary } + pub fn set_nullable(&mut self, is_nullable: bool) { + self.datatype.nullable = is_nullable; + } + pub fn is_nullable(&self) -> bool { self.datatype.is_nullable() } @@ -92,6 +96,10 @@ impl ColumnCatalog { self.desc.is_primary() } + pub fn set_nullable(&mut self, is_nullable: bool) { + self.desc.set_nullable(is_nullable); + } + pub fn is_nullable(&self) -> bool { self.desc.is_nullable() }