reifydb-core 0.4.13

Core database interfaces and data structures for ReifyDB
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2025 ReifyDB

use std::fmt;

use reifydb_type::{
	fragment::Fragment,
	util::bitvec::BitVec,
	value::{
		dictionary::DictionaryEntryId,
		r#type::Type,
		uuid::{Uuid4, Uuid7},
	},
};

use crate::value::column::{array::Column, buffer::ColumnBuffer};

pub mod array;
pub mod buffer;
pub mod columns;
pub mod compressed;
pub mod encoding;
pub mod frame;
pub mod headers;
pub mod mask;
pub mod nones;
pub mod push;
pub mod row;
pub mod row_ref;
pub mod stats;
pub mod transform;
pub mod view;

pub struct ColumnWithName {
	pub name: Fragment,
	pub data: ColumnBuffer,
}

impl Clone for ColumnWithName {
	fn clone(&self) -> Self {
		Self {
			name: self.name.clone(),
			data: self.data.clone(),
		}
	}
}

impl PartialEq for ColumnWithName {
	fn eq(&self, other: &Self) -> bool {
		self.name == other.name && self.data == other.data
	}
}

impl fmt::Debug for ColumnWithName {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		f.debug_struct("ColumnWithName").field("name", &self.name).field("data", &self.data).finish()
	}
}

impl ColumnWithName {
	pub fn new(name: impl Into<Fragment>, data: ColumnBuffer) -> Self {
		Self {
			name: name.into(),
			data,
		}
	}

	// Build a named column from a polymorphic `Column` trait-object handle.
	// Materializes via `to_canonical` + `to_buffer` (Arc-bumps the inner
	// buffer when the `Column` is already canonical).
	pub fn from_column(name: impl Into<Fragment>, column: Column) -> Self {
		let buffer = column
			.to_canonical()
			.map(|c| c.to_buffer())
			.unwrap_or_else(|_| panic!("ColumnWithName::from_column: to_canonical failed"));
		Self {
			name: name.into(),
			data: buffer,
		}
	}

	pub fn get_type(&self) -> Type {
		self.data.get_type()
	}

	pub fn with_new_data(&self, data: ColumnBuffer) -> ColumnWithName {
		ColumnWithName {
			name: self.name.clone(),
			data,
		}
	}

	pub fn name(&self) -> &Fragment {
		&self.name
	}

	pub fn name_owned(&self) -> Fragment {
		self.name.clone()
	}

	pub fn data(&self) -> &ColumnBuffer {
		&self.data
	}

	pub fn data_mut(&mut self) -> &mut ColumnBuffer {
		&mut self.data
	}

	// Return a polymorphic `Column` handle (trait-object wrapper around the
	// canonical form of `self.data`). Use this when you need encoding-agnostic
	// read operators (`filter`, `take`, `slice`, ...) or downcasting to
	// specialized impls - compressed encodings live behind this boundary.
	pub fn column(&self) -> Column {
		Column::from_column_buffer(self.data.clone())
	}

	pub fn to_static(&self) -> ColumnWithName {
		self.clone()
	}
}

impl ColumnWithName {
	pub fn int1(name: impl Into<Fragment>, data: impl IntoIterator<Item = i8>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int1(data),
		}
	}

	pub fn int1_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = i8>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int1_with_bitvec(data, bitvec),
		}
	}

	pub fn int2(name: impl Into<Fragment>, data: impl IntoIterator<Item = i16>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int2(data),
		}
	}

	pub fn int2_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = i16>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int2_with_bitvec(data, bitvec),
		}
	}

	pub fn int4(name: impl Into<Fragment>, data: impl IntoIterator<Item = i32>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int4(data),
		}
	}

	pub fn int4_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = i32>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int4_with_bitvec(data, bitvec),
		}
	}

	pub fn int8(name: impl Into<Fragment>, data: impl IntoIterator<Item = i64>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int8(data),
		}
	}

	pub fn int8_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = i64>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int8_with_bitvec(data, bitvec),
		}
	}

	pub fn int16(name: impl Into<Fragment>, data: impl IntoIterator<Item = i128>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int16(data),
		}
	}

	pub fn int16_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = i128>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::int16_with_bitvec(data, bitvec),
		}
	}

	pub fn uint1(name: impl Into<Fragment>, data: impl IntoIterator<Item = u8>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint1(data),
		}
	}

	pub fn uint1_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = u8>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint1_with_bitvec(data, bitvec),
		}
	}

	pub fn uint2(name: impl Into<Fragment>, data: impl IntoIterator<Item = u16>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint2(data),
		}
	}

	pub fn uint2_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = u16>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint2_with_bitvec(data, bitvec),
		}
	}

	pub fn uint4(name: impl Into<Fragment>, data: impl IntoIterator<Item = u32>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint4(data),
		}
	}

	pub fn uint4_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = u32>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint4_with_bitvec(data, bitvec),
		}
	}

	pub fn uint8(name: impl Into<Fragment>, data: impl IntoIterator<Item = u64>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint8(data),
		}
	}

	pub fn uint8_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = u64>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint8_with_bitvec(data, bitvec),
		}
	}

	pub fn uint16(name: impl Into<Fragment>, data: impl IntoIterator<Item = u128>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint16(data),
		}
	}

	pub fn uint16_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = u128>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uint16_with_bitvec(data, bitvec),
		}
	}

	pub fn float4(name: impl Into<Fragment>, data: impl IntoIterator<Item = f32>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::float4(data),
		}
	}

	pub fn float4_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = f32>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::float4_with_bitvec(data, bitvec),
		}
	}

	pub fn float8(name: impl Into<Fragment>, data: impl IntoIterator<Item = f64>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::float8(data),
		}
	}

	pub fn float8_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = f64>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::float8_with_bitvec(data, bitvec),
		}
	}

	pub fn bool(name: impl Into<Fragment>, data: impl IntoIterator<Item = bool>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::bool(data),
		}
	}

	pub fn bool_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = bool>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::bool_with_bitvec(data, bitvec),
		}
	}

	pub fn utf8(name: impl Into<Fragment>, data: impl IntoIterator<Item = String>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::utf8(data),
		}
	}

	pub fn utf8_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = String>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::utf8_with_bitvec(data, bitvec),
		}
	}

	pub fn uuid4(name: impl Into<Fragment>, data: impl IntoIterator<Item = Uuid4>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uuid4(data),
		}
	}

	pub fn uuid4_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = Uuid4>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uuid4_with_bitvec(data, bitvec),
		}
	}

	pub fn uuid7(name: impl Into<Fragment>, data: impl IntoIterator<Item = Uuid7>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uuid7(data),
		}
	}

	pub fn uuid7_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = Uuid7>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::uuid7_with_bitvec(data, bitvec),
		}
	}

	pub fn dictionary_id(name: impl Into<Fragment>, data: impl IntoIterator<Item = DictionaryEntryId>) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::dictionary_id(data),
		}
	}

	pub fn dictionary_id_with_bitvec(
		name: impl Into<Fragment>,
		data: impl IntoIterator<Item = DictionaryEntryId>,
		bitvec: impl Into<BitVec>,
	) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::dictionary_id_with_bitvec(data, bitvec),
		}
	}

	pub fn undefined_typed(name: impl Into<Fragment>, ty: Type, row_count: usize) -> Self {
		ColumnWithName {
			name: name.into(),
			data: ColumnBuffer::none_typed(ty, row_count),
		}
	}
}