Skip to content

Commit

Permalink
fix: fill symbol move to DataValue::to_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Mar 21, 2024
1 parent 9e35bf0 commit 84b4101
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/storage/table_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl TableCodec {
) -> Result<(Bytes, Bytes), DatabaseError> {
let key = TableCodec::encode_index_key(name, index, Some(tuple_id))?;

Ok((Bytes::from(key), Bytes::from(tuple_id.to_raw())))
Ok((Bytes::from(key), Bytes::from(tuple_id.to_raw(None))))
}

fn _encode_index_key(name: &str, index: &Index) -> Result<Vec<u8>, DatabaseError> {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl TableCodec {

if let Some(tuple_id) = tuple_id {
if matches!(index.ty, IndexType::Normal | IndexType::Composite) {
key_prefix.append(&mut tuple_id.to_raw());
key_prefix.append(&mut tuple_id.to_raw(None));
}
}
Ok(key_prefix)
Expand Down
12 changes: 4 additions & 8 deletions src/types/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,13 @@ impl Tuple {
if value.is_null() {
bytes[i / BITS_MAX_INDEX] = flip_bit(bytes[i / BITS_MAX_INDEX], i % BITS_MAX_INDEX);
} else {
let mut value_bytes = value.to_raw();
let logical_type = types[i];
let mut value_bytes = value.to_raw(Some(logical_type));

if let Some(len) = types[i].raw_len() {
let difference = len.saturating_sub(value_bytes.len());

bytes.append(&mut value_bytes);
bytes.append(&mut vec![b' '; difference]);
} else {
if logical_type.raw_len().is_none() {
bytes.append(&mut (value_bytes.len() as u32).encode_fixed_vec());
bytes.append(&mut value_bytes);
}
bytes.append(&mut value_bytes);
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl DataValue {
}
}

pub fn to_raw(&self) -> Vec<u8> {
pub fn to_raw(&self, logical_type: Option<LogicalType>) -> Vec<u8> {
match self {
DataValue::Null => None,
DataValue::Boolean(v) => v.map(|v| vec![v as u8]),
Expand All @@ -392,7 +392,16 @@ impl DataValue {
DataValue::UInt16(v) => v.map(|v| v.encode_fixed_vec()),
DataValue::UInt32(v) => v.map(|v| v.encode_fixed_vec()),
DataValue::UInt64(v) => v.map(|v| v.encode_fixed_vec()),
DataValue::Utf8(v) => v.clone().map(|v| v.into_bytes()),
DataValue::Utf8(v) => v.clone().map(|mut v| {
if let Some(LogicalType::Char(len)) = logical_type {
let difference = (len as usize).saturating_sub(v.len());

for _ in 0..difference {
v.push(' ')
}
}
v.into_bytes()
}),
DataValue::Date32(v) => v.map(|v| v.encode_fixed_vec()),
DataValue::Date64(v) => v.map(|v| v.encode_fixed_vec()),
DataValue::Decimal(v) => v.map(|v| v.serialize().to_vec()),
Expand Down

0 comments on commit 84b4101

Please sign in to comment.