Skip to main content

reifydb_core/value/column/transform/
append.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2026 ReifyDB
3
4use reifydb_value::{
5	Result,
6	storage::DataBitVec,
7	util::bitvec::BitVec,
8	value::{
9		Value,
10		blob::Blob,
11		constraint::Constraint,
12		date::Date,
13		datetime::DateTime,
14		decimal::Decimal,
15		duration::Duration,
16		int::Int,
17		row_number::RowNumber,
18		time::Time,
19		uint::Uint,
20		uuid::{Uuid4, Uuid7},
21		value_type::ValueType,
22	},
23};
24use uuid::Uuid;
25
26use crate::{
27	encoded::{row::EncodedRow, shape::RowShape},
28	error::CoreError,
29	value::column::{ColumnBuffer, columns::Columns},
30};
31
32impl Columns {
33	pub fn append_columns(&mut self, other: Columns) -> Result<()> {
34		if self.len() != other.len() {
35			return Err(CoreError::FrameError {
36				message: "mismatched column count".to_string(),
37			}
38			.into());
39		}
40
41		if !other.row_numbers.is_empty() {
42			self.row_numbers.make_mut().extend(other.row_numbers.iter().copied());
43		}
44		if !other.created_at.is_empty() {
45			self.created_at.make_mut().extend(other.created_at.iter().copied());
46		}
47		if !other.updated_at.is_empty() {
48			self.updated_at.make_mut().extend(other.updated_at.iter().copied());
49		}
50
51		for i in 0..self.columns.len() {
52			let self_name = self.names[i].text().to_string();
53			let other_name = other.names[i].text().to_string();
54			if self_name != other_name {
55				return Err(CoreError::FrameError {
56					message: format!(
57						"column name mismatch at index {}: '{}' vs '{}'",
58						i, self_name, other_name,
59					),
60				}
61				.into());
62			}
63			let other_data = other.columns[i].clone();
64			self.columns.make_mut()[i].extend(other_data)?;
65		}
66		Ok(())
67	}
68}
69
70impl Columns {
71	pub fn append_rows(
72		&mut self,
73		shape: &RowShape,
74		rows: impl IntoIterator<Item = EncodedRow>,
75		row_numbers: Vec<RowNumber>,
76	) -> Result<()> {
77		if self.len() != shape.field_count() {
78			return Err(CoreError::FrameError {
79				message: format!(
80					"mismatched column count: expected {}, got {}",
81					self.len(),
82					shape.field_count()
83				),
84			}
85			.into());
86		}
87
88		let rows: Vec<EncodedRow> = rows.into_iter().collect();
89
90		if !row_numbers.is_empty() && row_numbers.len() != rows.len() {
91			return Err(CoreError::FrameError {
92				message: format!(
93					"row_numbers length {} does not match rows length {}",
94					row_numbers.len(),
95					rows.len()
96				),
97			}
98			.into());
99		}
100
101		if !row_numbers.is_empty() {
102			self.row_numbers.make_mut().extend(row_numbers);
103		}
104
105		for row in &rows {
106			self.created_at.make_mut().push(DateTime::from_nanos(row.created_at_nanos()));
107			self.updated_at.make_mut().push(DateTime::from_nanos(row.updated_at_nanos()));
108		}
109
110		let columns = self.columns.make_mut();
111		for (index, column) in columns.iter_mut().enumerate() {
112			let field = shape.get_field(index).unwrap();
113			let is_all_none = if let ColumnBuffer::Option {
114				bitvec,
115				..
116			} = &*column
117			{
118				DataBitVec::count_ones(bitvec) == 0
119			} else {
120				false
121			};
122			if is_all_none {
123				let size = column.len();
124				let new_data = match field.constraint.get_type() {
125					ValueType::Boolean => ColumnBuffer::bool_with_bitvec(
126						vec![false; size],
127						BitVec::repeat(size, false),
128					),
129					ValueType::Float4 => ColumnBuffer::float4_with_bitvec(
130						vec![0.0f32; size],
131						BitVec::repeat(size, false),
132					),
133					ValueType::Float8 => ColumnBuffer::float8_with_bitvec(
134						vec![0.0f64; size],
135						BitVec::repeat(size, false),
136					),
137					ValueType::Int1 => ColumnBuffer::int1_with_bitvec(
138						vec![0i8; size],
139						BitVec::repeat(size, false),
140					),
141					ValueType::Int2 => ColumnBuffer::int2_with_bitvec(
142						vec![0i16; size],
143						BitVec::repeat(size, false),
144					),
145					ValueType::Int4 => ColumnBuffer::int4_with_bitvec(
146						vec![0i32; size],
147						BitVec::repeat(size, false),
148					),
149					ValueType::Int8 => ColumnBuffer::int8_with_bitvec(
150						vec![0i64; size],
151						BitVec::repeat(size, false),
152					),
153					ValueType::Int16 => ColumnBuffer::int16_with_bitvec(
154						vec![0i128; size],
155						BitVec::repeat(size, false),
156					),
157					ValueType::Utf8 => ColumnBuffer::utf8_with_bitvec(
158						vec![String::new(); size],
159						BitVec::repeat(size, false),
160					),
161					ValueType::Uint1 => ColumnBuffer::uint1_with_bitvec(
162						vec![0u8; size],
163						BitVec::repeat(size, false),
164					),
165					ValueType::Uint2 => ColumnBuffer::uint2_with_bitvec(
166						vec![0u16; size],
167						BitVec::repeat(size, false),
168					),
169					ValueType::Uint4 => ColumnBuffer::uint4_with_bitvec(
170						vec![0u32; size],
171						BitVec::repeat(size, false),
172					),
173					ValueType::Uint8 => ColumnBuffer::uint8_with_bitvec(
174						vec![0u64; size],
175						BitVec::repeat(size, false),
176					),
177					ValueType::Uint16 => ColumnBuffer::uint16_with_bitvec(
178						vec![0u128; size],
179						BitVec::repeat(size, false),
180					),
181					ValueType::Date => ColumnBuffer::date_with_bitvec(
182						vec![Date::default(); size],
183						BitVec::repeat(size, false),
184					),
185					ValueType::DateTime => ColumnBuffer::datetime_with_bitvec(
186						vec![DateTime::default(); size],
187						BitVec::repeat(size, false),
188					),
189					ValueType::Time => ColumnBuffer::time_with_bitvec(
190						vec![Time::default(); size],
191						BitVec::repeat(size, false),
192					),
193					ValueType::Duration => ColumnBuffer::duration_with_bitvec(
194						vec![Duration::default(); size],
195						BitVec::repeat(size, false),
196					),
197					ValueType::Option(_) => column.clone(),
198					ValueType::IdentityId => ColumnBuffer::identity_id_with_bitvec(
199						vec![Default::default(); size],
200						BitVec::repeat(size, false),
201					),
202					ValueType::Uuid4 => ColumnBuffer::uuid4_with_bitvec(
203						vec![Uuid4::from(Uuid::nil()); size],
204						BitVec::repeat(size, false),
205					),
206					ValueType::Uuid7 => ColumnBuffer::uuid7_with_bitvec(
207						vec![Uuid7::from(Uuid::nil()); size],
208						BitVec::repeat(size, false),
209					),
210					ValueType::Blob => ColumnBuffer::blob_with_bitvec(
211						vec![Blob::new(vec![]); size],
212						BitVec::repeat(size, false),
213					),
214					ValueType::Int => ColumnBuffer::int_with_bitvec(
215						vec![Int::default(); size],
216						BitVec::repeat(size, false),
217					),
218					ValueType::Uint => ColumnBuffer::uint_with_bitvec(
219						vec![Uint::default(); size],
220						BitVec::repeat(size, false),
221					),
222					ValueType::Decimal => ColumnBuffer::decimal_with_bitvec(
223						vec![Decimal::from(0); size],
224						BitVec::repeat(size, false),
225					),
226					ValueType::DictionaryId => {
227						let mut col_data = ColumnBuffer::dictionary_id_with_bitvec(
228							vec![Default::default(); size],
229							BitVec::repeat(size, false),
230						);
231						if let ColumnBuffer::DictionaryId(container) = &mut col_data
232							&& let Some(Constraint::Dictionary(dict_id, _)) =
233								field.constraint.constraint()
234						{
235							container.set_dictionary_id(*dict_id);
236						}
237						col_data
238					}
239					ValueType::Any
240					| ValueType::List(_)
241					| ValueType::Record(_)
242					| ValueType::Tuple(_) => ColumnBuffer::any_with_bitvec(
243						vec![Box::new(Value::none()); size],
244						BitVec::repeat(size, false),
245					),
246				};
247
248				*column = new_data;
249			}
250
251			if let ColumnBuffer::DictionaryId(container) = &mut *column
252				&& container.dictionary_id().is_none()
253				&& let Some(Constraint::Dictionary(dict_id, _)) = field.constraint.constraint()
254			{
255				container.set_dictionary_id(*dict_id);
256			}
257		}
258
259		for row in &rows {
260			let all_defined = (0..shape.field_count()).all(|i| row.is_defined(i));
261
262			if all_defined {
263				self.append_all_defined_from_shape(shape, row)?;
264			} else {
265				self.append_fallback_from_shape(shape, row)?;
266			}
267		}
268
269		Ok(())
270	}
271
272	fn append_all_defined_from_shape(&mut self, shape: &RowShape, row: &EncodedRow) -> Result<()> {
273		let names_snapshot: Vec<String> = self.names.iter().map(|n| n.text().to_string()).collect();
274		let columns = self.columns.make_mut();
275		for (index, column) in columns.iter_mut().enumerate() {
276			let field = shape.get_field(index).unwrap();
277			match (&mut *column, field.constraint.get_type()) {
278				(
279					ColumnBuffer::Option {
280						inner,
281						bitvec,
282					},
283					_ty,
284				) => {
285					let value = shape.get_value(row, index);
286					if matches!(value, Value::None { .. }) {
287						inner.push_none();
288						DataBitVec::push(bitvec, false);
289					} else {
290						inner.push_value(value);
291						DataBitVec::push(bitvec, true);
292					}
293				}
294				(ColumnBuffer::Bool(container), ValueType::Boolean) => {
295					container.push(shape.get_bool(row, index));
296				}
297				(ColumnBuffer::Float4(container), ValueType::Float4) => {
298					container.push(shape.get_f32(row, index));
299				}
300				(ColumnBuffer::Float8(container), ValueType::Float8) => {
301					container.push(shape.get_f64(row, index));
302				}
303				(ColumnBuffer::Int1(container), ValueType::Int1) => {
304					container.push(shape.get_i8(row, index));
305				}
306				(ColumnBuffer::Int2(container), ValueType::Int2) => {
307					container.push(shape.get_i16(row, index));
308				}
309				(ColumnBuffer::Int4(container), ValueType::Int4) => {
310					container.push(shape.get_i32(row, index));
311				}
312				(ColumnBuffer::Int8(container), ValueType::Int8) => {
313					container.push(shape.get_i64(row, index));
314				}
315				(ColumnBuffer::Int16(container), ValueType::Int16) => {
316					container.push(shape.get_i128(row, index));
317				}
318				(
319					ColumnBuffer::Utf8 {
320						container,
321						..
322					},
323					ValueType::Utf8,
324				) => {
325					container.push(shape.get_utf8(row, index).to_string());
326				}
327				(ColumnBuffer::Uint1(container), ValueType::Uint1) => {
328					container.push(shape.get_u8(row, index));
329				}
330				(ColumnBuffer::Uint2(container), ValueType::Uint2) => {
331					container.push(shape.get_u16(row, index));
332				}
333				(ColumnBuffer::Uint4(container), ValueType::Uint4) => {
334					container.push(shape.get_u32(row, index));
335				}
336				(ColumnBuffer::Uint8(container), ValueType::Uint8) => {
337					container.push(shape.get_u64(row, index));
338				}
339				(ColumnBuffer::Uint16(container), ValueType::Uint16) => {
340					container.push(shape.get_u128(row, index));
341				}
342				(ColumnBuffer::Date(container), ValueType::Date) => {
343					container.push(shape.get_date(row, index));
344				}
345				(ColumnBuffer::DateTime(container), ValueType::DateTime) => {
346					container.push(shape.get_datetime(row, index));
347				}
348				(ColumnBuffer::Time(container), ValueType::Time) => {
349					container.push(shape.get_time(row, index));
350				}
351				(ColumnBuffer::Duration(container), ValueType::Duration) => {
352					container.push(shape.get_duration(row, index));
353				}
354				(ColumnBuffer::Uuid4(container), ValueType::Uuid4) => {
355					container.push(shape.get_uuid4(row, index));
356				}
357				(ColumnBuffer::Uuid7(container), ValueType::Uuid7) => {
358					container.push(shape.get_uuid7(row, index));
359				}
360				(ColumnBuffer::IdentityId(container), ValueType::IdentityId) => {
361					container.push(shape.get_identity_id(row, index));
362				}
363				(
364					ColumnBuffer::Blob {
365						container,
366						..
367					},
368					ValueType::Blob,
369				) => {
370					container.push(shape.get_blob(row, index));
371				}
372				(
373					ColumnBuffer::Int {
374						container,
375						..
376					},
377					ValueType::Int,
378				) => {
379					container.push(shape.get_int(row, index));
380				}
381				(
382					ColumnBuffer::Uint {
383						container,
384						..
385					},
386					ValueType::Uint,
387				) => {
388					container.push(shape.get_uint(row, index));
389				}
390				(
391					ColumnBuffer::Decimal {
392						container,
393						..
394					},
395					ValueType::Decimal,
396				) => {
397					container.push(shape.get_decimal(row, index));
398				}
399				(ColumnBuffer::DictionaryId(container), ValueType::DictionaryId) => {
400					match shape.get_value(row, index) {
401						Value::DictionaryId(id) => container.push(id),
402						_ => container.push_default(),
403					}
404				}
405				(_, v) => {
406					return Err(CoreError::FrameError {
407						message: format!(
408							"type mismatch for column '{}'({}): incompatible with value {}",
409							names_snapshot[index],
410							column.get_type(),
411							v
412						),
413					}
414					.into());
415				}
416			}
417		}
418		Ok(())
419	}
420
421	fn append_fallback_from_shape(&mut self, shape: &RowShape, row: &EncodedRow) -> Result<()> {
422		let columns = self.columns.make_mut();
423		for (index, column) in columns.iter_mut().enumerate() {
424			let field = shape.get_field(index).unwrap();
425
426			if !row.is_defined(index) {
427				column.push_none();
428				continue;
429			}
430
431			match (&mut *column, field.constraint.get_type()) {
432				(
433					ColumnBuffer::Option {
434						inner,
435						bitvec,
436					},
437					_ty,
438				) => {
439					let value = shape.get_value(row, index);
440					inner.push_value(value);
441					DataBitVec::push(bitvec, true);
442				}
443				(ColumnBuffer::Bool(container), ValueType::Boolean) => {
444					container.push(shape.get_bool(row, index));
445				}
446				(ColumnBuffer::Float4(container), ValueType::Float4) => {
447					container.push(shape.get_f32(row, index));
448				}
449				(ColumnBuffer::Float8(container), ValueType::Float8) => {
450					container.push(shape.get_f64(row, index));
451				}
452				(ColumnBuffer::Int1(container), ValueType::Int1) => {
453					container.push(shape.get_i8(row, index));
454				}
455				(ColumnBuffer::Int2(container), ValueType::Int2) => {
456					container.push(shape.get_i16(row, index));
457				}
458				(ColumnBuffer::Int4(container), ValueType::Int4) => {
459					container.push(shape.get_i32(row, index));
460				}
461				(ColumnBuffer::Int8(container), ValueType::Int8) => {
462					container.push(shape.get_i64(row, index));
463				}
464				(ColumnBuffer::Int16(container), ValueType::Int16) => {
465					container.push(shape.get_i128(row, index));
466				}
467				(
468					ColumnBuffer::Utf8 {
469						container,
470						..
471					},
472					ValueType::Utf8,
473				) => {
474					container.push(shape.get_utf8(row, index).to_string());
475				}
476				(ColumnBuffer::Uint1(container), ValueType::Uint1) => {
477					container.push(shape.get_u8(row, index));
478				}
479				(ColumnBuffer::Uint2(container), ValueType::Uint2) => {
480					container.push(shape.get_u16(row, index));
481				}
482				(ColumnBuffer::Uint4(container), ValueType::Uint4) => {
483					container.push(shape.get_u32(row, index));
484				}
485				(ColumnBuffer::Uint8(container), ValueType::Uint8) => {
486					container.push(shape.get_u64(row, index));
487				}
488				(ColumnBuffer::Uint16(container), ValueType::Uint16) => {
489					container.push(shape.get_u128(row, index));
490				}
491				(ColumnBuffer::Date(container), ValueType::Date) => {
492					container.push(shape.get_date(row, index));
493				}
494				(ColumnBuffer::DateTime(container), ValueType::DateTime) => {
495					container.push(shape.get_datetime(row, index));
496				}
497				(ColumnBuffer::Time(container), ValueType::Time) => {
498					container.push(shape.get_time(row, index));
499				}
500				(ColumnBuffer::Duration(container), ValueType::Duration) => {
501					container.push(shape.get_duration(row, index));
502				}
503				(ColumnBuffer::Uuid4(container), ValueType::Uuid4) => {
504					container.push(shape.get_uuid4(row, index));
505				}
506				(ColumnBuffer::Uuid7(container), ValueType::Uuid7) => {
507					container.push(shape.get_uuid7(row, index));
508				}
509				(ColumnBuffer::IdentityId(container), ValueType::IdentityId) => {
510					container.push(shape.get_identity_id(row, index));
511				}
512				(
513					ColumnBuffer::Blob {
514						container,
515						..
516					},
517					ValueType::Blob,
518				) => {
519					container.push(shape.get_blob(row, index));
520				}
521				(
522					ColumnBuffer::Int {
523						container,
524						..
525					},
526					ValueType::Int,
527				) => {
528					container.push(shape.get_int(row, index));
529				}
530				(
531					ColumnBuffer::Uint {
532						container,
533						..
534					},
535					ValueType::Uint,
536				) => {
537					container.push(shape.get_uint(row, index));
538				}
539				(
540					ColumnBuffer::Decimal {
541						container,
542						..
543					},
544					ValueType::Decimal,
545				) => {
546					container.push(shape.get_decimal(row, index));
547				}
548				(ColumnBuffer::DictionaryId(container), ValueType::DictionaryId) => {
549					match shape.get_value(row, index) {
550						Value::DictionaryId(id) => container.push(id),
551						_ => container.push_default(),
552					}
553				}
554				(l, r) => unreachable!("{:#?} {:#?}", l, r),
555			}
556		}
557		Ok(())
558	}
559}
560
561#[cfg(test)]
562pub mod tests {
563	mod columns {
564		use reifydb_value::value::{
565			uuid::{Uuid4, Uuid7},
566			value_type::ValueType,
567		};
568		use uuid::{Timestamp, Uuid};
569
570		use crate::value::column::{ColumnBuffer, ColumnWithName, columns::Columns};
571
572		#[test]
573		fn test_boolean() {
574			let mut test_instance1 =
575				Columns::new(vec![ColumnWithName::bool_with_bitvec("id", [true], [false])]);
576
577			let test_instance2 =
578				Columns::new(vec![ColumnWithName::bool_with_bitvec("id", [false], [true])]);
579
580			test_instance1.append_columns(test_instance2).unwrap();
581
582			assert_eq!(test_instance1[0], ColumnBuffer::bool_with_bitvec([true, false], [false, true]));
583		}
584
585		#[test]
586		fn test_float4() {
587			let mut test_instance1 = Columns::new(vec![ColumnWithName::float4("id", [1.0f32, 2.0])]);
588
589			let test_instance2 = Columns::new(vec![ColumnWithName::float4_with_bitvec(
590				"id",
591				[3.0f32, 4.0],
592				[true, false],
593			)]);
594
595			test_instance1.append_columns(test_instance2).unwrap();
596
597			assert_eq!(
598				test_instance1[0],
599				ColumnBuffer::float4_with_bitvec([1.0f32, 2.0, 3.0, 4.0], [true, true, true, false])
600			);
601		}
602
603		#[test]
604		fn test_float8() {
605			let mut test_instance1 = Columns::new(vec![ColumnWithName::float8("id", [1.0f64, 2.0])]);
606
607			let test_instance2 = Columns::new(vec![ColumnWithName::float8_with_bitvec(
608				"id",
609				[3.0f64, 4.0],
610				[true, false],
611			)]);
612
613			test_instance1.append_columns(test_instance2).unwrap();
614
615			assert_eq!(
616				test_instance1[0],
617				ColumnBuffer::float8_with_bitvec([1.0f64, 2.0, 3.0, 4.0], [true, true, true, false])
618			);
619		}
620
621		#[test]
622		fn test_int1() {
623			let mut test_instance1 = Columns::new(vec![ColumnWithName::int1("id", [1, 2])]);
624
625			let test_instance2 =
626				Columns::new(vec![ColumnWithName::int1_with_bitvec("id", [3, 4], [true, false])]);
627
628			test_instance1.append_columns(test_instance2).unwrap();
629
630			assert_eq!(
631				test_instance1[0],
632				ColumnBuffer::int1_with_bitvec([1, 2, 3, 4], [true, true, true, false])
633			);
634		}
635
636		#[test]
637		fn test_int2() {
638			let mut test_instance1 = Columns::new(vec![ColumnWithName::int2("id", [1, 2])]);
639
640			let test_instance2 =
641				Columns::new(vec![ColumnWithName::int2_with_bitvec("id", [3, 4], [true, false])]);
642
643			test_instance1.append_columns(test_instance2).unwrap();
644
645			assert_eq!(
646				test_instance1[0],
647				ColumnBuffer::int2_with_bitvec([1, 2, 3, 4], [true, true, true, false])
648			);
649		}
650
651		#[test]
652		fn test_int4() {
653			let mut test_instance1 = Columns::new(vec![ColumnWithName::int4("id", [1, 2])]);
654
655			let test_instance2 =
656				Columns::new(vec![ColumnWithName::int4_with_bitvec("id", [3, 4], [true, false])]);
657
658			test_instance1.append_columns(test_instance2).unwrap();
659
660			assert_eq!(
661				test_instance1[0],
662				ColumnBuffer::int4_with_bitvec([1, 2, 3, 4], [true, true, true, false])
663			);
664		}
665
666		#[test]
667		fn test_int8() {
668			let mut test_instance1 = Columns::new(vec![ColumnWithName::int8("id", [1, 2])]);
669
670			let test_instance2 =
671				Columns::new(vec![ColumnWithName::int8_with_bitvec("id", [3, 4], [true, false])]);
672
673			test_instance1.append_columns(test_instance2).unwrap();
674
675			assert_eq!(
676				test_instance1[0],
677				ColumnBuffer::int8_with_bitvec([1, 2, 3, 4], [true, true, true, false])
678			);
679		}
680
681		#[test]
682		fn test_int16() {
683			let mut test_instance1 = Columns::new(vec![ColumnWithName::int16("id", [1, 2])]);
684
685			let test_instance2 =
686				Columns::new(vec![ColumnWithName::int16_with_bitvec("id", [3, 4], [true, false])]);
687
688			test_instance1.append_columns(test_instance2).unwrap();
689
690			assert_eq!(
691				test_instance1[0],
692				ColumnBuffer::int16_with_bitvec([1, 2, 3, 4], [true, true, true, false])
693			);
694		}
695
696		#[test]
697		fn test_string() {
698			let mut test_instance1 = Columns::new(vec![ColumnWithName::utf8_with_bitvec(
699				"id",
700				vec!["a".to_string(), "b".to_string()],
701				[true, true],
702			)]);
703
704			let test_instance2 = Columns::new(vec![ColumnWithName::utf8_with_bitvec(
705				"id",
706				vec!["c".to_string(), "d".to_string()],
707				[true, false],
708			)]);
709
710			test_instance1.append_columns(test_instance2).unwrap();
711
712			assert_eq!(
713				test_instance1[0],
714				ColumnBuffer::utf8_with_bitvec(
715					vec!["a".to_string(), "b".to_string(), "c".to_string(), "d".to_string()],
716					vec![true, true, true, false]
717				)
718			);
719		}
720
721		#[test]
722		fn test_uint1() {
723			let mut test_instance1 = Columns::new(vec![ColumnWithName::uint1("id", [1, 2])]);
724
725			let test_instance2 =
726				Columns::new(vec![ColumnWithName::uint1_with_bitvec("id", [3, 4], [true, false])]);
727
728			test_instance1.append_columns(test_instance2).unwrap();
729
730			assert_eq!(
731				test_instance1[0],
732				ColumnBuffer::uint1_with_bitvec([1, 2, 3, 4], [true, true, true, false])
733			);
734		}
735
736		#[test]
737		fn test_uint2() {
738			let mut test_instance1 = Columns::new(vec![ColumnWithName::uint2("id", [1, 2])]);
739
740			let test_instance2 =
741				Columns::new(vec![ColumnWithName::uint2_with_bitvec("id", [3, 4], [true, false])]);
742
743			test_instance1.append_columns(test_instance2).unwrap();
744
745			assert_eq!(
746				test_instance1[0],
747				ColumnBuffer::uint2_with_bitvec([1, 2, 3, 4], [true, true, true, false])
748			);
749		}
750
751		#[test]
752		fn test_uint4() {
753			let mut test_instance1 = Columns::new(vec![ColumnWithName::uint4("id", [1, 2])]);
754
755			let test_instance2 =
756				Columns::new(vec![ColumnWithName::uint4_with_bitvec("id", [3, 4], [true, false])]);
757
758			test_instance1.append_columns(test_instance2).unwrap();
759
760			assert_eq!(
761				test_instance1[0],
762				ColumnBuffer::uint4_with_bitvec([1, 2, 3, 4], [true, true, true, false])
763			);
764		}
765
766		#[test]
767		fn test_uint8() {
768			let mut test_instance1 = Columns::new(vec![ColumnWithName::uint8("id", [1, 2])]);
769
770			let test_instance2 =
771				Columns::new(vec![ColumnWithName::uint8_with_bitvec("id", [3, 4], [true, false])]);
772
773			test_instance1.append_columns(test_instance2).unwrap();
774
775			assert_eq!(
776				test_instance1[0],
777				ColumnBuffer::uint8_with_bitvec([1, 2, 3, 4], [true, true, true, false])
778			);
779		}
780
781		#[test]
782		fn test_uint16() {
783			let mut test_instance1 = Columns::new(vec![ColumnWithName::uint16("id", [1, 2])]);
784
785			let test_instance2 =
786				Columns::new(vec![ColumnWithName::uint16_with_bitvec("id", [3, 4], [true, false])]);
787
788			test_instance1.append_columns(test_instance2).unwrap();
789
790			assert_eq!(
791				test_instance1[0],
792				ColumnBuffer::uint16_with_bitvec([1, 2, 3, 4], [true, true, true, false])
793			);
794		}
795
796		#[test]
797		fn test_uuid4() {
798			let uuid1 = Uuid4::from(Uuid::new_v4());
799			let uuid2 = Uuid4::from(Uuid::new_v4());
800			let uuid3 = Uuid4::from(Uuid::new_v4());
801			let uuid4 = Uuid4::from(Uuid::new_v4());
802
803			let mut test_instance1 = Columns::new(vec![ColumnWithName::uuid4("id", [uuid1, uuid2])]);
804
805			let test_instance2 = Columns::new(vec![ColumnWithName::uuid4_with_bitvec(
806				"id",
807				[uuid3, uuid4],
808				[true, false],
809			)]);
810
811			test_instance1.append_columns(test_instance2).unwrap();
812
813			assert_eq!(
814				test_instance1[0],
815				ColumnBuffer::uuid4_with_bitvec(
816					[uuid1, uuid2, uuid3, uuid4],
817					[true, true, true, false]
818				)
819			);
820		}
821
822		#[test]
823		fn test_uuid7() {
824			let uuid1 = Uuid7::from(Uuid::new_v7(Timestamp::from_gregorian_time(1, 1)));
825			let uuid2 = Uuid7::from(Uuid::new_v7(Timestamp::from_gregorian_time(1, 2)));
826			let uuid3 = Uuid7::from(Uuid::new_v7(Timestamp::from_gregorian_time(2, 1)));
827			let uuid4 = Uuid7::from(Uuid::new_v7(Timestamp::from_gregorian_time(2, 2)));
828
829			let mut test_instance1 = Columns::new(vec![ColumnWithName::uuid7("id", [uuid1, uuid2])]);
830
831			let test_instance2 = Columns::new(vec![ColumnWithName::uuid7_with_bitvec(
832				"id",
833				[uuid3, uuid4],
834				[true, false],
835			)]);
836
837			test_instance1.append_columns(test_instance2).unwrap();
838
839			assert_eq!(
840				test_instance1[0],
841				ColumnBuffer::uuid7_with_bitvec(
842					[uuid1, uuid2, uuid3, uuid4],
843					[true, true, true, false]
844				)
845			);
846		}
847
848		#[test]
849		fn test_with_undefined_lr_promotes_correctly() {
850			let mut test_instance1 =
851				Columns::new(vec![ColumnWithName::int2_with_bitvec("id", [1, 2], [true, false])]);
852
853			let test_instance2 =
854				Columns::new(vec![ColumnWithName::undefined_typed("id", ValueType::Boolean, 2)]);
855
856			test_instance1.append_columns(test_instance2).unwrap();
857
858			assert_eq!(
859				test_instance1[0],
860				ColumnBuffer::int2_with_bitvec([1, 2, 0, 0], [true, false, false, false])
861			);
862		}
863
864		#[test]
865		fn test_with_undefined_l_promotes_correctly() {
866			let mut test_instance1 =
867				Columns::new(vec![ColumnWithName::undefined_typed("score", ValueType::Boolean, 2)]);
868
869			let test_instance2 =
870				Columns::new(vec![ColumnWithName::int2_with_bitvec("score", [10, 20], [true, false])]);
871
872			test_instance1.append_columns(test_instance2).unwrap();
873
874			assert_eq!(
875				test_instance1[0],
876				ColumnBuffer::int2_with_bitvec([0, 0, 10, 20], [false, false, true, false])
877			);
878		}
879
880		#[test]
881		fn test_fails_on_column_count_mismatch() {
882			let mut test_instance1 = Columns::new(vec![ColumnWithName::int2("id", [1])]);
883
884			let test_instance2 = Columns::new(vec![
885				ColumnWithName::int2("id", [2]),
886				ColumnWithName::utf8("name", vec!["Bob".to_string()]),
887			]);
888
889			let result = test_instance1.append_columns(test_instance2);
890			assert!(result.is_err());
891		}
892
893		#[test]
894		fn test_fails_on_column_name_mismatch() {
895			let mut test_instance1 = Columns::new(vec![ColumnWithName::int2("id", [1])]);
896
897			let test_instance2 = Columns::new(vec![ColumnWithName::int2("wrong", [2])]);
898
899			let result = test_instance1.append_columns(test_instance2);
900			assert!(result.is_err());
901		}
902
903		#[test]
904		fn test_fails_on_type_mismatch() {
905			let mut test_instance1 = Columns::new(vec![ColumnWithName::int2("id", [1])]);
906
907			let test_instance2 = Columns::new(vec![ColumnWithName::utf8("id", vec!["A".to_string()])]);
908
909			let result = test_instance1.append_columns(test_instance2);
910			assert!(result.is_err());
911		}
912	}
913
914	mod row {
915		use reifydb_value::{
916			fragment::Fragment,
917			util::bitvec::BitVec,
918			value::{
919				Value,
920				blob::Blob,
921				constraint::TypeConstraint,
922				dictionary::{DictionaryEntryId, DictionaryId},
923				identity::IdentityId,
924				ordered_f32::OrderedF32,
925				ordered_f64::OrderedF64,
926				value_type::ValueType,
927			},
928		};
929
930		use crate::{
931			encoded::shape::{RowShape, RowShapeField},
932			value::column::{ColumnBuffer, ColumnWithName, columns::Columns},
933		};
934
935		#[test]
936		fn test_before_undefined_bool() {
937			let mut test_instance =
938				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
939
940			let shape = RowShape::testing(&[ValueType::Boolean]);
941			let mut row = shape.allocate();
942			shape.set_values(&mut row, &[Value::Boolean(true)]);
943
944			test_instance.append_rows(&shape, [row], vec![]).unwrap();
945
946			assert_eq!(
947				test_instance[0],
948				ColumnBuffer::bool_with_bitvec(
949					[false, false, true],
950					BitVec::from_slice(&[false, false, true])
951				)
952			);
953		}
954
955		#[test]
956		fn test_before_undefined_float4() {
957			let mut test_instance =
958				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
959			let shape = RowShape::testing(&[ValueType::Float4]);
960			let mut row = shape.allocate();
961			shape.set_values(&mut row, &[Value::Float4(OrderedF32::try_from(1.5).unwrap())]);
962			test_instance.append_rows(&shape, [row], vec![]).unwrap();
963
964			assert_eq!(
965				test_instance[0],
966				ColumnBuffer::float4_with_bitvec(
967					[0.0, 0.0, 1.5],
968					BitVec::from_slice(&[false, false, true])
969				)
970			);
971		}
972
973		#[test]
974		fn test_before_undefined_float8() {
975			let mut test_instance =
976				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
977			let shape = RowShape::testing(&[ValueType::Float8]);
978			let mut row = shape.allocate();
979			shape.set_values(&mut row, &[Value::Float8(OrderedF64::try_from(2.25).unwrap())]);
980			test_instance.append_rows(&shape, [row], vec![]).unwrap();
981
982			assert_eq!(
983				test_instance[0],
984				ColumnBuffer::float8_with_bitvec(
985					[0.0, 0.0, 2.25],
986					BitVec::from_slice(&[false, false, true])
987				)
988			);
989		}
990
991		#[test]
992		fn test_before_undefined_int1() {
993			let mut test_instance =
994				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
995			let shape = RowShape::testing(&[ValueType::Int1]);
996			let mut row = shape.allocate();
997			shape.set_values(&mut row, &[Value::Int1(42)]);
998			test_instance.append_rows(&shape, [row], vec![]).unwrap();
999
1000			assert_eq!(
1001				test_instance[0],
1002				ColumnBuffer::int1_with_bitvec([0, 0, 42], BitVec::from_slice(&[false, false, true]))
1003			);
1004		}
1005
1006		#[test]
1007		fn test_before_undefined_int2() {
1008			let mut test_instance =
1009				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1010			let shape = RowShape::testing(&[ValueType::Int2]);
1011			let mut row = shape.allocate();
1012			shape.set_values(&mut row, &[Value::Int2(-1234)]);
1013			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1014
1015			assert_eq!(
1016				test_instance[0],
1017				ColumnBuffer::int2_with_bitvec(
1018					[0, 0, -1234],
1019					BitVec::from_slice(&[false, false, true])
1020				)
1021			);
1022		}
1023
1024		#[test]
1025		fn test_before_undefined_int4() {
1026			let mut test_instance =
1027				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1028			let shape = RowShape::testing(&[ValueType::Int4]);
1029			let mut row = shape.allocate();
1030			shape.set_values(&mut row, &[Value::Int4(56789)]);
1031			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1032
1033			assert_eq!(
1034				test_instance[0],
1035				ColumnBuffer::int4_with_bitvec(
1036					[0, 0, 56789],
1037					BitVec::from_slice(&[false, false, true])
1038				)
1039			);
1040		}
1041
1042		#[test]
1043		fn test_before_undefined_int8() {
1044			let mut test_instance =
1045				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1046			let shape = RowShape::testing(&[ValueType::Int8]);
1047			let mut row = shape.allocate();
1048			shape.set_values(&mut row, &[Value::Int8(-987654321)]);
1049			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1050
1051			assert_eq!(
1052				test_instance[0],
1053				ColumnBuffer::int8_with_bitvec(
1054					[0, 0, -987654321],
1055					BitVec::from_slice(&[false, false, true])
1056				)
1057			);
1058		}
1059
1060		#[test]
1061		fn test_before_undefined_int16() {
1062			let mut test_instance =
1063				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1064			let shape = RowShape::testing(&[ValueType::Int16]);
1065			let mut row = shape.allocate();
1066			shape.set_values(&mut row, &[Value::Int16(123456789012345678901234567890i128)]);
1067			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1068
1069			assert_eq!(
1070				test_instance[0],
1071				ColumnBuffer::int16_with_bitvec(
1072					[0, 0, 123456789012345678901234567890i128],
1073					BitVec::from_slice(&[false, false, true])
1074				)
1075			);
1076		}
1077
1078		#[test]
1079		fn test_before_undefined_string() {
1080			let mut test_instance =
1081				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1082			let shape = RowShape::testing(&[ValueType::Utf8]);
1083			let mut row = shape.allocate();
1084			shape.set_values(&mut row, &[Value::Utf8("reifydb".into())]);
1085			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1086
1087			assert_eq!(
1088				test_instance[0],
1089				ColumnBuffer::utf8_with_bitvec(
1090					["".to_string(), "".to_string(), "reifydb".to_string()],
1091					BitVec::from_slice(&[false, false, true])
1092				)
1093			);
1094		}
1095
1096		#[test]
1097		fn test_before_undefined_uint1() {
1098			let mut test_instance =
1099				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1100			let shape = RowShape::testing(&[ValueType::Uint1]);
1101			let mut row = shape.allocate();
1102			shape.set_values(&mut row, &[Value::Uint1(255)]);
1103			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1104
1105			assert_eq!(
1106				test_instance[0],
1107				ColumnBuffer::uint1_with_bitvec([0, 0, 255], BitVec::from_slice(&[false, false, true]))
1108			);
1109		}
1110
1111		#[test]
1112		fn test_before_undefined_uint2() {
1113			let mut test_instance =
1114				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1115			let shape = RowShape::testing(&[ValueType::Uint2]);
1116			let mut row = shape.allocate();
1117			shape.set_values(&mut row, &[Value::Uint2(65535)]);
1118			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1119
1120			assert_eq!(
1121				test_instance[0],
1122				ColumnBuffer::uint2_with_bitvec(
1123					[0, 0, 65535],
1124					BitVec::from_slice(&[false, false, true])
1125				)
1126			);
1127		}
1128
1129		#[test]
1130		fn test_before_undefined_uint4() {
1131			let mut test_instance =
1132				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1133			let shape = RowShape::testing(&[ValueType::Uint4]);
1134			let mut row = shape.allocate();
1135			shape.set_values(&mut row, &[Value::Uint4(4294967295)]);
1136			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1137
1138			assert_eq!(
1139				test_instance[0],
1140				ColumnBuffer::uint4_with_bitvec(
1141					[0, 0, 4294967295],
1142					BitVec::from_slice(&[false, false, true])
1143				)
1144			);
1145		}
1146
1147		#[test]
1148		fn test_before_undefined_uint8() {
1149			let mut test_instance =
1150				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1151			let shape = RowShape::testing(&[ValueType::Uint8]);
1152			let mut row = shape.allocate();
1153			shape.set_values(&mut row, &[Value::Uint8(18446744073709551615)]);
1154			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1155
1156			assert_eq!(
1157				test_instance[0],
1158				ColumnBuffer::uint8_with_bitvec(
1159					[0, 0, 18446744073709551615],
1160					BitVec::from_slice(&[false, false, true])
1161				)
1162			);
1163		}
1164
1165		#[test]
1166		fn test_before_undefined_uint16() {
1167			let mut test_instance =
1168				Columns::new(vec![ColumnWithName::undefined_typed("test_col", ValueType::Boolean, 2)]);
1169			let shape = RowShape::testing(&[ValueType::Uint16]);
1170			let mut row = shape.allocate();
1171			shape.set_values(&mut row, &[Value::Uint16(340282366920938463463374607431768211455u128)]);
1172			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1173
1174			assert_eq!(
1175				test_instance[0],
1176				ColumnBuffer::uint16_with_bitvec(
1177					[0, 0, 340282366920938463463374607431768211455u128],
1178					BitVec::from_slice(&[false, false, true])
1179				)
1180			);
1181		}
1182
1183		#[test]
1184		fn test_mismatched_columns() {
1185			let mut test_instance = Columns::new(vec![]);
1186
1187			let shape = RowShape::testing(&[ValueType::Int2]);
1188			let mut row = shape.allocate();
1189			shape.set_values(&mut row, &[Value::Int2(2)]);
1190
1191			let err = test_instance.append_rows(&shape, [row], vec![]).err().unwrap();
1192			assert!(err.to_string().contains("mismatched column count: expected 0, got 1"));
1193		}
1194
1195		#[test]
1196		fn test_ok() {
1197			let mut test_instance = test_instance_with_columns();
1198
1199			let shape = RowShape::testing(&[ValueType::Int2, ValueType::Boolean]);
1200			let mut row_one = shape.allocate();
1201			shape.set_values(&mut row_one, &[Value::Int2(2), Value::Boolean(true)]);
1202			let mut row_two = shape.allocate();
1203			shape.set_values(&mut row_two, &[Value::Int2(3), Value::Boolean(false)]);
1204
1205			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1206
1207			assert_eq!(test_instance[0], ColumnBuffer::int2([1, 2, 3]));
1208			assert_eq!(test_instance[1], ColumnBuffer::bool([true, true, false]));
1209		}
1210
1211		#[test]
1212		fn test_all_defined_bool() {
1213			let mut test_instance =
1214				Columns::new(vec![ColumnWithName::bool("test_col", Vec::<bool>::new())]);
1215
1216			let shape = RowShape::testing(&[ValueType::Boolean]);
1217			let mut row_one = shape.allocate();
1218			shape.set_bool(&mut row_one, 0, true);
1219			let mut row_two = shape.allocate();
1220			shape.set_bool(&mut row_two, 0, false);
1221
1222			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1223
1224			assert_eq!(test_instance[0], ColumnBuffer::bool([true, false]));
1225		}
1226
1227		#[test]
1228		fn test_all_defined_float4() {
1229			let mut test_instance =
1230				Columns::new(vec![ColumnWithName::float4("test_col", Vec::<f32>::new())]);
1231
1232			let shape = RowShape::testing(&[ValueType::Float4]);
1233			let mut row_one = shape.allocate();
1234			shape.set_values(&mut row_one, &[Value::Float4(OrderedF32::try_from(1.0).unwrap())]);
1235			let mut row_two = shape.allocate();
1236			shape.set_values(&mut row_two, &[Value::Float4(OrderedF32::try_from(2.0).unwrap())]);
1237
1238			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1239
1240			assert_eq!(test_instance[0], ColumnBuffer::float4([1.0, 2.0]));
1241		}
1242
1243		#[test]
1244		fn test_all_defined_float8() {
1245			let mut test_instance =
1246				Columns::new(vec![ColumnWithName::float8("test_col", Vec::<f64>::new())]);
1247
1248			let shape = RowShape::testing(&[ValueType::Float8]);
1249			let mut row_one = shape.allocate();
1250			shape.set_values(&mut row_one, &[Value::Float8(OrderedF64::try_from(1.0).unwrap())]);
1251			let mut row_two = shape.allocate();
1252			shape.set_values(&mut row_two, &[Value::Float8(OrderedF64::try_from(2.0).unwrap())]);
1253
1254			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1255
1256			assert_eq!(test_instance[0], ColumnBuffer::float8([1.0, 2.0]));
1257		}
1258
1259		#[test]
1260		fn test_all_defined_int1() {
1261			let mut test_instance = Columns::new(vec![ColumnWithName::int1("test_col", Vec::<i8>::new())]);
1262
1263			let shape = RowShape::testing(&[ValueType::Int1]);
1264			let mut row_one = shape.allocate();
1265			shape.set_values(&mut row_one, &[Value::Int1(1)]);
1266			let mut row_two = shape.allocate();
1267			shape.set_values(&mut row_two, &[Value::Int1(2)]);
1268
1269			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1270
1271			assert_eq!(test_instance[0], ColumnBuffer::int1([1, 2]));
1272		}
1273
1274		#[test]
1275		fn test_all_defined_int2() {
1276			let mut test_instance = Columns::new(vec![ColumnWithName::int2("test_col", Vec::<i16>::new())]);
1277
1278			let shape = RowShape::testing(&[ValueType::Int2]);
1279			let mut row_one = shape.allocate();
1280			shape.set_values(&mut row_one, &[Value::Int2(100)]);
1281			let mut row_two = shape.allocate();
1282			shape.set_values(&mut row_two, &[Value::Int2(200)]);
1283
1284			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1285
1286			assert_eq!(test_instance[0], ColumnBuffer::int2([100, 200]));
1287		}
1288
1289		#[test]
1290		fn test_all_defined_int4() {
1291			let mut test_instance = Columns::new(vec![ColumnWithName::int4("test_col", Vec::<i32>::new())]);
1292
1293			let shape = RowShape::testing(&[ValueType::Int4]);
1294			let mut row_one = shape.allocate();
1295			shape.set_values(&mut row_one, &[Value::Int4(1000)]);
1296			let mut row_two = shape.allocate();
1297			shape.set_values(&mut row_two, &[Value::Int4(2000)]);
1298
1299			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1300
1301			assert_eq!(test_instance[0], ColumnBuffer::int4([1000, 2000]));
1302		}
1303
1304		#[test]
1305		fn test_all_defined_int8() {
1306			let mut test_instance = Columns::new(vec![ColumnWithName::int8("test_col", Vec::<i64>::new())]);
1307
1308			let shape = RowShape::testing(&[ValueType::Int8]);
1309			let mut row_one = shape.allocate();
1310			shape.set_values(&mut row_one, &[Value::Int8(10000)]);
1311			let mut row_two = shape.allocate();
1312			shape.set_values(&mut row_two, &[Value::Int8(20000)]);
1313
1314			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1315
1316			assert_eq!(test_instance[0], ColumnBuffer::int8([10000, 20000]));
1317		}
1318
1319		#[test]
1320		fn test_all_defined_int16() {
1321			let mut test_instance =
1322				Columns::new(vec![ColumnWithName::int16("test_col", Vec::<i128>::new())]);
1323
1324			let shape = RowShape::testing(&[ValueType::Int16]);
1325			let mut row_one = shape.allocate();
1326			shape.set_values(&mut row_one, &[Value::Int16(1000)]);
1327			let mut row_two = shape.allocate();
1328			shape.set_values(&mut row_two, &[Value::Int16(2000)]);
1329
1330			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1331
1332			assert_eq!(test_instance[0], ColumnBuffer::int16([1000, 2000]));
1333		}
1334
1335		#[test]
1336		fn test_all_defined_string() {
1337			let mut test_instance =
1338				Columns::new(vec![ColumnWithName::utf8("test_col", Vec::<String>::new())]);
1339
1340			let shape = RowShape::testing(&[ValueType::Utf8]);
1341			let mut row_one = shape.allocate();
1342			shape.set_values(&mut row_one, &[Value::Utf8("a".into())]);
1343			let mut row_two = shape.allocate();
1344			shape.set_values(&mut row_two, &[Value::Utf8("b".into())]);
1345
1346			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1347
1348			assert_eq!(test_instance[0], ColumnBuffer::utf8(["a".to_string(), "b".to_string()]));
1349		}
1350
1351		#[test]
1352		fn test_all_defined_uint1() {
1353			let mut test_instance = Columns::new(vec![ColumnWithName::uint1("test_col", Vec::<u8>::new())]);
1354
1355			let shape = RowShape::testing(&[ValueType::Uint1]);
1356			let mut row_one = shape.allocate();
1357			shape.set_values(&mut row_one, &[Value::Uint1(1)]);
1358			let mut row_two = shape.allocate();
1359			shape.set_values(&mut row_two, &[Value::Uint1(2)]);
1360
1361			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1362
1363			assert_eq!(test_instance[0], ColumnBuffer::uint1([1, 2]));
1364		}
1365
1366		#[test]
1367		fn test_all_defined_uint2() {
1368			let mut test_instance =
1369				Columns::new(vec![ColumnWithName::uint2("test_col", Vec::<u16>::new())]);
1370
1371			let shape = RowShape::testing(&[ValueType::Uint2]);
1372			let mut row_one = shape.allocate();
1373			shape.set_values(&mut row_one, &[Value::Uint2(100)]);
1374			let mut row_two = shape.allocate();
1375			shape.set_values(&mut row_two, &[Value::Uint2(200)]);
1376
1377			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1378
1379			assert_eq!(test_instance[0], ColumnBuffer::uint2([100, 200]));
1380		}
1381
1382		#[test]
1383		fn test_all_defined_uint4() {
1384			let mut test_instance =
1385				Columns::new(vec![ColumnWithName::uint4("test_col", Vec::<u32>::new())]);
1386
1387			let shape = RowShape::testing(&[ValueType::Uint4]);
1388			let mut row_one = shape.allocate();
1389			shape.set_values(&mut row_one, &[Value::Uint4(1000)]);
1390			let mut row_two = shape.allocate();
1391			shape.set_values(&mut row_two, &[Value::Uint4(2000)]);
1392
1393			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1394
1395			assert_eq!(test_instance[0], ColumnBuffer::uint4([1000, 2000]));
1396		}
1397
1398		#[test]
1399		fn test_all_defined_uint8() {
1400			let mut test_instance =
1401				Columns::new(vec![ColumnWithName::uint8("test_col", Vec::<u64>::new())]);
1402
1403			let shape = RowShape::testing(&[ValueType::Uint8]);
1404			let mut row_one = shape.allocate();
1405			shape.set_values(&mut row_one, &[Value::Uint8(10000)]);
1406			let mut row_two = shape.allocate();
1407			shape.set_values(&mut row_two, &[Value::Uint8(20000)]);
1408
1409			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1410
1411			assert_eq!(test_instance[0], ColumnBuffer::uint8([10000, 20000]));
1412		}
1413
1414		#[test]
1415		fn test_all_defined_uint16() {
1416			let mut test_instance =
1417				Columns::new(vec![ColumnWithName::uint16("test_col", Vec::<u128>::new())]);
1418
1419			let shape = RowShape::testing(&[ValueType::Uint16]);
1420			let mut row_one = shape.allocate();
1421			shape.set_values(&mut row_one, &[Value::Uint16(1000)]);
1422			let mut row_two = shape.allocate();
1423			shape.set_values(&mut row_two, &[Value::Uint16(2000)]);
1424
1425			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1426
1427			assert_eq!(test_instance[0], ColumnBuffer::uint16([1000, 2000]));
1428		}
1429
1430		#[test]
1431		fn test_row_with_undefined() {
1432			let mut test_instance = test_instance_with_columns();
1433
1434			let shape = RowShape::testing(&[ValueType::Int2, ValueType::Boolean]);
1435			let mut row = shape.allocate();
1436			shape.set_values(&mut row, &[Value::none(), Value::Boolean(false)]);
1437
1438			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1439
1440			assert_eq!(test_instance[0], ColumnBuffer::int2_with_bitvec(vec![1, 0], vec![true, false]));
1441			assert_eq!(test_instance[1], ColumnBuffer::bool_with_bitvec([true, false], [true, true]));
1442		}
1443
1444		#[test]
1445		fn test_row_with_type_mismatch_fails() {
1446			let mut test_instance = test_instance_with_columns();
1447
1448			let shape = RowShape::testing(&[ValueType::Boolean, ValueType::Boolean]);
1449			let mut row = shape.allocate();
1450			shape.set_values(&mut row, &[Value::Boolean(true), Value::Boolean(true)]);
1451
1452			let result = test_instance.append_rows(&shape, [row], vec![]);
1453			assert!(result.is_err());
1454			assert!(result.unwrap_err().to_string().contains("type mismatch"));
1455		}
1456
1457		#[test]
1458		fn test_row_wrong_length_fails() {
1459			let mut test_instance = test_instance_with_columns();
1460
1461			let shape = RowShape::testing(&[ValueType::Int2]);
1462			let mut row = shape.allocate();
1463			shape.set_values(&mut row, &[Value::Int2(2)]);
1464
1465			let result = test_instance.append_rows(&shape, [row], vec![]);
1466			assert!(result.is_err());
1467			assert!(result.unwrap_err().to_string().contains("mismatched column count"));
1468		}
1469
1470		#[test]
1471		fn test_fallback_bool() {
1472			let mut test_instance = Columns::new(vec![
1473				ColumnWithName::bool("test_col", Vec::<bool>::new()),
1474				ColumnWithName::bool("none", Vec::<bool>::new()),
1475			]);
1476
1477			let shape = RowShape::testing(&[ValueType::Boolean, ValueType::Boolean]);
1478			let mut row_one = shape.allocate();
1479			shape.set_bool(&mut row_one, 0, true);
1480			shape.set_none(&mut row_one, 1);
1481
1482			test_instance.append_rows(&shape, [row_one], vec![]).unwrap();
1483
1484			assert_eq!(test_instance[0], ColumnBuffer::bool_with_bitvec([true], [true]));
1485
1486			assert_eq!(test_instance[1], ColumnBuffer::bool_with_bitvec([false], [false]));
1487		}
1488
1489		#[test]
1490		fn test_fallback_float4() {
1491			let mut test_instance = Columns::new(vec![
1492				ColumnWithName::float4("test_col", Vec::<f32>::new()),
1493				ColumnWithName::float4("none", Vec::<f32>::new()),
1494			]);
1495
1496			let shape = RowShape::testing(&[ValueType::Float4, ValueType::Float4]);
1497			let mut row = shape.allocate();
1498			shape.set_f32(&mut row, 0, 1.5);
1499			shape.set_none(&mut row, 1);
1500
1501			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1502
1503			assert_eq!(test_instance[0], ColumnBuffer::float4_with_bitvec([1.5], [true]));
1504			assert_eq!(test_instance[1], ColumnBuffer::float4_with_bitvec([0.0], [false]));
1505		}
1506
1507		#[test]
1508		fn test_fallback_float8() {
1509			let mut test_instance = Columns::new(vec![
1510				ColumnWithName::float8("test_col", Vec::<f64>::new()),
1511				ColumnWithName::float8("none", Vec::<f64>::new()),
1512			]);
1513
1514			let shape = RowShape::testing(&[ValueType::Float8, ValueType::Float8]);
1515			let mut row = shape.allocate();
1516			shape.set_f64(&mut row, 0, 2.5);
1517			shape.set_none(&mut row, 1);
1518
1519			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1520
1521			assert_eq!(test_instance[0], ColumnBuffer::float8_with_bitvec([2.5], [true]));
1522			assert_eq!(test_instance[1], ColumnBuffer::float8_with_bitvec([0.0], [false]));
1523		}
1524
1525		#[test]
1526		fn test_fallback_int1() {
1527			let mut test_instance = Columns::new(vec![
1528				ColumnWithName::int1("test_col", Vec::<i8>::new()),
1529				ColumnWithName::int1("none", Vec::<i8>::new()),
1530			]);
1531
1532			let shape = RowShape::testing(&[ValueType::Int1, ValueType::Int1]);
1533			let mut row = shape.allocate();
1534			shape.set_i8(&mut row, 0, 42);
1535			shape.set_none(&mut row, 1);
1536
1537			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1538
1539			assert_eq!(test_instance[0], ColumnBuffer::int1_with_bitvec([42], [true]));
1540			assert_eq!(test_instance[1], ColumnBuffer::int1_with_bitvec([0], [false]));
1541		}
1542
1543		#[test]
1544		fn test_fallback_int2() {
1545			let mut test_instance = Columns::new(vec![
1546				ColumnWithName::int2("test_col", Vec::<i16>::new()),
1547				ColumnWithName::int2("none", Vec::<i16>::new()),
1548			]);
1549
1550			let shape = RowShape::testing(&[ValueType::Int2, ValueType::Int2]);
1551			let mut row = shape.allocate();
1552			shape.set_i16(&mut row, 0, -1234i16);
1553			shape.set_none(&mut row, 1);
1554
1555			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1556
1557			assert_eq!(test_instance[0], ColumnBuffer::int2_with_bitvec([-1234], [true]));
1558			assert_eq!(test_instance[1], ColumnBuffer::int2_with_bitvec([0], [false]));
1559		}
1560
1561		#[test]
1562		fn test_fallback_int4() {
1563			let mut test_instance = Columns::new(vec![
1564				ColumnWithName::int4("test_col", Vec::<i32>::new()),
1565				ColumnWithName::int4("none", Vec::<i32>::new()),
1566			]);
1567
1568			let shape = RowShape::testing(&[ValueType::Int4, ValueType::Int4]);
1569			let mut row = shape.allocate();
1570			shape.set_i32(&mut row, 0, 56789);
1571			shape.set_none(&mut row, 1);
1572
1573			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1574
1575			assert_eq!(test_instance[0], ColumnBuffer::int4_with_bitvec([56789], [true]));
1576			assert_eq!(test_instance[1], ColumnBuffer::int4_with_bitvec([0], [false]));
1577		}
1578
1579		#[test]
1580		fn test_fallback_int8() {
1581			let mut test_instance = Columns::new(vec![
1582				ColumnWithName::int8("test_col", Vec::<i64>::new()),
1583				ColumnWithName::int8("none", Vec::<i64>::new()),
1584			]);
1585
1586			let shape = RowShape::testing(&[ValueType::Int8, ValueType::Int8]);
1587			let mut row = shape.allocate();
1588			shape.set_i64(&mut row, 0, -987654321);
1589			shape.set_none(&mut row, 1);
1590
1591			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1592
1593			assert_eq!(test_instance[0], ColumnBuffer::int8_with_bitvec([-987654321], [true]));
1594			assert_eq!(test_instance[1], ColumnBuffer::int8_with_bitvec([0], [false]));
1595		}
1596
1597		#[test]
1598		fn test_fallback_int16() {
1599			let mut test_instance = Columns::new(vec![
1600				ColumnWithName::int16("test_col", Vec::<i128>::new()),
1601				ColumnWithName::int16("none", Vec::<i128>::new()),
1602			]);
1603
1604			let shape = RowShape::testing(&[ValueType::Int16, ValueType::Int16]);
1605			let mut row = shape.allocate();
1606			shape.set_i128(&mut row, 0, 123456789012345678901234567890i128);
1607			shape.set_none(&mut row, 1);
1608
1609			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1610
1611			assert_eq!(
1612				test_instance[0],
1613				ColumnBuffer::int16_with_bitvec([123456789012345678901234567890i128], [true])
1614			);
1615			assert_eq!(test_instance[1], ColumnBuffer::int16_with_bitvec([0], [false]));
1616		}
1617
1618		#[test]
1619		fn test_fallback_string() {
1620			let mut test_instance = Columns::new(vec![
1621				ColumnWithName::utf8("test_col", Vec::<String>::new()),
1622				ColumnWithName::utf8("none", Vec::<String>::new()),
1623			]);
1624
1625			let shape = RowShape::testing(&[ValueType::Utf8, ValueType::Utf8]);
1626			let mut row = shape.allocate();
1627			shape.set_utf8(&mut row, 0, "reifydb");
1628			shape.set_none(&mut row, 1);
1629
1630			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1631
1632			assert_eq!(test_instance[0], ColumnBuffer::utf8_with_bitvec(["reifydb".to_string()], [true]));
1633			assert_eq!(test_instance[1], ColumnBuffer::utf8_with_bitvec(["".to_string()], [false]));
1634		}
1635
1636		#[test]
1637		fn test_fallback_uint1() {
1638			let mut test_instance = Columns::new(vec![
1639				ColumnWithName::uint1("test_col", Vec::<u8>::new()),
1640				ColumnWithName::uint1("none", Vec::<u8>::new()),
1641			]);
1642
1643			let shape = RowShape::testing(&[ValueType::Uint1, ValueType::Uint1]);
1644			let mut row = shape.allocate();
1645			shape.set_u8(&mut row, 0, 255);
1646			shape.set_none(&mut row, 1);
1647
1648			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1649
1650			assert_eq!(test_instance[0], ColumnBuffer::uint1_with_bitvec([255], [true]));
1651			assert_eq!(test_instance[1], ColumnBuffer::uint1_with_bitvec([0], [false]));
1652		}
1653
1654		#[test]
1655		fn test_fallback_uint2() {
1656			let mut test_instance = Columns::new(vec![
1657				ColumnWithName::uint2("test_col", Vec::<u16>::new()),
1658				ColumnWithName::uint2("none", Vec::<u16>::new()),
1659			]);
1660
1661			let shape = RowShape::testing(&[ValueType::Uint2, ValueType::Uint2]);
1662			let mut row = shape.allocate();
1663			shape.set_u16(&mut row, 0, 65535u16);
1664			shape.set_none(&mut row, 1);
1665
1666			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1667
1668			assert_eq!(test_instance[0], ColumnBuffer::uint2_with_bitvec([65535], [true]));
1669			assert_eq!(test_instance[1], ColumnBuffer::uint2_with_bitvec([0], [false]));
1670		}
1671
1672		#[test]
1673		fn test_fallback_uint4() {
1674			let mut test_instance = Columns::new(vec![
1675				ColumnWithName::uint4("test_col", Vec::<u32>::new()),
1676				ColumnWithName::uint4("none", Vec::<u32>::new()),
1677			]);
1678
1679			let shape = RowShape::testing(&[ValueType::Uint4, ValueType::Uint4]);
1680			let mut row = shape.allocate();
1681			shape.set_u32(&mut row, 0, 4294967295u32);
1682			shape.set_none(&mut row, 1);
1683
1684			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1685
1686			assert_eq!(test_instance[0], ColumnBuffer::uint4_with_bitvec([4294967295], [true]));
1687			assert_eq!(test_instance[1], ColumnBuffer::uint4_with_bitvec([0], [false]));
1688		}
1689
1690		#[test]
1691		fn test_fallback_uint8() {
1692			let mut test_instance = Columns::new(vec![
1693				ColumnWithName::uint8("test_col", Vec::<u64>::new()),
1694				ColumnWithName::uint8("none", Vec::<u64>::new()),
1695			]);
1696
1697			let shape = RowShape::testing(&[ValueType::Uint8, ValueType::Uint8]);
1698			let mut row = shape.allocate();
1699			shape.set_u64(&mut row, 0, 18446744073709551615u64);
1700			shape.set_none(&mut row, 1);
1701
1702			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1703
1704			assert_eq!(test_instance[0], ColumnBuffer::uint8_with_bitvec([18446744073709551615], [true]));
1705			assert_eq!(test_instance[1], ColumnBuffer::uint8_with_bitvec([0], [false]));
1706		}
1707
1708		#[test]
1709		fn test_fallback_uint16() {
1710			let mut test_instance = Columns::new(vec![
1711				ColumnWithName::uint16("test_col", Vec::<u128>::new()),
1712				ColumnWithName::uint16("none", Vec::<u128>::new()),
1713			]);
1714
1715			let shape = RowShape::testing(&[ValueType::Uint16, ValueType::Uint16]);
1716			let mut row = shape.allocate();
1717			shape.set_u128(&mut row, 0, 340282366920938463463374607431768211455u128);
1718			shape.set_none(&mut row, 1);
1719
1720			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1721
1722			assert_eq!(
1723				test_instance[0],
1724				ColumnBuffer::uint16_with_bitvec([340282366920938463463374607431768211455u128], [true])
1725			);
1726			assert_eq!(test_instance[1], ColumnBuffer::uint16_with_bitvec([0], [false]));
1727		}
1728
1729		#[test]
1730		fn test_all_defined_dictionary_id() {
1731			let constraint = TypeConstraint::dictionary(DictionaryId::from(1u64), ValueType::Uint4);
1732			let shape = RowShape::new(vec![RowShapeField::new("status", constraint)]);
1733
1734			let mut test_instance = Columns::new(vec![ColumnWithName::dictionary_id(
1735				"status",
1736				Vec::<DictionaryEntryId>::new(),
1737			)]);
1738
1739			let mut row_one = shape.allocate();
1740			shape.set_values(&mut row_one, &[Value::DictionaryId(DictionaryEntryId::U4(10))]);
1741			let mut row_two = shape.allocate();
1742			shape.set_values(&mut row_two, &[Value::DictionaryId(DictionaryEntryId::U4(20))]);
1743
1744			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1745
1746			assert_eq!(test_instance[0].get_value(0), Value::DictionaryId(DictionaryEntryId::U4(10)));
1747			assert_eq!(test_instance[0].get_value(1), Value::DictionaryId(DictionaryEntryId::U4(20)));
1748		}
1749
1750		#[test]
1751		fn test_fallback_dictionary_id() {
1752			let dict_constraint = TypeConstraint::dictionary(DictionaryId::from(1u64), ValueType::Uint4);
1753			let shape = RowShape::new(vec![
1754				RowShapeField::new("dict_col", dict_constraint),
1755				RowShapeField::unconstrained("bool_col", ValueType::Boolean),
1756			]);
1757
1758			let mut test_instance = Columns::new(vec![
1759				ColumnWithName::dictionary_id("dict_col", Vec::<DictionaryEntryId>::new()),
1760				ColumnWithName::bool("bool_col", Vec::<bool>::new()),
1761			]);
1762
1763			let mut row = shape.allocate();
1764			shape.set_values(&mut row, &[Value::none(), Value::Boolean(true)]);
1765
1766			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1767
1768			// Dictionary column should be undefined
1769			assert!(!test_instance[0].is_defined(0));
1770			// Bool column should be defined
1771			assert_eq!(test_instance[1].get_value(0), Value::Boolean(true));
1772		}
1773
1774		#[test]
1775		fn test_before_undefined_dictionary_id() {
1776			let constraint = TypeConstraint::dictionary(DictionaryId::from(2u64), ValueType::Uint4);
1777			let shape = RowShape::new(vec![RowShapeField::new("tag", constraint)]);
1778
1779			let mut test_instance =
1780				Columns::new(vec![ColumnWithName::undefined_typed("tag", ValueType::Boolean, 2)]);
1781
1782			let mut row = shape.allocate();
1783			shape.set_values(&mut row, &[Value::DictionaryId(DictionaryEntryId::U4(5))]);
1784
1785			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1786
1787			// First two are undefined (promoted from Undefined column), third is defined
1788			assert!(!test_instance[0].is_defined(0));
1789			assert!(!test_instance[0].is_defined(1));
1790			assert!(test_instance[0].is_defined(2));
1791			assert_eq!(test_instance[0].get_value(2), Value::DictionaryId(DictionaryEntryId::U4(5)));
1792		}
1793
1794		#[test]
1795		fn test_all_defined_identity_id() {
1796			let id1 = IdentityId::anonymous();
1797			let id2 = IdentityId::root();
1798
1799			let shape = RowShape::testing(&[ValueType::IdentityId]);
1800			let mut test_instance = Columns::new(vec![ColumnWithName::new(
1801				Fragment::internal("id_col"),
1802				ColumnBuffer::identity_id(Vec::<IdentityId>::new()),
1803			)]);
1804
1805			let mut row_one = shape.allocate();
1806			shape.set_identity_id(&mut row_one, 0, id1);
1807			let mut row_two = shape.allocate();
1808			shape.set_identity_id(&mut row_two, 0, id2);
1809
1810			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1811
1812			assert_eq!(test_instance[0].get_value(0), Value::IdentityId(id1));
1813			assert_eq!(test_instance[0].get_value(1), Value::IdentityId(id2));
1814		}
1815
1816		#[test]
1817		fn test_fallback_identity_id() {
1818			let id = IdentityId::anonymous();
1819
1820			let shape = RowShape::testing(&[ValueType::IdentityId, ValueType::Boolean]);
1821			let mut test_instance = Columns::new(vec![
1822				ColumnWithName::new(
1823					Fragment::internal("id_col"),
1824					ColumnBuffer::identity_id(Vec::<IdentityId>::new()),
1825				),
1826				ColumnWithName::bool("bool_col", Vec::<bool>::new()),
1827			]);
1828
1829			let mut row = shape.allocate();
1830			shape.set_identity_id(&mut row, 0, id);
1831			shape.set_none(&mut row, 1);
1832
1833			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1834
1835			assert_eq!(test_instance[0].get_value(0), Value::IdentityId(id));
1836			assert!(test_instance[0].is_defined(0));
1837			assert!(!test_instance[1].is_defined(0));
1838		}
1839
1840		#[test]
1841		fn test_all_defined_blob() {
1842			let blob1 = Blob::new(vec![1, 2, 3]);
1843			let blob2 = Blob::new(vec![4, 5]);
1844
1845			let shape = RowShape::testing(&[ValueType::Blob]);
1846			let mut test_instance = Columns::new(vec![ColumnWithName::new(
1847				Fragment::internal("blob_col"),
1848				ColumnBuffer::blob(Vec::<Blob>::new()),
1849			)]);
1850
1851			let mut row_one = shape.allocate();
1852			shape.set_blob(&mut row_one, 0, &blob1);
1853			let mut row_two = shape.allocate();
1854			shape.set_blob(&mut row_two, 0, &blob2);
1855
1856			test_instance.append_rows(&shape, [row_one, row_two], vec![]).unwrap();
1857
1858			assert_eq!(test_instance[0].get_value(0), Value::Blob(blob1));
1859			assert_eq!(test_instance[0].get_value(1), Value::Blob(blob2));
1860		}
1861
1862		#[test]
1863		fn test_fallback_blob() {
1864			let blob = Blob::new(vec![10, 20, 30]);
1865
1866			let shape = RowShape::testing(&[ValueType::Blob, ValueType::Boolean]);
1867			let mut test_instance = Columns::new(vec![
1868				ColumnWithName::new(
1869					Fragment::internal("blob_col"),
1870					ColumnBuffer::blob(Vec::<Blob>::new()),
1871				),
1872				ColumnWithName::bool("bool_col", Vec::<bool>::new()),
1873			]);
1874
1875			let mut row = shape.allocate();
1876			shape.set_blob(&mut row, 0, &blob);
1877			shape.set_none(&mut row, 1);
1878
1879			test_instance.append_rows(&shape, [row], vec![]).unwrap();
1880
1881			assert_eq!(test_instance[0].get_value(0), Value::Blob(blob));
1882			assert!(test_instance[0].is_defined(0));
1883			assert!(!test_instance[1].is_defined(0));
1884		}
1885
1886		fn test_instance_with_columns() -> Columns {
1887			Columns::new(vec![
1888				ColumnWithName::new(Fragment::internal("int2"), ColumnBuffer::int2(vec![1])),
1889				ColumnWithName::new(Fragment::internal("bool"), ColumnBuffer::bool(vec![true])),
1890			])
1891		}
1892	}
1893}