1use reifydb_type::{
5 storage::DataBitVec,
6 util::bitvec::BitVec,
7 value::{
8 Value,
9 blob::Blob,
10 date::Date,
11 datetime::DateTime,
12 decimal::Decimal,
13 dictionary::DictionaryEntryId,
14 duration::Duration,
15 identity::IdentityId,
16 int::Int,
17 time::Time,
18 uint::Uint,
19 uuid::{Uuid4, Uuid7},
20 },
21};
22
23use crate::value::column::data::{ColumnData, with_container};
24
25macro_rules! push_or_promote {
26 (@wrap_option $self:expr, $new_col:expr, $len:expr) => {
28 if $len > 0 {
29 let mut bitvec = BitVec::repeat($len, false);
30 DataBitVec::push(&mut bitvec, true);
31 *$self = ColumnData::Option {
32 inner: Box::new($new_col),
33 bitvec,
34 };
35 } else {
36 *$self = $new_col;
37 }
38 };
39 ($self:expr, $val:expr, $col_variant:ident, $factory_expr:expr) => {
41 match $self {
42 ColumnData::$col_variant(_) => $self.push($val),
43 _ => unimplemented!(),
44 }
45 };
46 (struct $self:expr, $val:expr, $col_variant:ident, $factory_expr:expr) => {
48 match $self {
49 ColumnData::$col_variant {
50 ..
51 } => $self.push($val),
52 _ => unimplemented!(),
53 }
54 };
55 (direct $self:expr, $val:expr, $col_variant:ident, $factory_expr:expr) => {
57 match $self {
58 ColumnData::$col_variant(container) => container.push($val),
59 _ => unimplemented!(),
60 }
61 };
62 (struct_direct $self:expr, $val:expr, $col_variant:ident, $factory_expr:expr) => {
64 match $self {
65 ColumnData::$col_variant {
66 container,
67 ..
68 } => container.push($val),
69 _ => unimplemented!(),
70 }
71 };
72}
73
74impl ColumnData {
75 pub fn push_value(&mut self, value: Value) {
76 if let ColumnData::Option {
78 inner,
79 bitvec,
80 } = self
81 {
82 if matches!(value, Value::None { .. }) {
83 with_container!(inner.as_mut(), |c| c.push_default());
84 DataBitVec::push(bitvec, false);
85 } else if DataBitVec::count_ones(bitvec) == 0 {
86 let len = inner.len();
88 let mut new_inner = match &value {
90 Value::Boolean(_) => ColumnData::bool(vec![false; len]),
91 Value::Float4(_) => ColumnData::float4(vec![0.0f32; len]),
92 Value::Float8(_) => ColumnData::float8(vec![0.0f64; len]),
93 Value::Int1(_) => ColumnData::int1(vec![0i8; len]),
94 Value::Int2(_) => ColumnData::int2(vec![0i16; len]),
95 Value::Int4(_) => ColumnData::int4(vec![0i32; len]),
96 Value::Int8(_) => ColumnData::int8(vec![0i64; len]),
97 Value::Int16(_) => ColumnData::int16(vec![0i128; len]),
98 Value::Uint1(_) => ColumnData::uint1(vec![0u8; len]),
99 Value::Uint2(_) => ColumnData::uint2(vec![0u16; len]),
100 Value::Uint4(_) => ColumnData::uint4(vec![0u32; len]),
101 Value::Uint8(_) => ColumnData::uint8(vec![0u64; len]),
102 Value::Uint16(_) => ColumnData::uint16(vec![0u128; len]),
103 Value::Utf8(_) => ColumnData::utf8(vec![String::new(); len]),
104 Value::Date(_) => ColumnData::date(vec![Date::default(); len]),
105 Value::DateTime(_) => ColumnData::datetime(vec![DateTime::default(); len]),
106 Value::Time(_) => ColumnData::time(vec![Time::default(); len]),
107 Value::Duration(_) => ColumnData::duration(vec![Duration::default(); len]),
108 Value::Uuid4(_) => ColumnData::uuid4(vec![Uuid4::default(); len]),
109 Value::Uuid7(_) => ColumnData::uuid7(vec![Uuid7::default(); len]),
110 Value::IdentityId(_) => {
111 ColumnData::identity_id(vec![IdentityId::default(); len])
112 }
113 Value::DictionaryId(_) => {
114 ColumnData::dictionary_id(vec![DictionaryEntryId::default(); len])
115 }
116 Value::Blob(_) => ColumnData::blob(vec![Blob::default(); len]),
117 Value::Int(_) => ColumnData::int(vec![Int::default(); len]),
118 Value::Uint(_) => ColumnData::uint(vec![Uint::default(); len]),
119 Value::Decimal(_) => ColumnData::decimal(vec![Decimal::default(); len]),
120 Value::Any(_) => ColumnData::any(vec![Box::new(Value::none()); len]),
121 _ => unreachable!(),
122 };
123 new_inner.push_value(value);
124 if len > 0 {
125 let mut new_bitvec = BitVec::repeat(len, false);
126 DataBitVec::push(&mut new_bitvec, true);
127 *self = ColumnData::Option {
128 inner: Box::new(new_inner),
129 bitvec: new_bitvec,
130 };
131 } else {
132 *self = new_inner;
133 }
134 } else {
135 inner.push_value(value);
136 DataBitVec::push(bitvec, true);
137 }
138 return;
139 }
140 match value {
141 Value::Boolean(v) => push_or_promote!(self, v, Bool, ColumnData::bool(vec![])),
142 Value::Float4(v) => push_or_promote!(self, v.value(), Float4, ColumnData::float4(vec![])),
143 Value::Float8(v) => push_or_promote!(self, v.value(), Float8, ColumnData::float8(vec![])),
144 Value::Int1(v) => push_or_promote!(self, v, Int1, ColumnData::int1(vec![])),
145 Value::Int2(v) => push_or_promote!(self, v, Int2, ColumnData::int2(vec![])),
146 Value::Int4(v) => push_or_promote!(self, v, Int4, ColumnData::int4(vec![])),
147 Value::Int8(v) => push_or_promote!(self, v, Int8, ColumnData::int8(vec![])),
148 Value::Int16(v) => push_or_promote!(self, v, Int16, ColumnData::int16(vec![])),
149 Value::Uint1(v) => push_or_promote!(self, v, Uint1, ColumnData::uint1(vec![])),
150 Value::Uint2(v) => push_or_promote!(self, v, Uint2, ColumnData::uint2(vec![])),
151 Value::Uint4(v) => push_or_promote!(self, v, Uint4, ColumnData::uint4(vec![])),
152 Value::Uint8(v) => push_or_promote!(self, v, Uint8, ColumnData::uint8(vec![])),
153 Value::Uint16(v) => push_or_promote!(self, v, Uint16, ColumnData::uint16(vec![])),
154 Value::Utf8(v) => {
155 push_or_promote!(struct self, v, Utf8, ColumnData::utf8(Vec::<String>::new()))
156 }
157 Value::Date(v) => push_or_promote!(self, v, Date, ColumnData::date(vec![])),
158 Value::DateTime(v) => push_or_promote!(self, v, DateTime, ColumnData::datetime(vec![])),
159 Value::Time(v) => push_or_promote!(self, v, Time, ColumnData::time(vec![])),
160 Value::Duration(v) => push_or_promote!(self, v, Duration, ColumnData::duration(vec![])),
161 Value::Uuid4(v) => push_or_promote!(self, v, Uuid4, ColumnData::uuid4(vec![])),
162 Value::Uuid7(v) => push_or_promote!(self, v, Uuid7, ColumnData::uuid7(vec![])),
163 Value::IdentityId(v) => {
164 push_or_promote!(direct self, v, IdentityId, ColumnData::identity_id(vec![]))
165 }
166 Value::DictionaryId(v) => {
167 push_or_promote!(direct self, v, DictionaryId, ColumnData::dictionary_id(vec![]))
168 }
169 Value::Blob(v) => push_or_promote!(struct_direct self, v, Blob, ColumnData::blob(vec![])),
170 Value::Int(v) => push_or_promote!(struct_direct self, v, Int, ColumnData::int(vec![])),
171 Value::Uint(v) => push_or_promote!(struct_direct self, v, Uint, ColumnData::uint(vec![])),
172 Value::Decimal(v) => {
173 push_or_promote!(struct_direct self, v, Decimal, ColumnData::decimal(vec![]))
174 }
175 Value::None {
176 ..
177 } => self.push_none(),
178 Value::Type(t) => self.push_value(Value::Any(Box::new(Value::Type(t)))),
179 Value::Any(v) => match self {
180 ColumnData::Any(container) => container.push(v),
181 _ => unreachable!("Cannot push Any value to non-Any column"),
182 },
183 }
184 }
185}
186
187#[cfg(test)]
188#[allow(clippy::approx_constant)]
189pub mod tests {
190 use reifydb_type::value::{
191 Value,
192 date::Date,
193 datetime::DateTime,
194 dictionary::DictionaryEntryId,
195 duration::Duration,
196 identity::IdentityId,
197 ordered_f32::OrderedF32,
198 ordered_f64::OrderedF64,
199 time::Time,
200 r#type::Type,
201 uuid::{Uuid4, Uuid7},
202 };
203
204 use crate::value::column::ColumnData;
205
206 #[test]
207 fn test_bool() {
208 let mut col = ColumnData::bool(vec![true]);
209 col.push_value(Value::Boolean(false));
210 let ColumnData::Bool(container) = col else {
211 panic!("Expected Bool");
212 };
213 assert_eq!(container.data().to_vec(), vec![true, false]);
214 }
215
216 #[test]
217 fn test_undefined_bool() {
218 let mut col = ColumnData::bool(vec![true]);
219 col.push_value(Value::none());
220 assert_eq!(col.len(), 2);
222 assert!(col.is_defined(0));
223 assert!(!col.is_defined(1));
224 }
225
226 #[test]
227 fn test_push_value_to_none_bool() {
228 let mut col = ColumnData::none_typed(Type::Boolean, 2);
229 col.push_value(Value::Boolean(true));
230 assert_eq!(col.len(), 3);
231 assert!(!col.is_defined(0));
232 assert!(!col.is_defined(1));
233 assert!(col.is_defined(2));
234 assert_eq!(col.get_value(2), Value::Boolean(true));
235 }
236
237 #[test]
238 fn test_float4() {
239 let mut col = ColumnData::float4(vec![1.0]);
240 col.push_value(Value::Float4(OrderedF32::try_from(2.0).unwrap()));
241 let ColumnData::Float4(container) = col else {
242 panic!("Expected Float4");
243 };
244 assert_eq!(container.data().as_slice(), &[1.0, 2.0]);
245 }
246
247 #[test]
248 fn test_undefined_float4() {
249 let mut col = ColumnData::float4(vec![1.0]);
250 col.push_value(Value::none());
251 assert_eq!(col.len(), 2);
252 assert!(col.is_defined(0));
253 assert!(!col.is_defined(1));
254 }
255
256 #[test]
257 fn test_push_value_to_none_float4() {
258 let mut col = ColumnData::none_typed(Type::Boolean, 1);
259 col.push_value(Value::Float4(OrderedF32::try_from(3.14).unwrap()));
260 assert_eq!(col.len(), 2);
261 assert!(!col.is_defined(0));
262 assert!(col.is_defined(1));
263 }
264
265 #[test]
266 fn test_float8() {
267 let mut col = ColumnData::float8(vec![1.0]);
268 col.push_value(Value::Float8(OrderedF64::try_from(2.0).unwrap()));
269 let ColumnData::Float8(container) = col else {
270 panic!("Expected Float8");
271 };
272 assert_eq!(container.data().as_slice(), &[1.0, 2.0]);
273 }
274
275 #[test]
276 fn test_undefined_float8() {
277 let mut col = ColumnData::float8(vec![1.0]);
278 col.push_value(Value::none());
279 assert_eq!(col.len(), 2);
280 assert!(col.is_defined(0));
281 assert!(!col.is_defined(1));
282 }
283
284 #[test]
285 fn test_push_value_to_none_float8() {
286 let mut col = ColumnData::none_typed(Type::Boolean, 1);
287 col.push_value(Value::Float8(OrderedF64::try_from(2.718).unwrap()));
288 assert_eq!(col.len(), 2);
289 assert!(!col.is_defined(0));
290 assert!(col.is_defined(1));
291 }
292
293 #[test]
294 fn test_int1() {
295 let mut col = ColumnData::int1(vec![1]);
296 col.push_value(Value::Int1(2));
297 let ColumnData::Int1(container) = col else {
298 panic!("Expected Int1");
299 };
300 assert_eq!(container.data().as_slice(), &[1, 2]);
301 }
302
303 #[test]
304 fn test_undefined_int1() {
305 let mut col = ColumnData::int1(vec![1]);
306 col.push_value(Value::none());
307 assert_eq!(col.len(), 2);
308 assert!(col.is_defined(0));
309 assert!(!col.is_defined(1));
310 }
311
312 #[test]
313 fn test_push_value_to_none_int1() {
314 let mut col = ColumnData::none_typed(Type::Boolean, 1);
315 col.push_value(Value::Int1(5));
316 assert_eq!(col.len(), 2);
317 assert!(!col.is_defined(0));
318 assert!(col.is_defined(1));
319 assert_eq!(col.get_value(1), Value::Int1(5));
320 }
321
322 #[test]
323 fn test_int2() {
324 let mut col = ColumnData::int2(vec![1]);
325 col.push_value(Value::Int2(3));
326 let ColumnData::Int2(container) = col else {
327 panic!("Expected Int2");
328 };
329 assert_eq!(container.data().as_slice(), &[1, 3]);
330 }
331
332 #[test]
333 fn test_undefined_int2() {
334 let mut col = ColumnData::int2(vec![1]);
335 col.push_value(Value::none());
336 assert_eq!(col.len(), 2);
337 assert!(col.is_defined(0));
338 assert!(!col.is_defined(1));
339 }
340
341 #[test]
342 fn test_push_value_to_none_int2() {
343 let mut col = ColumnData::none_typed(Type::Boolean, 1);
344 col.push_value(Value::Int2(10));
345 assert_eq!(col.len(), 2);
346 assert!(!col.is_defined(0));
347 assert!(col.is_defined(1));
348 assert_eq!(col.get_value(1), Value::Int2(10));
349 }
350
351 #[test]
352 fn test_int4() {
353 let mut col = ColumnData::int4(vec![10]);
354 col.push_value(Value::Int4(20));
355 let ColumnData::Int4(container) = col else {
356 panic!("Expected Int4");
357 };
358 assert_eq!(container.data().as_slice(), &[10, 20]);
359 }
360
361 #[test]
362 fn test_undefined_int4() {
363 let mut col = ColumnData::int4(vec![10]);
364 col.push_value(Value::none());
365 assert_eq!(col.len(), 2);
366 assert!(col.is_defined(0));
367 assert!(!col.is_defined(1));
368 }
369
370 #[test]
371 fn test_push_value_to_none_int4() {
372 let mut col = ColumnData::none_typed(Type::Boolean, 1);
373 col.push_value(Value::Int4(20));
374 assert_eq!(col.len(), 2);
375 assert!(!col.is_defined(0));
376 assert!(col.is_defined(1));
377 assert_eq!(col.get_value(1), Value::Int4(20));
378 }
379
380 #[test]
381 fn test_int8() {
382 let mut col = ColumnData::int8(vec![100]);
383 col.push_value(Value::Int8(200));
384 let ColumnData::Int8(container) = col else {
385 panic!("Expected Int8");
386 };
387 assert_eq!(container.data().as_slice(), &[100, 200]);
388 }
389
390 #[test]
391 fn test_undefined_int8() {
392 let mut col = ColumnData::int8(vec![100]);
393 col.push_value(Value::none());
394 assert_eq!(col.len(), 2);
395 assert!(col.is_defined(0));
396 assert!(!col.is_defined(1));
397 }
398
399 #[test]
400 fn test_push_value_to_none_int8() {
401 let mut col = ColumnData::none_typed(Type::Boolean, 1);
402 col.push_value(Value::Int8(30));
403 assert_eq!(col.len(), 2);
404 assert!(!col.is_defined(0));
405 assert!(col.is_defined(1));
406 assert_eq!(col.get_value(1), Value::Int8(30));
407 }
408
409 #[test]
410 fn test_int16() {
411 let mut col = ColumnData::int16(vec![1000]);
412 col.push_value(Value::Int16(2000));
413 let ColumnData::Int16(container) = col else {
414 panic!("Expected Int16");
415 };
416 assert_eq!(container.data().as_slice(), &[1000, 2000]);
417 }
418
419 #[test]
420 fn test_undefined_int16() {
421 let mut col = ColumnData::int16(vec![1000]);
422 col.push_value(Value::none());
423 assert_eq!(col.len(), 2);
424 assert!(col.is_defined(0));
425 assert!(!col.is_defined(1));
426 }
427
428 #[test]
429 fn test_push_value_to_none_int16() {
430 let mut col = ColumnData::none_typed(Type::Boolean, 1);
431 col.push_value(Value::Int16(40));
432 assert_eq!(col.len(), 2);
433 assert!(!col.is_defined(0));
434 assert!(col.is_defined(1));
435 assert_eq!(col.get_value(1), Value::Int16(40));
436 }
437
438 #[test]
439 fn test_uint1() {
440 let mut col = ColumnData::uint1(vec![1]);
441 col.push_value(Value::Uint1(2));
442 let ColumnData::Uint1(container) = col else {
443 panic!("Expected Uint1");
444 };
445 assert_eq!(container.data().as_slice(), &[1, 2]);
446 }
447
448 #[test]
449 fn test_undefined_uint1() {
450 let mut col = ColumnData::uint1(vec![1]);
451 col.push_value(Value::none());
452 assert_eq!(col.len(), 2);
453 assert!(col.is_defined(0));
454 assert!(!col.is_defined(1));
455 }
456
457 #[test]
458 fn test_push_value_to_none_uint1() {
459 let mut col = ColumnData::none_typed(Type::Boolean, 1);
460 col.push_value(Value::Uint1(1));
461 assert_eq!(col.len(), 2);
462 assert!(!col.is_defined(0));
463 assert!(col.is_defined(1));
464 assert_eq!(col.get_value(1), Value::Uint1(1));
465 }
466
467 #[test]
468 fn test_uint2() {
469 let mut col = ColumnData::uint2(vec![10]);
470 col.push_value(Value::Uint2(20));
471 let ColumnData::Uint2(container) = col else {
472 panic!("Expected Uint2");
473 };
474 assert_eq!(container.data().as_slice(), &[10, 20]);
475 }
476
477 #[test]
478 fn test_undefined_uint2() {
479 let mut col = ColumnData::uint2(vec![10]);
480 col.push_value(Value::none());
481 assert_eq!(col.len(), 2);
482 assert!(col.is_defined(0));
483 assert!(!col.is_defined(1));
484 }
485
486 #[test]
487 fn test_push_value_to_none_uint2() {
488 let mut col = ColumnData::none_typed(Type::Boolean, 1);
489 col.push_value(Value::Uint2(2));
490 assert_eq!(col.len(), 2);
491 assert!(!col.is_defined(0));
492 assert!(col.is_defined(1));
493 assert_eq!(col.get_value(1), Value::Uint2(2));
494 }
495
496 #[test]
497 fn test_uint4() {
498 let mut col = ColumnData::uint4(vec![100]);
499 col.push_value(Value::Uint4(200));
500 let ColumnData::Uint4(container) = col else {
501 panic!("Expected Uint4");
502 };
503 assert_eq!(container.data().as_slice(), &[100, 200]);
504 }
505
506 #[test]
507 fn test_undefined_uint4() {
508 let mut col = ColumnData::uint4(vec![100]);
509 col.push_value(Value::none());
510 assert_eq!(col.len(), 2);
511 assert!(col.is_defined(0));
512 assert!(!col.is_defined(1));
513 }
514
515 #[test]
516 fn test_push_value_to_none_uint4() {
517 let mut col = ColumnData::none_typed(Type::Boolean, 1);
518 col.push_value(Value::Uint4(3));
519 assert_eq!(col.len(), 2);
520 assert!(!col.is_defined(0));
521 assert!(col.is_defined(1));
522 assert_eq!(col.get_value(1), Value::Uint4(3));
523 }
524
525 #[test]
526 fn test_uint8() {
527 let mut col = ColumnData::uint8(vec![1000]);
528 col.push_value(Value::Uint8(2000));
529 let ColumnData::Uint8(container) = col else {
530 panic!("Expected Uint8");
531 };
532 assert_eq!(container.data().as_slice(), &[1000, 2000]);
533 }
534
535 #[test]
536 fn test_undefined_uint8() {
537 let mut col = ColumnData::uint8(vec![1000]);
538 col.push_value(Value::none());
539 assert_eq!(col.len(), 2);
540 assert!(col.is_defined(0));
541 assert!(!col.is_defined(1));
542 }
543
544 #[test]
545 fn test_push_value_to_none_uint8() {
546 let mut col = ColumnData::none_typed(Type::Boolean, 1);
547 col.push_value(Value::Uint8(4));
548 assert_eq!(col.len(), 2);
549 assert!(!col.is_defined(0));
550 assert!(col.is_defined(1));
551 assert_eq!(col.get_value(1), Value::Uint8(4));
552 }
553
554 #[test]
555 fn test_uint16() {
556 let mut col = ColumnData::uint16(vec![10000]);
557 col.push_value(Value::Uint16(20000));
558 let ColumnData::Uint16(container) = col else {
559 panic!("Expected Uint16");
560 };
561 assert_eq!(container.data().as_slice(), &[10000, 20000]);
562 }
563
564 #[test]
565 fn test_undefined_uint16() {
566 let mut col = ColumnData::uint16(vec![10000]);
567 col.push_value(Value::none());
568 assert_eq!(col.len(), 2);
569 assert!(col.is_defined(0));
570 assert!(!col.is_defined(1));
571 }
572
573 #[test]
574 fn test_push_value_to_none_uint16() {
575 let mut col = ColumnData::none_typed(Type::Boolean, 1);
576 col.push_value(Value::Uint16(5));
577 assert_eq!(col.len(), 2);
578 assert!(!col.is_defined(0));
579 assert!(col.is_defined(1));
580 assert_eq!(col.get_value(1), Value::Uint16(5));
581 }
582
583 #[test]
584 fn test_utf8() {
585 let mut col = ColumnData::utf8(vec!["hello".to_string()]);
586 col.push_value(Value::Utf8("world".to_string()));
587 let ColumnData::Utf8 {
588 container,
589 ..
590 } = col
591 else {
592 panic!("Expected Utf8");
593 };
594 assert_eq!(container.data().as_slice(), &["hello".to_string(), "world".to_string()]);
595 }
596
597 #[test]
598 fn test_undefined_utf8() {
599 let mut col = ColumnData::utf8(vec!["hello".to_string()]);
600 col.push_value(Value::none());
601 assert_eq!(col.len(), 2);
602 assert!(col.is_defined(0));
603 assert!(!col.is_defined(1));
604 }
605
606 #[test]
607 fn test_push_value_to_none_utf8() {
608 let mut col = ColumnData::none_typed(Type::Boolean, 1);
609 col.push_value(Value::Utf8("ok".to_string()));
610 assert_eq!(col.len(), 2);
611 assert!(!col.is_defined(0));
612 assert!(col.is_defined(1));
613 assert_eq!(col.get_value(1), Value::Utf8("ok".to_string()));
614 }
615
616 #[test]
617 fn test_undefined() {
618 let mut col = ColumnData::int2(vec![1]);
619 col.push_value(Value::none());
620 assert_eq!(col.len(), 2);
621 assert!(col.is_defined(0));
622 assert!(!col.is_defined(1));
623 }
624
625 #[test]
626 fn test_date() {
627 let date1 = Date::from_ymd(2023, 1, 1).unwrap();
628 let date2 = Date::from_ymd(2023, 12, 31).unwrap();
629 let mut col = ColumnData::date(vec![date1]);
630 col.push_value(Value::Date(date2));
631 let ColumnData::Date(container) = col else {
632 panic!("Expected Date");
633 };
634 assert_eq!(container.data().as_slice(), &[date1, date2]);
635 }
636
637 #[test]
638 fn test_undefined_date() {
639 let date1 = Date::from_ymd(2023, 1, 1).unwrap();
640 let mut col = ColumnData::date(vec![date1]);
641 col.push_value(Value::none());
642 assert_eq!(col.len(), 2);
643 assert!(col.is_defined(0));
644 assert!(!col.is_defined(1));
645 }
646
647 #[test]
648 fn test_push_value_to_none_date() {
649 let date = Date::from_ymd(2023, 6, 15).unwrap();
650 let mut col = ColumnData::none_typed(Type::Boolean, 1);
651 col.push_value(Value::Date(date));
652 assert_eq!(col.len(), 2);
653 assert!(!col.is_defined(0));
654 assert!(col.is_defined(1));
655 assert_eq!(col.get_value(1), Value::Date(date));
656 }
657
658 #[test]
659 fn test_datetime() {
660 let dt1 = DateTime::from_timestamp(1672531200).unwrap(); let dt2 = DateTime::from_timestamp(1704067200).unwrap(); let mut col = ColumnData::datetime(vec![dt1]);
663 col.push_value(Value::DateTime(dt2));
664 let ColumnData::DateTime(container) = col else {
665 panic!("Expected DateTime");
666 };
667 assert_eq!(container.data().as_slice(), &[dt1, dt2]);
668 }
669
670 #[test]
671 fn test_undefined_datetime() {
672 let dt1 = DateTime::from_timestamp(1672531200).unwrap();
673 let mut col = ColumnData::datetime(vec![dt1]);
674 col.push_value(Value::none());
675 assert_eq!(col.len(), 2);
676 assert!(col.is_defined(0));
677 assert!(!col.is_defined(1));
678 }
679
680 #[test]
681 fn test_push_value_to_none_datetime() {
682 let dt = DateTime::from_timestamp(1672531200).unwrap();
683 let mut col = ColumnData::none_typed(Type::Boolean, 1);
684 col.push_value(Value::DateTime(dt));
685 assert_eq!(col.len(), 2);
686 assert!(!col.is_defined(0));
687 assert!(col.is_defined(1));
688 assert_eq!(col.get_value(1), Value::DateTime(dt));
689 }
690
691 #[test]
692 fn test_time() {
693 let time1 = Time::from_hms(12, 30, 0).unwrap();
694 let time2 = Time::from_hms(18, 45, 30).unwrap();
695 let mut col = ColumnData::time(vec![time1]);
696 col.push_value(Value::Time(time2));
697 let ColumnData::Time(container) = col else {
698 panic!("Expected Time");
699 };
700 assert_eq!(container.data().as_slice(), &[time1, time2]);
701 }
702
703 #[test]
704 fn test_undefined_time() {
705 let time1 = Time::from_hms(12, 30, 0).unwrap();
706 let mut col = ColumnData::time(vec![time1]);
707 col.push_value(Value::none());
708 assert_eq!(col.len(), 2);
709 assert!(col.is_defined(0));
710 assert!(!col.is_defined(1));
711 }
712
713 #[test]
714 fn test_push_value_to_none_time() {
715 let time = Time::from_hms(15, 20, 10).unwrap();
716 let mut col = ColumnData::none_typed(Type::Boolean, 1);
717 col.push_value(Value::Time(time));
718 assert_eq!(col.len(), 2);
719 assert!(!col.is_defined(0));
720 assert!(col.is_defined(1));
721 assert_eq!(col.get_value(1), Value::Time(time));
722 }
723
724 #[test]
725 fn test_duration() {
726 let duration1 = Duration::from_days(30);
727 let duration2 = Duration::from_hours(24);
728 let mut col = ColumnData::duration(vec![duration1]);
729 col.push_value(Value::Duration(duration2));
730 let ColumnData::Duration(container) = col else {
731 panic!("Expected Duration");
732 };
733 assert_eq!(container.data().as_slice(), &[duration1, duration2]);
734 }
735
736 #[test]
737 fn test_undefined_duration() {
738 let duration1 = Duration::from_days(30);
739 let mut col = ColumnData::duration(vec![duration1]);
740 col.push_value(Value::none());
741 assert_eq!(col.len(), 2);
742 assert!(col.is_defined(0));
743 assert!(!col.is_defined(1));
744 }
745
746 #[test]
747 fn test_push_value_to_none_duration() {
748 let duration = Duration::from_minutes(90);
749 let mut col = ColumnData::none_typed(Type::Boolean, 1);
750 col.push_value(Value::Duration(duration));
751 assert_eq!(col.len(), 2);
752 assert!(!col.is_defined(0));
753 assert!(col.is_defined(1));
754 assert_eq!(col.get_value(1), Value::Duration(duration));
755 }
756
757 #[test]
758 fn test_identity_id() {
759 let id1 = IdentityId::generate();
760 let id2 = IdentityId::generate();
761 let mut col = ColumnData::identity_id(vec![id1]);
762 col.push_value(Value::IdentityId(id2));
763 let ColumnData::IdentityId(container) = col else {
764 panic!("Expected IdentityId");
765 };
766 assert_eq!(container.data().as_slice(), &[id1, id2]);
767 }
768
769 #[test]
770 fn test_undefined_identity_id() {
771 let id1 = IdentityId::generate();
772 let mut col = ColumnData::identity_id(vec![id1]);
773 col.push_value(Value::none());
774 assert_eq!(col.len(), 2);
775 assert!(col.is_defined(0));
776 assert!(!col.is_defined(1));
777 }
778
779 #[test]
780 fn test_push_value_to_none_identity_id() {
781 let id = IdentityId::generate();
782 let mut col = ColumnData::none_typed(Type::Boolean, 1);
783 col.push_value(Value::IdentityId(id));
784 assert_eq!(col.len(), 2);
785 assert!(!col.is_defined(0));
786 assert!(col.is_defined(1));
787 assert_eq!(col.get_value(1), Value::IdentityId(id));
788 }
789
790 #[test]
791 fn test_uuid4() {
792 let uuid1 = Uuid4::generate();
793 let uuid2 = Uuid4::generate();
794 let mut col = ColumnData::uuid4(vec![uuid1]);
795 col.push_value(Value::Uuid4(uuid2));
796 let ColumnData::Uuid4(container) = col else {
797 panic!("Expected Uuid4");
798 };
799 assert_eq!(container.data().as_slice(), &[uuid1, uuid2]);
800 }
801
802 #[test]
803 fn test_undefined_uuid4() {
804 let uuid1 = Uuid4::generate();
805 let mut col = ColumnData::uuid4(vec![uuid1]);
806 col.push_value(Value::none());
807 assert_eq!(col.len(), 2);
808 assert!(col.is_defined(0));
809 assert!(!col.is_defined(1));
810 }
811
812 #[test]
813 fn test_push_value_to_none_uuid4() {
814 let uuid = Uuid4::generate();
815 let mut col = ColumnData::none_typed(Type::Boolean, 1);
816 col.push_value(Value::Uuid4(uuid));
817 assert_eq!(col.len(), 2);
818 assert!(!col.is_defined(0));
819 assert!(col.is_defined(1));
820 assert_eq!(col.get_value(1), Value::Uuid4(uuid));
821 }
822
823 #[test]
824 fn test_uuid7() {
825 let uuid1 = Uuid7::generate();
826 let uuid2 = Uuid7::generate();
827 let mut col = ColumnData::uuid7(vec![uuid1]);
828 col.push_value(Value::Uuid7(uuid2));
829 let ColumnData::Uuid7(container) = col else {
830 panic!("Expected Uuid7");
831 };
832 assert_eq!(container.data().as_slice(), &[uuid1, uuid2]);
833 }
834
835 #[test]
836 fn test_undefined_uuid7() {
837 let uuid1 = Uuid7::generate();
838 let mut col = ColumnData::uuid7(vec![uuid1]);
839 col.push_value(Value::none());
840 assert_eq!(col.len(), 2);
841 assert!(col.is_defined(0));
842 assert!(!col.is_defined(1));
843 }
844
845 #[test]
846 fn test_push_value_to_none_uuid7() {
847 let uuid = Uuid7::generate();
848 let mut col = ColumnData::none_typed(Type::Boolean, 1);
849 col.push_value(Value::Uuid7(uuid));
850 assert_eq!(col.len(), 2);
851 assert!(!col.is_defined(0));
852 assert!(col.is_defined(1));
853 assert_eq!(col.get_value(1), Value::Uuid7(uuid));
854 }
855
856 #[test]
857 fn test_dictionary_id() {
858 let e1 = DictionaryEntryId::U4(10);
859 let e2 = DictionaryEntryId::U4(20);
860 let mut col = ColumnData::dictionary_id(vec![e1]);
861 col.push_value(Value::DictionaryId(e2));
862 let ColumnData::DictionaryId(container) = col else {
863 panic!("Expected DictionaryId");
864 };
865 assert_eq!(container.data().as_slice(), &[e1, e2]);
866 }
867
868 #[test]
869 fn test_undefined_dictionary_id() {
870 let e1 = DictionaryEntryId::U4(10);
871 let mut col = ColumnData::dictionary_id(vec![e1]);
872 col.push_value(Value::none());
873 assert_eq!(col.len(), 2);
874 assert!(col.is_defined(0));
875 assert!(!col.is_defined(1));
876 }
877
878 #[test]
879 fn test_push_value_to_none_dictionary_id() {
880 let e = DictionaryEntryId::U4(42);
881 let mut col = ColumnData::none_typed(Type::Boolean, 1);
882 col.push_value(Value::DictionaryId(e));
883 assert_eq!(col.len(), 2);
884 assert!(!col.is_defined(0));
885 assert!(col.is_defined(1));
886 assert_eq!(col.get_value(1), Value::DictionaryId(e));
887 }
888}