From 5b724b9a252d18bf3ed3ca107731fd39704a4c17 Mon Sep 17 00:00:00 2001 From: Linwei Zhang Date: Wed, 28 Feb 2024 23:15:11 +0800 Subject: [PATCH] Fix tuple nullmap codec --- bustubx/src/catalog/catalog.rs | 1 - bustubx/src/execution/physical_plan/index_scan.rs | 1 - bustubx/src/execution/physical_plan/seq_scan.rs | 1 - bustubx/src/storage/codec/scalar.rs | 3 +++ bustubx/src/storage/codec/tuple.rs | 9 +++++++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bustubx/src/catalog/catalog.rs b/bustubx/src/catalog/catalog.rs index 6476858..62be4d3 100644 --- a/bustubx/src/catalog/catalog.rs +++ b/bustubx/src/catalog/catalog.rs @@ -313,7 +313,6 @@ impl Catalog { b_plus_tree_index.root_page_id.load(Ordering::SeqCst).into(), ], ); - println!("LWZTEST tuple: {:?}", tuple); indexes_table .table .insert_tuple(&EMPTY_TUPLE_META, &tuple)?; diff --git a/bustubx/src/execution/physical_plan/index_scan.rs b/bustubx/src/execution/physical_plan/index_scan.rs index 7eda7a4..6922b7f 100644 --- a/bustubx/src/execution/physical_plan/index_scan.rs +++ b/bustubx/src/execution/physical_plan/index_scan.rs @@ -48,7 +48,6 @@ impl VolcanoExecutor for PhysicalIndexScan { } fn next(&self, context: &mut ExecutionContext) -> BustubxResult> { - println!("LWZTEST index_scan"); let mut guard = self.iterator.lock().unwrap(); let Some(iterator) = &mut *guard else { return Err(BustubxError::Execution( diff --git a/bustubx/src/execution/physical_plan/seq_scan.rs b/bustubx/src/execution/physical_plan/seq_scan.rs index d9f00ef..8424c29 100644 --- a/bustubx/src/execution/physical_plan/seq_scan.rs +++ b/bustubx/src/execution/physical_plan/seq_scan.rs @@ -34,7 +34,6 @@ impl VolcanoExecutor for PhysicalSeqScan { } fn next(&self, _context: &mut ExecutionContext) -> BustubxResult> { - println!("LWZTEST seq_scan"); let Some(iterator) = &mut *self.iterator.lock().unwrap() else { return Err(BustubxError::Execution( "table iterator not created".to_string(), diff --git a/bustubx/src/storage/codec/scalar.rs b/bustubx/src/storage/codec/scalar.rs index 54d9977..0a217e2 100644 --- a/bustubx/src/storage/codec/scalar.rs +++ b/bustubx/src/storage/codec/scalar.rs @@ -20,6 +20,9 @@ impl ScalarValueCodec { ScalarValue::Float32(Some(v)) => CommonCodec::encode_f32(*v), ScalarValue::Float64(Some(v)) => CommonCodec::encode_f64(*v), ScalarValue::Varchar(Some(v)) => { + if v.len() > u16::MAX as usize { + panic!("Varchar length is greater than u16::Max") + } let mut bytes = vec![]; bytes.extend(CommonCodec::encode_u16(v.len() as u16)); bytes.extend(CommonCodec::encode_string(v)); diff --git a/bustubx/src/storage/codec/tuple.rs b/bustubx/src/storage/codec/tuple.rs index 6e9504c..e737f6c 100644 --- a/bustubx/src/storage/codec/tuple.rs +++ b/bustubx/src/storage/codec/tuple.rs @@ -25,7 +25,7 @@ impl TupleCodec { pub fn decode(bytes: &[u8], schema: SchemaRef) -> BustubxResult> { let mut total_offset = 0; - let null_map_bytes = (schema.column_count() >> 3) + 1; + let null_map_bytes = schema.column_count().div_ceil(8); let null_map = DynamicBitmap::from_bytes(&bytes[0..null_map_bytes]); total_offset += null_map_bytes; let mut bytes = &bytes[null_map_bytes..]; @@ -67,7 +67,12 @@ mod tests { ])); let tuple = Tuple::new( schema.clone(), - vec![true.into(), ScalarValue::Int32(None), 1234u64.into(), "aabb".to_string().into()], + vec![ + true.into(), + ScalarValue::Int32(None), + 1234u64.into(), + "aabb".to_string().into(), + ], ); let new_tuple = TupleCodec::decode(&TupleCodec::encode(&tuple), schema) .unwrap()