diff --git a/bustubx/src/common/scalar.rs b/bustubx/src/common/scalar.rs index 1d7a099..003b2c8 100644 --- a/bustubx/src/common/scalar.rs +++ b/bustubx/src/common/scalar.rs @@ -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!(), } } diff --git a/bustubx/src/storage/index_page.rs b/bustubx/src/storage/index_page.rs index ff7ad1c..594d14e 100644 --- a/bustubx/src/storage/index_page.rs +++ b/bustubx/src/storage/index_page.rs @@ -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::(); let kv_size = key_size + value_size; for i in 0..self.current_size { @@ -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::(); let kv_size = key_size + value_size; for i in 0..self.current_size { @@ -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()]); diff --git a/bustubx/src/storage/table_heap.rs b/bustubx/src/storage/table_heap.rs index c50c1ba..968e707 100644 --- a/bustubx/src/storage/table_heap.rs +++ b/bustubx/src/storage/table_heap.rs @@ -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] @@ -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] @@ -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] @@ -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); } } diff --git a/bustubx/src/storage/table_page.rs b/bustubx/src/storage/table_page.rs index 00fd514..cf3b799 100644 --- a/bustubx/src/storage/table_page.rs +++ b/bustubx/src/storage/table_page.rs @@ -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). @@ -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); @@ -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); }