Skip to content

Commit

Permalink
chore: cr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
QuenKar committed Oct 18, 2023
1 parent 941680b commit edee847
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/datatypes/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use std::cmp::Ordering;
use std::fmt::{Display, Formatter};
use std::mem::size_of;
use std::str::FromStr;
use std::sync::Arc;

Expand Down Expand Up @@ -656,14 +655,15 @@ impl ListValue {
))
}

fn byte_size(&self) -> usize {
let mut size = size_of::<ConcreteDataType>();
if let Some(items) = self.items() {
for item in items.iter() {
size += item.as_value_ref().byte_size();
/// use 'the first item size' * 'length of items' to estimate the size.
/// it could be inaccurate.
fn estimated_size(&self) -> usize {
if let Some(items) = &self.items {
if let Some(item) = items.first() {
return item.as_value_ref().data_size() * items.len();
}
}
size
0
}
}

Expand Down Expand Up @@ -1102,7 +1102,9 @@ impl<'a> PartialOrd for ListValueRef<'a> {
}

impl<'a> ValueRef<'a> {
pub fn byte_size(&self) -> usize {
/// Returns the size of the underlying data in bytes,
/// The size is estimated and only considers the data size.
pub fn data_size(&self) -> usize {
match *self {
ValueRef::Null => 0,
ValueRef::Boolean(_) => 1,
Expand All @@ -1125,8 +1127,8 @@ impl<'a> ValueRef<'a> {
ValueRef::Duration(_) => 16,
ValueRef::Interval(_) => 24,
ValueRef::List(v) => match v {
ListValueRef::Indexed { vector, idx } => vector.get(idx).as_value_ref().byte_size(),
ListValueRef::Ref { val } => val.byte_size(),
ListValueRef::Indexed { vector, .. } => vector.memory_size() / vector.len(),
ListValueRef::Ref { val } => val.estimated_size(),
},
}
}
Expand Down Expand Up @@ -2203,7 +2205,7 @@ mod tests {
}

fn check_value_ref_size_eq(value_ref: &ValueRef, size: usize) {
assert_eq!(value_ref.byte_size(), size);
assert_eq!(value_ref.data_size(), size);
}

#[test]
Expand Down Expand Up @@ -2242,7 +2244,7 @@ mod tests {
datatype: ConcreteDataType::string_datatype(),
},
}),
11 + 10 + 24,
22,
);

let data = vec![
Expand Down Expand Up @@ -2270,21 +2272,21 @@ mod tests {
vector: &vector,
idx: 0,
}),
36,
85,
);
check_value_ref_size_eq(
&ValueRef::List(ListValueRef::Indexed {
vector: &vector,
idx: 1,
}),
0,
85,
);
check_value_ref_size_eq(
&ValueRef::List(ListValueRef::Indexed {
vector: &vector,
idx: 2,
}),
32,
85,
)
}
}

0 comments on commit edee847

Please sign in to comment.