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