Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Jan 30, 2024
1 parent 877bff7 commit dc99a41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions bustubx/src/common/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ impl ScalarValue {
Self::Int16(Some(v)) => v.to_be_bytes().to_vec(),
Self::Int32(Some(v)) => v.to_be_bytes().to_vec(),
Self::Int64(Some(v)) => v.to_be_bytes().to_vec(),

// TODO fixme
Self::Boolean(None) => vec![0u8; 1],
Self::Int8(None) => vec![0u8; 1],
Self::Int16(None) => vec![0u8; 2],
Self::Int32(None) => vec![0u8; 4],
Self::Int64(None) => vec![0u8; 8],
_ => unimplemented!(),

Check warning on line 51 in bustubx/src/common/scalar.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unreachable pattern
}
}
Expand Down
6 changes: 3 additions & 3 deletions bustubx/src/storage/index_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl BPlusTreeInternalPage {
if self.current_size == 0 {
buf[12..BUSTUBX_PAGE_SIZE].fill(0);
} else {
let key_size = self.array[0].0.data.len();
let key_size = self.array[0].0.to_bytes().len();
let value_size = size_of::<PageId>();
let kv_size = key_size + value_size;
for i in 0..self.current_size {
Expand Down Expand Up @@ -465,7 +465,7 @@ impl BPlusTreeLeafPage {
if self.current_size == 0 {
buf[16..BUSTUBX_PAGE_SIZE].fill(0);
} else {
let key_size = self.array[0].0.data.len();
let key_size = self.array[0].0.to_bytes().len();
let value_size = size_of::<Rid>();
let kv_size = key_size + value_size;
for i in 0..self.current_size {
Expand Down Expand Up @@ -628,7 +628,7 @@ mod tests {
assert_eq!(new_page.max_size, 5);
assert_eq!(
new_page.array[0].0.data,
vec![ScalarValue::Int8(None), ScalarValue::Int16(None)]
vec![ScalarValue::Int8(Some(0)), ScalarValue::Int16(Some(0))]
);
assert_eq!(new_page.array[0].1, 0);
assert_eq!(new_page.array[1].0.data, vec![1i8.into(), 1i16.into()]);
Expand Down
10 changes: 5 additions & 5 deletions bustubx/src/storage/table_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ mod tests {
&Tuple::new(schema.clone(), vec![3i8.into(), 3i16.into()]),
);
assert_eq!(table_heap.first_page_id, 0);
assert_eq!(table_heap.last_page_id, 1);
assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 2);
assert_eq!(table_heap.last_page_id, 0);
assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 1);
}

#[test]
Expand Down Expand Up @@ -323,7 +323,7 @@ mod tests {
assert_eq!(meta.insert_txn_id, 1);
assert_eq!(meta.delete_txn_id, 2);
assert_eq!(meta.is_deleted, true);
assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 2);
assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 1);
}

#[test]
Expand Down Expand Up @@ -385,7 +385,7 @@ mod tests {
assert_eq!(meta, meta3);
assert_eq!(tuple.data, vec![3i8.into(), 3i16.into()]);

assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 2);
assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 1);
}

#[test]
Expand Down Expand Up @@ -452,6 +452,6 @@ mod tests {

assert!(iterator.next(&mut table_heap).is_none());

assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 2);
assert_eq!(table_heap.buffer_pool_manager.replacer.size(), 1);
}
}
8 changes: 4 additions & 4 deletions bustubx/src/storage/table_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ impl TablePage {
};

// Check if the current slot has enough space for the new tuple. Return None if not.
if slot_end_offset < tuple.data.len() as u16 {
if slot_end_offset < tuple.to_bytes().len() as u16 {
return None;
}

// Calculate the insertion offset for the new tuple by subtracting its data length
// from the ending offset of the current slot.
let tuple_offset = slot_end_offset - tuple.data.len() as u16;
let tuple_offset = slot_end_offset - tuple.to_bytes().len() as u16;

// Calculate the minimum valid tuple insertion offset, including the table page header size,
// the total size of each tuple info (existing tuple infos and newly added tuple info).
Expand All @@ -86,7 +86,7 @@ impl TablePage {

// Store tuple information including offset, length, and metadata.
self.tuple_info
.push((tuple_offset, tuple.data.len() as u16, meta.clone()));
.push((tuple_offset, tuple.to_bytes().len() as u16, meta.clone()));

// only check
assert_eq!(tuple_id, self.tuple_info.len() as u16 - 1);
Expand All @@ -97,7 +97,7 @@ impl TablePage {
}

// Copy the tuple's data into the appropriate position within the page's data buffer.
self.data[tuple_offset as usize..(tuple_offset + tuple.data.len() as u16) as usize]
self.data[tuple_offset as usize..(tuple_offset + tuple.to_bytes().len() as u16) as usize]
.copy_from_slice(&tuple.to_bytes());
return Some(tuple_id);
}
Expand Down

0 comments on commit dc99a41

Please sign in to comment.