Skip to content

Commit

Permalink
binder: primary key should by-default be non-null (#649)
Browse files Browse the repository at this point in the history
* binder: primary key should by-default be non-null

Signed-off-by: yangjiang <yangjiang@ebay.com>

* fix ut

Signed-off-by: yangjiang <yangjiang@ebay.com>
  • Loading branch information
Ted-Jiang committed May 17, 2022
1 parent fbf343d commit d6173d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/binder/statement/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())),
Expand Down
8 changes: 8 additions & 0 deletions src/catalog/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit d6173d2

Please sign in to comment.