reifydb_core/value/column/push/
undefined.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use crate::value::column::data::ColumnData;
5
6impl ColumnData {
7	pub fn push_undefined(&mut self) {
8		match self {
9			ColumnData::Bool(container) => container.push_undefined(),
10			ColumnData::Float4(container) => container.push_undefined(),
11			ColumnData::Float8(container) => container.push_undefined(),
12			ColumnData::Int1(container) => container.push_undefined(),
13			ColumnData::Int2(container) => container.push_undefined(),
14			ColumnData::Int4(container) => container.push_undefined(),
15			ColumnData::Int8(container) => container.push_undefined(),
16			ColumnData::Int16(container) => container.push_undefined(),
17			ColumnData::Utf8 {
18				container,
19				..
20			} => container.push_undefined(),
21			ColumnData::Uint1(container) => container.push_undefined(),
22			ColumnData::Uint2(container) => container.push_undefined(),
23			ColumnData::Uint4(container) => container.push_undefined(),
24			ColumnData::Uint8(container) => container.push_undefined(),
25			ColumnData::Uint16(container) => container.push_undefined(),
26			ColumnData::Date(container) => container.push_undefined(),
27			ColumnData::DateTime(container) => container.push_undefined(),
28			ColumnData::Time(container) => container.push_undefined(),
29			ColumnData::Duration(container) => container.push_undefined(),
30			ColumnData::Undefined(container) => container.push_undefined(),
31			ColumnData::RowNumber(container) => container.push_undefined(),
32			ColumnData::IdentityId(container) => container.push_undefined(),
33			ColumnData::Uuid4(container) => container.push_undefined(),
34			ColumnData::Uuid7(container) => container.push_undefined(),
35			ColumnData::Blob {
36				container,
37				..
38			} => container.push_undefined(),
39			ColumnData::Int {
40				container,
41				..
42			} => container.push_undefined(),
43			ColumnData::Uint {
44				container,
45				..
46			} => container.push_undefined(),
47			ColumnData::Decimal {
48				container,
49				..
50			} => container.push_undefined(),
51			&mut ColumnData::Any(ref mut container) => container.push_undefined(),
52		}
53	}
54}
55
56#[cfg(test)]
57mod tests {
58	use crate::value::column::ColumnData;
59
60	#[test]
61	fn test_bool() {
62		let mut col = ColumnData::bool(vec![true]);
63		col.push_undefined();
64		let ColumnData::Bool(container) = col else {
65			panic!("Expected Bool");
66		};
67
68		assert_eq!(container.data().to_vec(), vec![true, false]);
69		assert!(container.is_defined(0));
70		assert!(!container.is_defined(1));
71	}
72
73	#[test]
74	fn test_float4() {
75		let mut col = ColumnData::float4(vec![1.0]);
76		col.push_undefined();
77		let ColumnData::Float4(container) = col else {
78			panic!("Expected Float4");
79		};
80
81		assert_eq!(container.data().as_slice(), &[1.0, 0.0]);
82		assert!(container.is_defined(0));
83		assert!(!container.is_defined(1));
84	}
85
86	#[test]
87	fn test_float8() {
88		let mut col = ColumnData::float8(vec![1.0]);
89		col.push_undefined();
90		let ColumnData::Float8(container) = col else {
91			panic!("Expected Float8");
92		};
93
94		assert_eq!(container.data().as_slice(), &[1.0, 0.0]);
95		assert!(container.is_defined(0));
96		assert!(!container.is_defined(1));
97	}
98
99	#[test]
100	fn test_int1() {
101		let mut col = ColumnData::int1(vec![1]);
102		col.push_undefined();
103		let ColumnData::Int1(container) = col else {
104			panic!("Expected Int1");
105		};
106
107		assert_eq!(container.data().as_slice(), &[1, 0]);
108		assert!(container.is_defined(0));
109		assert!(!container.is_defined(1));
110	}
111
112	#[test]
113	fn test_int2() {
114		let mut col = ColumnData::int2(vec![1]);
115		col.push_undefined();
116		let ColumnData::Int2(container) = col else {
117			panic!("Expected Int2");
118		};
119
120		assert_eq!(container.data().as_slice(), &[1, 0]);
121		assert!(container.is_defined(0));
122		assert!(!container.is_defined(1));
123	}
124
125	#[test]
126	fn test_int4() {
127		let mut col = ColumnData::int4(vec![1]);
128		col.push_undefined();
129		let ColumnData::Int4(container) = col else {
130			panic!("Expected Int4");
131		};
132
133		assert_eq!(container.data().as_slice(), &[1, 0]);
134		assert!(container.is_defined(0));
135		assert!(!container.is_defined(1));
136	}
137
138	#[test]
139	fn test_int8() {
140		let mut col = ColumnData::int8(vec![1]);
141		col.push_undefined();
142		let ColumnData::Int8(container) = col else {
143			panic!("Expected Int8");
144		};
145
146		assert_eq!(container.data().as_slice(), &[1, 0]);
147		assert!(container.is_defined(0));
148		assert!(!container.is_defined(1));
149	}
150
151	#[test]
152	fn test_int16() {
153		let mut col = ColumnData::int16(vec![1]);
154		col.push_undefined();
155		let ColumnData::Int16(container) = col else {
156			panic!("Expected Int16");
157		};
158
159		assert_eq!(container.data().as_slice(), &[1, 0]);
160		assert!(container.is_defined(0));
161		assert!(!container.is_defined(1));
162	}
163
164	#[test]
165	fn test_string() {
166		let mut col = ColumnData::utf8(vec!["a"]);
167		col.push_undefined();
168		let ColumnData::Utf8 {
169			container,
170			..
171		} = col
172		else {
173			panic!("Expected Utf8");
174		};
175
176		assert_eq!(container.data().as_slice(), &["a".to_string(), "".to_string()]);
177		assert!(container.is_defined(0));
178		assert!(!container.is_defined(1));
179	}
180
181	#[test]
182	fn test_uint1() {
183		let mut col = ColumnData::uint1(vec![1]);
184		col.push_undefined();
185		let ColumnData::Uint1(container) = col else {
186			panic!("Expected Uint1");
187		};
188
189		assert_eq!(container.data().as_slice(), &[1, 0]);
190		assert!(container.is_defined(0));
191		assert!(!container.is_defined(1));
192	}
193
194	#[test]
195	fn test_uint2() {
196		let mut col = ColumnData::uint2(vec![1]);
197		col.push_undefined();
198		let ColumnData::Uint2(container) = col else {
199			panic!("Expected Uint2");
200		};
201
202		assert_eq!(container.data().as_slice(), &[1, 0]);
203		assert!(container.is_defined(0));
204		assert!(!container.is_defined(1));
205	}
206
207	#[test]
208	fn test_uint4() {
209		let mut col = ColumnData::uint4(vec![1]);
210		col.push_undefined();
211		let ColumnData::Uint4(container) = col else {
212			panic!("Expected Uint4");
213		};
214
215		assert_eq!(container.data().as_slice(), &[1, 0]);
216		assert!(container.is_defined(0));
217		assert!(!container.is_defined(1));
218	}
219
220	#[test]
221	fn test_uint8() {
222		let mut col = ColumnData::uint8(vec![1]);
223		col.push_undefined();
224		let ColumnData::Uint8(container) = col else {
225			panic!("Expected Uint8");
226		};
227
228		assert_eq!(container.data().as_slice(), &[1, 0]);
229		assert!(container.is_defined(0));
230		assert!(!container.is_defined(1));
231	}
232
233	#[test]
234	fn test_uint16() {
235		let mut col = ColumnData::uint16(vec![1]);
236		col.push_undefined();
237		let ColumnData::Uint16(container) = col else {
238			panic!("Expected Uint16");
239		};
240
241		assert_eq!(container.data().as_slice(), &[1, 0]);
242		assert!(container.is_defined(0));
243		assert!(!container.is_defined(1));
244	}
245
246	#[test]
247	fn test_undefined() {
248		let mut col = ColumnData::undefined(5);
249		col.push_undefined();
250		let ColumnData::Undefined(container) = col else {
251			panic!("Expected Undefined");
252		};
253
254		assert_eq!(container.len(), 6);
255	}
256}