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