reifydb_core/value/column/push/
none.rs1use crate::value::column::builder::ColumnBuilder;
5
6impl ColumnBuilder {
7 pub fn push_none(&mut self) {
8 self.inner.append_null();
9 self.optional = true;
10 }
11}
12
13#[cfg(test)]
14pub mod tests {
15 use arrow_array::ArrayRef;
16 use arrow_schema::FieldRef;
17 use reifydb_runtime::context::{
18 clock::{Clock, MockClock},
19 rng::Rng,
20 };
21 use reifydb_value::value::{
22 column_view::ColumnView, dictionary::DictionaryEntryId, identity::IdentityId, value_type::ValueType,
23 };
24
25 use crate::value::column::{builder::ColumnBuilder, factory};
26
27 fn builder_of(column: (FieldRef, ArrayRef)) -> ColumnBuilder {
28 ColumnBuilder::from_view(&ColumnView::try_from(&column).unwrap())
29 }
30
31 fn view(column: &(FieldRef, ArrayRef)) -> ColumnView<'_> {
32 ColumnView::try_from(column).unwrap()
33 }
34
35 fn test_clock_and_rng() -> (MockClock, Clock, Rng) {
36 let mock = MockClock::from_millis(1000);
37 let clock = Clock::Mock(mock.clone());
38 let rng = Rng::seeded(42);
39 (mock, clock, rng)
40 }
41
42 #[test]
43 fn test_bool() {
44 let mut col = builder_of(factory::bool("c", vec![true]));
45 col.push_none();
46 let col = col.finish("c");
48 let col = view(&col);
49 assert!(col.is_defined(0));
50 assert!(!col.is_defined(1));
51 assert_eq!(col.len(), 2);
52 }
53
54 #[test]
55 fn test_float4() {
56 let mut col = builder_of(factory::float4("c", vec![1.0]));
57 col.push_none();
58 let col = col.finish("c");
59 let col = view(&col);
60 assert!(col.is_defined(0));
61 assert!(!col.is_defined(1));
62 assert_eq!(col.len(), 2);
63 }
64
65 #[test]
66 fn test_float8() {
67 let mut col = builder_of(factory::float8("c", vec![1.0]));
68 col.push_none();
69 let col = col.finish("c");
70 let col = view(&col);
71 assert!(col.is_defined(0));
72 assert!(!col.is_defined(1));
73 assert_eq!(col.len(), 2);
74 }
75
76 #[test]
77 fn test_int1() {
78 let mut col = builder_of(factory::int1("c", vec![1]));
79 col.push_none();
80 let col = col.finish("c");
81 let col = view(&col);
82 assert!(col.is_defined(0));
83 assert!(!col.is_defined(1));
84 assert_eq!(col.len(), 2);
85 }
86
87 #[test]
88 fn test_int2() {
89 let mut col = builder_of(factory::int2("c", vec![1]));
90 col.push_none();
91 let col = col.finish("c");
92 let col = view(&col);
93 assert!(col.is_defined(0));
94 assert!(!col.is_defined(1));
95 assert_eq!(col.len(), 2);
96 }
97
98 #[test]
99 fn test_int4() {
100 let mut col = builder_of(factory::int4("c", vec![1]));
101 col.push_none();
102 let col = col.finish("c");
103 let col = view(&col);
104 assert!(col.is_defined(0));
105 assert!(!col.is_defined(1));
106 assert_eq!(col.len(), 2);
107 }
108
109 #[test]
110 fn test_int8() {
111 let mut col = builder_of(factory::int8("c", vec![1]));
112 col.push_none();
113 let col = col.finish("c");
114 let col = view(&col);
115 assert!(col.is_defined(0));
116 assert!(!col.is_defined(1));
117 assert_eq!(col.len(), 2);
118 }
119
120 #[test]
121 fn test_int16() {
122 let mut col = builder_of(factory::int16("c", vec![1]));
123 col.push_none();
124 let col = col.finish("c");
125 let col = view(&col);
126 assert!(col.is_defined(0));
127 assert!(!col.is_defined(1));
128 assert_eq!(col.len(), 2);
129 }
130
131 #[test]
132 fn test_string() {
133 let mut col = builder_of(factory::utf8("c", vec!["a"]));
134 col.push_none();
135 let col = col.finish("c");
136 let col = view(&col);
137 assert!(col.is_defined(0));
138 assert!(!col.is_defined(1));
139 assert_eq!(col.len(), 2);
140 }
141
142 #[test]
143 fn test_uint1() {
144 let mut col = builder_of(factory::uint1("c", vec![1]));
145 col.push_none();
146 let col = col.finish("c");
147 let col = view(&col);
148 assert!(col.is_defined(0));
149 assert!(!col.is_defined(1));
150 assert_eq!(col.len(), 2);
151 }
152
153 #[test]
154 fn test_uint2() {
155 let mut col = builder_of(factory::uint2("c", vec![1]));
156 col.push_none();
157 let col = col.finish("c");
158 let col = view(&col);
159 assert!(col.is_defined(0));
160 assert!(!col.is_defined(1));
161 assert_eq!(col.len(), 2);
162 }
163
164 #[test]
165 fn test_uint4() {
166 let mut col = builder_of(factory::uint4("c", vec![1]));
167 col.push_none();
168 let col = col.finish("c");
169 let col = view(&col);
170 assert!(col.is_defined(0));
171 assert!(!col.is_defined(1));
172 assert_eq!(col.len(), 2);
173 }
174
175 #[test]
176 fn test_uint8() {
177 let mut col = builder_of(factory::uint8("c", vec![1]));
178 col.push_none();
179 let col = col.finish("c");
180 let col = view(&col);
181 assert!(col.is_defined(0));
182 assert!(!col.is_defined(1));
183 assert_eq!(col.len(), 2);
184 }
185
186 #[test]
187 fn test_uint16() {
188 let mut col = builder_of(factory::uint16("c", vec![1]));
189 col.push_none();
190 let col = col.finish("c");
191 let col = view(&col);
192 assert!(col.is_defined(0));
193 assert!(!col.is_defined(1));
194 assert_eq!(col.len(), 2);
195 }
196
197 #[test]
198 fn test_identity_id() {
199 let (_, clock, rng) = test_clock_and_rng();
200 let mut col = builder_of(factory::identity_id("c", vec![IdentityId::generate(&clock, &rng)]));
201 col.push_none();
202 let col = col.finish("c");
203 let col = view(&col);
204 assert!(col.is_defined(0));
205 assert!(!col.is_defined(1));
206 assert_eq!(col.len(), 2);
207 }
208
209 #[test]
210 fn test_dictionary_id() {
211 let mut col = builder_of(factory::dictionary_id("c", vec![DictionaryEntryId::U4(10)]));
212 col.push_none();
213 let col = col.finish("c");
214 let col = view(&col);
215 assert!(col.is_defined(0));
216 assert!(!col.is_defined(1));
217 assert_eq!(col.len(), 2);
218 }
219
220 #[test]
221 fn test_none_on_option() {
222 let mut col = builder_of(factory::none_typed("c", ValueType::Boolean, 5));
223 col.push_none();
224 let col = col.finish("c");
225 let col = view(&col);
226 assert_eq!(col.len(), 6);
227 assert!(!col.is_defined(0));
228 assert!(!col.is_defined(5));
229 }
230}