Skip to content

Commit 5dd1d23

Browse files
committed
fix: column miss match on Insert
1 parent 1853027 commit 5dd1d23

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

src/catalog/column.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl ColumnCatalog {
8484
&self.summary
8585
}
8686

87-
pub(crate) fn id(&self) -> Option<ColumnId> {
87+
pub fn id(&self) -> Option<ColumnId> {
8888
match &self.summary.relation {
8989
ColumnRelation::None => None,
9090
ColumnRelation::Table { column_id, .. } => Some(*column_id),
@@ -138,17 +138,6 @@ impl ColumnCatalog {
138138
}
139139
}
140140

141-
#[cfg(test)]
142-
impl ColumnSummary {
143-
pub(crate) fn column_id(&self) -> Option<&ColumnId> {
144-
if let ColumnRelation::Table { column_id, .. } = &self.relation {
145-
Some(column_id)
146-
} else {
147-
None
148-
}
149-
}
150-
}
151-
152141
/// The descriptor of a column.
153142
#[derive(Debug, Clone, PartialEq, Eq, Hash, ReferenceSerialization)]
154143
pub struct ColumnDesc {

src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ pub(crate) mod test {
399399
true,
400400
ColumnDesc::new(LogicalType::Integer, false, false, None).unwrap(),
401401
);
402-
let number_column_id = schema[0].summary.column_id().unwrap();
403-
column.set_ref_table(Arc::new("a".to_string()), *number_column_id);
402+
let number_column_id = schema[0].id().unwrap();
403+
column.set_ref_table(Arc::new("a".to_string()), number_column_id);
404404

405405
debug_assert_eq!(schema, Arc::new(vec![ColumnRef::from(column)]));
406406
debug_assert_eq!(

src/execution/dml/insert.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Insert {
5858
let mut tuples = Vec::new();
5959
let schema = input.output_schema().clone();
6060

61-
let pk_index = throw!(schema
61+
let pk_name = throw!(schema
6262
.iter()
6363
.find(|col| col.desc.is_primary)
64-
.map(|col| col.id())
64+
.map(|col| col.name())
6565
.ok_or_else(|| DatabaseError::NotNull));
6666

6767
if let Some(table_catalog) = transaction.table(cache.0, table_name.clone()).cloned()
@@ -74,17 +74,17 @@ impl<'a, T: Transaction + 'a> WriteExecutor<'a, T> for Insert {
7474

7575
let mut tuple_map = HashMap::new();
7676
for (i, value) in values.into_iter().enumerate() {
77-
tuple_map.insert(schema[i].id(), value);
77+
tuple_map.insert(schema[i].name(), value);
7878
}
7979
let tuple_id = throw!(tuple_map
80-
.get(&pk_index)
80+
.get(pk_name)
8181
.cloned()
8282
.ok_or(DatabaseError::NotNull));
8383
let mut values = Vec::with_capacity(table_catalog.columns_len());
8484

8585
for col in table_catalog.columns() {
8686
let value = {
87-
let mut value = tuple_map.remove(&col.id());
87+
let mut value = tuple_map.remove(&col.name());
8888

8989
if value.is_none() {
9090
value = throw!(col.default_value());

tests/macros-test/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,15 @@ mod test {
171171
);
172172
assert!(numbers.next().is_none());
173173

174+
let function_schema = function.output_schema();
174175
let table_name = Arc::new("test_numbers".to_string());
175176
let mut c1 = ColumnCatalog::new(
176177
"c1".to_string(),
177178
true,
178179
ColumnDesc::new(LogicalType::Integer, false, false, None)?,
179180
);
180181
c1.summary.relation = ColumnRelation::Table {
181-
column_id: 0,
182+
column_id: function_schema[0].id().unwrap(),
182183
table_name: table_name.clone(),
183184
};
184185
let mut c2 = ColumnCatalog::new(
@@ -187,12 +188,12 @@ mod test {
187188
ColumnDesc::new(LogicalType::Integer, false, false, None)?,
188189
);
189190
c2.summary.relation = ColumnRelation::Table {
190-
column_id: 1,
191+
column_id: function_schema[1].id().unwrap(),
191192
table_name: table_name.clone(),
192193
};
193194

194195
assert_eq!(
195-
function.output_schema(),
196+
function_schema,
196197
&Arc::new(vec![ColumnRef::from(c1), ColumnRef::from(c2)])
197198
);
198199

0 commit comments

Comments
 (0)