1use std::fmt;
12
13use crate::types::LogicalType;
14
15#[derive(Debug, Clone, PartialEq)]
22#[non_exhaustive]
23pub enum Value {
24 Null,
26 Boolean(bool),
28 TinyInt(i8),
30 SmallInt(i16),
32 Integer(i32),
34 BigInt(i64),
36 HugeInt(i128),
38 UTinyInt(u8),
40 USmallInt(u16),
42 UInteger(u32),
44 UBigInt(u64),
46 UHugeInt(u128),
48 Float(f32),
50 Double(f64),
52 Decimal {
54 unscaled: i128,
56 width: u8,
58 scale: u8,
60 },
61 Varchar(String),
63 Blob(Vec<u8>),
65 Date(i32),
67 Time(i64),
69 TimeTz(i64),
75 Timestamp(i64),
77 TimestampTz(i64),
84 Interval {
90 months: i32,
92 days: i32,
94 micros: i64,
96 },
97 List {
99 element: LogicalType,
101 values: Vec<Value>,
103 },
104 Struct(Vec<(String, Value)>),
106 Map {
124 key: Box<LogicalType>,
126 value: Box<LogicalType>,
128 entries: Vec<(Value, Value)>,
130 },
131}
132
133impl Value {
134 #[must_use]
140 pub fn map(key: LogicalType, value: LogicalType, entries: Vec<(Self, Self)>) -> Self {
141 Self::Map { key: Box::new(key), value: Box::new(value), entries }
142 }
143
144 #[must_use]
155 pub fn footprint(&self) -> usize {
156 size_of::<Self>() + self.heap()
157 }
158
159 fn heap(&self) -> usize {
161 match self {
162 Self::Varchar(text) => text.capacity(),
163 Self::Blob(bytes) => bytes.capacity(),
164 Self::List { values, .. } => {
165 values.capacity() * size_of::<Self>() + values.iter().map(Self::heap).sum::<usize>()
166 }
167 Self::Struct(fields) => {
168 fields.capacity() * size_of::<(String, Self)>()
169 + fields
170 .iter()
171 .map(|(name, value)| name.capacity() + value.heap())
172 .sum::<usize>()
173 }
174 Self::Map { entries, .. } => {
178 2 * size_of::<LogicalType>()
179 + entries.capacity() * size_of::<(Self, Self)>()
180 + entries.iter().map(|(key, value)| key.heap() + value.heap()).sum::<usize>()
181 }
182 _ => 0,
183 }
184 }
185
186 #[must_use]
188 pub fn is_null(&self) -> bool {
189 matches!(self, Self::Null)
190 }
191
192 #[must_use]
194 pub fn logical_type(&self) -> LogicalType {
195 match self {
196 Self::Null => LogicalType::Null,
197 Self::Boolean(_) => LogicalType::Boolean,
198 Self::TinyInt(_) => LogicalType::TinyInt,
199 Self::SmallInt(_) => LogicalType::SmallInt,
200 Self::Integer(_) => LogicalType::Integer,
201 Self::BigInt(_) => LogicalType::BigInt,
202 Self::HugeInt(_) => LogicalType::HugeInt,
203 Self::UTinyInt(_) => LogicalType::UTinyInt,
204 Self::USmallInt(_) => LogicalType::USmallInt,
205 Self::UInteger(_) => LogicalType::UInteger,
206 Self::UBigInt(_) => LogicalType::UBigInt,
207 Self::UHugeInt(_) => LogicalType::UHugeInt,
208 Self::Float(_) => LogicalType::Float,
209 Self::Double(_) => LogicalType::Double,
210 Self::Decimal { width, scale, .. } => {
211 LogicalType::Decimal { width: *width, scale: *scale }
212 }
213 Self::Varchar(_) => LogicalType::Varchar,
214 Self::Blob(_) => LogicalType::Blob,
215 Self::Date(_) => LogicalType::Date,
216 Self::Time(_) => LogicalType::Time,
217 Self::TimeTz(_) => LogicalType::TimeTz,
218 Self::Timestamp(_) => LogicalType::Timestamp,
219 Self::TimestampTz(_) => LogicalType::TimestampTz,
220 Self::Interval { .. } => LogicalType::Interval,
221 Self::List { element, .. } => LogicalType::list(element.clone()),
222 Self::Struct(fields) => LogicalType::Struct(
223 fields
224 .iter()
225 .map(|(name, value)| crate::types::Field::new(name, value.logical_type()))
226 .collect(),
227 ),
228 Self::Map { key, value, .. } => LogicalType::Map(key.clone(), value.clone()),
229 }
230 }
231
232 #[must_use]
238 pub fn as_i64(&self) -> Option<i64> {
239 match *self {
240 Self::TinyInt(v) => Some(i64::from(v)),
241 Self::SmallInt(v) => Some(i64::from(v)),
242 Self::Integer(v) => Some(i64::from(v)),
243 Self::BigInt(v) => Some(v),
244 Self::UTinyInt(v) => Some(i64::from(v)),
245 Self::USmallInt(v) => Some(i64::from(v)),
246 Self::UInteger(v) => Some(i64::from(v)),
247 Self::UBigInt(v) => i64::try_from(v).ok(),
248 Self::HugeInt(v) => i64::try_from(v).ok(),
249 Self::UHugeInt(v) => i64::try_from(v).ok(),
250 _ => None,
251 }
252 }
253
254 #[must_use]
256 pub fn as_bool(&self) -> Option<bool> {
257 match *self {
258 Self::Boolean(v) => Some(v),
259 _ => None,
260 }
261 }
262
263 #[must_use]
265 pub fn as_str(&self) -> Option<&str> {
266 match self {
267 Self::Varchar(v) => Some(v),
268 _ => None,
269 }
270 }
271}
272
273impl fmt::Display for Value {
274 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
275 match self {
276 Self::Null => f.write_str("NULL"),
277 Self::Boolean(v) => f.write_str(if *v { "true" } else { "false" }),
278 Self::TinyInt(v) => write!(f, "{v}"),
279 Self::SmallInt(v) => write!(f, "{v}"),
280 Self::Integer(v) => write!(f, "{v}"),
281 Self::BigInt(v) => write!(f, "{v}"),
282 Self::HugeInt(v) => write!(f, "{v}"),
283 Self::UTinyInt(v) => write!(f, "{v}"),
284 Self::USmallInt(v) => write!(f, "{v}"),
285 Self::UInteger(v) => write!(f, "{v}"),
286 Self::UBigInt(v) => write!(f, "{v}"),
287 Self::UHugeInt(v) => write!(f, "{v}"),
288 Self::Float(v) => write_float(f, *v),
289 Self::Double(v) => write_float(f, *v),
290 Self::Decimal { unscaled, scale, .. } => write_decimal(f, *unscaled, *scale),
291 Self::Varchar(v) => f.write_str(v),
292 Self::Blob(v) => write_blob(f, v),
293 Self::Date(v) => write_date(f, *v),
294 Self::Time(v) => write_time(f, *v),
295 Self::TimeTz(v) => {
299 write_time(f, *v)?;
300 f.write_str(UTC)
301 }
302 Self::Timestamp(v) => write_timestamp(f, *v),
303 Self::TimestampTz(v) => {
304 write_timestamp(f, *v)?;
305 f.write_str(UTC)
306 }
307 Self::Interval { months, days, micros } => write_interval(f, *months, *days, *micros),
308 Self::List { values, .. } => {
309 f.write_str("[")?;
310 for (index, value) in values.iter().enumerate() {
311 if index > 0 {
312 f.write_str(", ")?;
313 }
314 write!(f, "{value}")?;
315 }
316 f.write_str("]")
317 }
318 Self::Struct(fields) => {
319 f.write_str("{")?;
320 for (index, (name, value)) in fields.iter().enumerate() {
321 if index > 0 {
322 f.write_str(", ")?;
323 }
324 write!(f, "'{name}': {value}")?;
325 }
326 f.write_str("}")
327 }
328 Self::Map { entries, .. } => {
332 f.write_str("{")?;
333 for (index, (key, value)) in entries.iter().enumerate() {
334 if index > 0 {
335 f.write_str(", ")?;
336 }
337 write!(f, "{key}={value}")?;
338 }
339 f.write_str("}")
340 }
341 }
342 }
343}
344
345impl Value {
346 #[must_use]
348 pub fn to_string_at_offset(&self, offset_seconds: i32) -> String {
349 let offset = offset_text(offset_seconds);
350 match self {
351 Self::TimestampTz(micros) => {
352 let local = micros.saturating_add(i64::from(offset_seconds) * 1_000_000);
353 format!("{}{offset}", Self::Timestamp(local))
354 }
355 Self::TimeTz(micros) => format!("{}{offset}", Self::Time(*micros)),
356 other => other.to_string(),
357 }
358 }
359}
360
361fn offset_text(seconds: i32) -> String {
362 let sign = if seconds < 0 { '-' } else { '+' };
363 let absolute = seconds.unsigned_abs();
364 let hours = absolute / 3600;
365 let minutes = (absolute / 60) % 60;
366 let remainder = absolute % 60;
367 if remainder != 0 {
368 format!("{sign}{hours:02}:{minutes:02}:{remainder:02}")
369 } else if minutes != 0 {
370 format!("{sign}{hours:02}:{minutes:02}")
371 } else {
372 format!("{sign}{hours:02}")
373 }
374}
375
376trait Real: Copy + fmt::Display + fmt::LowerExp {
383 fn is_nan(self) -> bool;
384 fn is_infinite(self) -> bool;
385 fn is_sign_negative(self) -> bool;
386}
387
388impl Real for f32 {
389 fn is_nan(self) -> bool {
390 Self::is_nan(self)
391 }
392
393 fn is_infinite(self) -> bool {
394 Self::is_infinite(self)
395 }
396
397 fn is_sign_negative(self) -> bool {
398 Self::is_sign_negative(self)
399 }
400}
401
402impl Real for f64 {
403 fn is_nan(self) -> bool {
404 Self::is_nan(self)
405 }
406
407 fn is_infinite(self) -> bool {
408 Self::is_infinite(self)
409 }
410
411 fn is_sign_negative(self) -> bool {
412 Self::is_sign_negative(self)
413 }
414}
415
416fn write_float<T: Real>(f: &mut fmt::Formatter<'_>, value: T) -> fmt::Result {
426 if value.is_nan() {
431 return f.write_str(if value.is_sign_negative() { "-nan" } else { "nan" });
432 }
433 if value.is_infinite() {
434 return f.write_str(if value.is_sign_negative() { "-inf" } else { "inf" });
435 }
436 let scientific = format!("{value:e}");
437 let (mantissa, exponent) = scientific.split_once('e').unwrap_or((scientific.as_str(), "0"));
438 let exponent: i32 = exponent.parse().unwrap_or(0);
439 if (-4..16).contains(&exponent) {
440 let text = format!("{value}");
441 if text.contains('.') {
442 return f.write_str(&text);
443 }
444 return write!(f, "{text}.0");
445 }
446 let sign = if exponent < 0 { '-' } else { '+' };
447 write!(f, "{mantissa}e{sign}{:02}", exponent.abs())
448}
449
450fn write_decimal(f: &mut fmt::Formatter<'_>, unscaled: i128, scale: u8) -> fmt::Result {
451 if scale == 0 {
452 return write!(f, "{unscaled}");
453 }
454 let negative = unscaled < 0;
455 let digits = unscaled.unsigned_abs().to_string();
457 let scale = usize::from(scale);
458 let (whole, fraction) = if digits.len() > scale {
459 let split = digits.len() - scale;
460 (digits[..split].to_string(), digits[split..].to_string())
461 } else {
462 ("0".to_string(), format!("{:0>scale$}", digits))
463 };
464 if negative {
465 f.write_str("-")?;
466 }
467 write!(f, "{whole}.{fraction}")
468}
469
470fn write_blob(f: &mut fmt::Formatter<'_>, bytes: &[u8]) -> fmt::Result {
477 for &byte in bytes {
478 if (byte.is_ascii_graphic() || byte == b' ') && !matches!(byte, b'\\' | b'\'' | b'"') {
479 write!(f, "{}", byte as char)?;
480 } else {
481 write!(f, "\\x{byte:02X}")?;
482 }
483 }
484 Ok(())
485}
486
487#[must_use]
494pub fn civil_from_days(days: i32) -> (i32, u32, u32) {
495 let z = i64::from(days) + 719_468;
496 let era = if z >= 0 { z } else { z - 146_096 } / 146_097;
497 let day_of_era = z - era * 146_097;
498 let year_of_era =
499 (day_of_era - day_of_era / 1460 + day_of_era / 36_524 - day_of_era / 146_096) / 365;
500 let year = year_of_era + era * 400;
501 let day_of_year = day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100);
502 let shifted_month = (5 * day_of_year + 2) / 153;
503 let day = day_of_year - (153 * shifted_month + 2) / 5 + 1;
504 let month = if shifted_month < 10 { shifted_month + 3 } else { shifted_month - 9 };
505 let year = if month <= 2 { year + 1 } else { year };
506 #[expect(clippy::cast_possible_truncation, reason = "the ranges are 1 to 12 and 1 to 31")]
507 (year as i32, month as u32, day as u32)
508}
509
510#[must_use]
525pub fn interval_micros(months: i32, days: i32, micros: i64) -> i128 {
526 const MICROS_PER_DAY: i128 = 86_400 * 1_000_000;
527 const DAYS_PER_MONTH: i128 = 30;
528 (i128::from(months) * DAYS_PER_MONTH + i128::from(days)) * MICROS_PER_DAY + i128::from(micros)
529}
530
531#[must_use]
533pub fn days_from_civil(year: i32, month: u32, day: u32) -> i32 {
534 let year = i64::from(year) - i64::from(month <= 2);
535 let era = if year >= 0 { year } else { year - 399 } / 400;
536 let year_of_era = year - era * 400;
537 let month = i64::from(month);
538 let shifted_month = if month > 2 { month - 3 } else { month + 9 };
539 let day_of_year = (153 * shifted_month + 2) / 5 + i64::from(day) - 1;
540 let day_of_era = year_of_era * 365 + year_of_era / 4 - year_of_era / 100 + day_of_year;
541 #[expect(clippy::cast_possible_truncation, reason = "a date in i32 range stays in i32 range")]
542 ((era * 146_097 + day_of_era - 719_468) as i32)
543}
544
545fn write_date(f: &mut fmt::Formatter<'_>, days: i32) -> fmt::Result {
552 let (year, month, day) = civil_from_days(days);
553 if year <= 0 {
554 write!(f, "{:04}-{month:02}-{day:02} (BC)", 1 - year)
555 } else {
556 write!(f, "{year:04}-{month:02}-{day:02}")
557 }
558}
559
560const UTC: &str = "+00";
566
567fn write_time(f: &mut fmt::Formatter<'_>, micros: i64) -> fmt::Result {
568 let seconds = micros.div_euclid(1_000_000);
569 let fraction = micros.rem_euclid(1_000_000);
570 let (hours, minutes, seconds) = (seconds / 3600, (seconds / 60) % 60, seconds % 60);
571 write!(f, "{hours:02}:{minutes:02}:{seconds:02}")?;
572 if fraction != 0 {
573 let text = format!("{fraction:06}");
575 write!(f, ".{}", text.trim_end_matches('0'))?;
576 }
577 Ok(())
578}
579
580fn write_timestamp(f: &mut fmt::Formatter<'_>, micros: i64) -> fmt::Result {
581 const MICROS_PER_DAY: i64 = 86_400 * 1_000_000;
582 let days = micros.div_euclid(MICROS_PER_DAY);
583 let within_day = micros.rem_euclid(MICROS_PER_DAY);
584 let Ok(days) = i32::try_from(days) else {
585 return f.write_str("timestamp out of range");
586 };
587 write_date(f, days)?;
588 f.write_str(" ")?;
589 write_time(f, within_day)
590}
591
592fn write_interval(f: &mut fmt::Formatter<'_>, months: i32, days: i32, micros: i64) -> fmt::Result {
593 let mut wrote = false;
594 let space = |f: &mut fmt::Formatter<'_>, wrote: &mut bool| -> fmt::Result {
595 if *wrote {
596 f.write_str(" ")?;
597 }
598 *wrote = true;
599 Ok(())
600 };
601 let (years, rest_months) = (months / 12, months % 12);
602 if years != 0 {
603 space(f, &mut wrote)?;
604 write!(f, "{years} year{}", plural(years))?;
605 }
606 if rest_months != 0 {
607 space(f, &mut wrote)?;
608 write!(f, "{rest_months} month{}", plural(rest_months))?;
609 }
610 if days != 0 {
611 space(f, &mut wrote)?;
612 write!(f, "{days} day{}", plural(days))?;
613 }
614 if micros != 0 || !wrote {
615 space(f, &mut wrote)?;
616 if micros < 0 {
617 f.write_str("-")?;
618 }
619 write_time(f, micros.abs())?;
620 }
621 Ok(())
622}
623
624fn plural(n: i32) -> &'static str {
625 if n == 1 || n == -1 { "" } else { "s" }
626}
627
628#[cfg(test)]
629mod tests {
630 use super::{Value, civil_from_days, days_from_civil};
631 use crate::types::LogicalType;
632
633 #[test]
634 fn a_value_knows_its_own_type() {
635 assert_eq!(Value::Integer(1).logical_type(), LogicalType::Integer);
636 assert_eq!(Value::Null.logical_type(), LogicalType::Null);
637 let list = Value::List { element: LogicalType::Varchar, values: Vec::new() };
638 assert_eq!(list.logical_type(), LogicalType::list(LogicalType::Varchar));
641 }
642
643 #[test]
644 fn the_date_conversion_is_its_own_inverse() {
645 for days in days_from_civil(1600, 1, 1)..days_from_civil(2400, 1, 1) {
648 let (year, month, day) = civil_from_days(days);
649 assert_eq!(days_from_civil(year, month, day), days, "{year}-{month}-{day}");
650 }
651 }
652
653 #[test]
654 fn the_epoch_is_where_it_should_be() {
655 assert_eq!(days_from_civil(1970, 1, 1), 0);
656 assert_eq!(civil_from_days(0), (1970, 1, 1));
657 assert_eq!(Value::Date(0).to_string(), "1970-01-01");
658 assert_eq!(Value::Date(19_723).to_string(), "2024-01-01");
659 assert_eq!(Value::Date(19_737).to_string(), "2024-01-15");
660 }
661
662 #[test]
663 fn a_leap_day_is_a_day() {
664 assert_eq!(civil_from_days(days_from_civil(2024, 2, 29)), (2024, 2, 29));
665 assert_eq!(days_from_civil(1900, 3, 1) - days_from_civil(1900, 2, 28), 1);
668 assert_eq!(days_from_civil(2000, 3, 1) - days_from_civil(2000, 2, 28), 2);
669 }
670
671 #[test]
672 fn a_year_at_or_before_zero_prints_in_the_era_before_christ() {
673 let date = |year, month, day| Value::Date(days_from_civil(year, month, day)).to_string();
674 assert_eq!(date(1, 1, 1), "0001-01-01");
677 assert_eq!(date(0, 1, 1), "0001-01-01 (BC)");
678 assert_eq!(date(0, 12, 31), "0001-12-31 (BC)");
679 assert_eq!(date(-1, 1, 1), "0002-01-01 (BC)");
680 assert_eq!(date(-2020, 3, 4), "2021-03-04 (BC)");
681 let timestamp = |year, month, day| {
682 Value::Timestamp(i64::from(days_from_civil(year, month, day)) * 86_400 * 1_000_000)
683 .to_string()
684 };
685 assert_eq!(timestamp(0, 1, 1), "0001-01-01 (BC) 00:00:00");
686 }
687
688 #[test]
689 fn times_print_with_the_trailing_zeros_trimmed() {
690 assert_eq!(Value::Time(0).to_string(), "00:00:00");
691 assert_eq!(Value::Time(3_723_000_000).to_string(), "01:02:03");
692 assert_eq!(Value::Time(3_723_500_000).to_string(), "01:02:03.5");
693 assert_eq!(Value::Time(3_723_000_001).to_string(), "01:02:03.000001");
694 }
695
696 #[test]
697 fn a_timestamp_before_the_epoch_borrows_from_the_day() {
698 assert_eq!(Value::Timestamp(-1).to_string(), "1969-12-31 23:59:59.999999");
701 assert_eq!(Value::Timestamp(0).to_string(), "1970-01-01 00:00:00");
702 }
703
704 #[test]
705 fn a_decimal_prints_at_its_scale() {
706 let d = |unscaled, scale| Value::Decimal { unscaled, width: 18, scale }.to_string();
707 assert_eq!(d(1234, 2), "12.34");
708 assert_eq!(d(-1234, 2), "-12.34");
709 assert_eq!(d(5, 3), "0.005");
710 assert_eq!(d(-5, 3), "-0.005");
711 assert_eq!(d(1234, 0), "1234");
712 assert_eq!(d(1_000_000, 6), "1.000000");
713 }
714
715 #[test]
716 fn a_float_keeps_the_point_that_says_it_is_one() {
717 assert_eq!(Value::Double(1.0).to_string(), "1.0");
718 assert_eq!(Value::Double(-3.0).to_string(), "-3.0");
719 assert_eq!(Value::Double(1.5).to_string(), "1.5");
720 assert_eq!(Value::Double(-0.0).to_string(), "-0.0");
721 assert_eq!(Value::Float(0.5).to_string(), "0.5");
722 }
723
724 #[test]
725 fn a_float_is_printed_from_its_own_width_rather_than_widened_first() {
726 assert_eq!(Value::Float(0.1).to_string(), "0.1");
729 assert_eq!(Value::Float(1.0).to_string(), "1.0");
730 }
731
732 #[test]
733 fn a_float_switches_to_an_exponent_where_duckdb_switches() {
734 assert_eq!(Value::Double(1e15).to_string(), "1000000000000000.0");
735 assert_eq!(Value::Double(1e16).to_string(), "1e+16");
736 assert_eq!(Value::Double(1e20).to_string(), "1e+20");
737 assert_eq!(Value::Double(1e-4).to_string(), "0.0001");
738 assert_eq!(Value::Double(1e-5).to_string(), "1e-05");
739 assert_eq!(Value::Double(1.234_567_890_123_456_8e17).to_string(), "1.2345678901234568e+17");
740 }
741
742 #[test]
743 fn a_float_that_is_not_a_number_says_so_the_way_duckdb_says_it() {
744 assert_eq!(Value::Double(f64::INFINITY).to_string(), "inf");
745 assert_eq!(Value::Double(f64::NEG_INFINITY).to_string(), "-inf");
746 assert_eq!(Value::Double(f64::NAN).to_string(), "nan");
747 assert_eq!(Value::Double(-f64::NAN).to_string(), "-nan");
752 assert_eq!(Value::Float(-f32::NAN).to_string(), "-nan");
753 }
754
755 #[test]
756 fn an_interval_keeps_months_days_and_micros_apart() {
757 let i = |months, days, micros| Value::Interval { months, days, micros }.to_string();
758 assert_eq!(i(14, 3, 3_723_000_000), "1 year 2 months 3 days 01:02:03");
759 assert_eq!(i(1, 0, 0), "1 month");
760 assert_eq!(i(0, 0, 0), "00:00:00");
761 assert_eq!(i(0, 0, -1_000_000), "-00:00:01");
762 }
763
764 #[test]
765 fn a_blob_escapes_what_is_not_printable() {
766 assert_eq!(Value::Blob(b"ok".to_vec()).to_string(), "ok");
767 assert_eq!(Value::Blob(vec![0, 1, b'a']).to_string(), "\\x00\\x01a");
768 assert_eq!(Value::Blob(vec![0x7f, 0xff]).to_string(), "\\x7F\\xFF");
769 assert_eq!(Value::Blob(br#"'"\"#.to_vec()).to_string(), "\\x27\\x22\\x5C");
771 assert_eq!(Value::Blob(b" &`~".to_vec()).to_string(), " &`~");
772 }
773
774 #[test]
775 fn a_limit_that_does_not_fit_is_none_rather_than_clamped() {
776 assert_eq!(Value::Integer(5).as_i64(), Some(5));
777 assert_eq!(Value::UBigInt(u64::MAX).as_i64(), None);
778 assert_eq!(Value::Varchar("5".into()).as_i64(), None);
779 }
780
781 #[test]
782 fn a_footprint_is_the_value_plus_what_it_owns() {
783 let bare = Value::Integer(1).footprint();
784 assert_eq!(bare, size_of::<Value>(), "a number owns nothing");
785 assert_eq!(
786 Value::Boolean(true).footprint(),
787 bare,
788 "the enum is one width whatever is in it"
789 );
790 let text = "a string long enough to be on the heap in any implementation".to_string();
791 assert_eq!(Value::Varchar(text.clone()).footprint(), bare + text.capacity());
792 let list = Value::List {
793 element: LogicalType::Varchar,
794 values: vec![Value::Varchar(text.clone())],
795 };
796 assert_eq!(list.footprint(), bare + size_of::<Value>() + text.capacity());
800 }
801
802 #[test]
806 fn a_value_is_sixty_four_bytes_and_a_map_did_not_widen_it() {
807 assert_eq!(size_of::<Value>(), 64);
808 let entries = vec![(Value::Varchar("a".to_string()), Value::Varchar("b".to_string()))];
809 let map = Value::map(LogicalType::Varchar, LogicalType::Varchar, entries);
810 assert_eq!(
813 map.footprint(),
814 size_of::<Value>() + 2 * size_of::<LogicalType>() + 2 * size_of::<Value>() + 2
815 );
816 assert_eq!(
817 map.logical_type(),
818 LogicalType::map(LogicalType::Varchar, LogicalType::Varchar)
819 );
820 }
821}