Skip to content

Commit

Permalink
Fix tuple nullmap codec
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Feb 28, 2024
1 parent d0b784b commit 5b724b9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion bustubx/src/catalog/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
1 change: 0 additions & 1 deletion bustubx/src/execution/physical_plan/index_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl VolcanoExecutor for PhysicalIndexScan {
}

fn next(&self, context: &mut ExecutionContext) -> BustubxResult<Option<Tuple>> {
println!("LWZTEST index_scan");
let mut guard = self.iterator.lock().unwrap();
let Some(iterator) = &mut *guard else {
return Err(BustubxError::Execution(
Expand Down
1 change: 0 additions & 1 deletion bustubx/src/execution/physical_plan/seq_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl VolcanoExecutor for PhysicalSeqScan {
}

fn next(&self, _context: &mut ExecutionContext) -> BustubxResult<Option<Tuple>> {
println!("LWZTEST seq_scan");
let Some(iterator) = &mut *self.iterator.lock().unwrap() else {
return Err(BustubxError::Execution(
"table iterator not created".to_string(),
Expand Down
3 changes: 3 additions & 0 deletions bustubx/src/storage/codec/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
9 changes: 7 additions & 2 deletions bustubx/src/storage/codec/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl TupleCodec {
pub fn decode(bytes: &[u8], schema: SchemaRef) -> BustubxResult<DecodedData<Tuple>> {
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..];
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5b724b9

Please sign in to comment.