vortex_fastlanes/for/
mod.rs1use std::fmt::Debug;
4
5pub use compress::*;
6use vortex_array::stats::{ArrayStats, StatsSetRef};
7use vortex_array::vtable::{
8 ArrayVTable, CanonicalVTable, NotSupported, VTable, ValidityChild, ValidityVTableFromChild,
9};
10use vortex_array::{Array, ArrayRef, Canonical, EncodingId, EncodingRef, vtable};
11use vortex_dtype::{DType, PType};
12use vortex_error::{VortexResult, vortex_bail};
13use vortex_scalar::Scalar;
14
15mod compress;
16mod compute;
17mod ops;
18mod pipeline;
19mod serde;
20
21vtable!(FoR);
22
23impl VTable for FoRVTable {
24 type Array = FoRArray;
25 type Encoding = FoREncoding;
26
27 type ArrayVTable = Self;
28 type CanonicalVTable = Self;
29 type OperationsVTable = Self;
30 type ValidityVTable = ValidityVTableFromChild;
31 type VisitorVTable = Self;
32 type ComputeVTable = NotSupported;
33 type EncodeVTable = Self;
34 type SerdeVTable = Self;
35 type PipelineVTable = Self;
36
37 fn id(_encoding: &Self::Encoding) -> EncodingId {
38 EncodingId::new_ref("fastlanes.for")
39 }
40
41 fn encoding(_array: &Self::Array) -> EncodingRef {
42 EncodingRef::new_ref(FoREncoding.as_ref())
43 }
44}
45
46#[derive(Clone, Debug)]
47pub struct FoRArray {
48 encoded: ArrayRef,
49 reference: Scalar,
50 stats_set: ArrayStats,
51}
52
53#[derive(Clone, Debug)]
54pub struct FoREncoding;
55
56impl FoRArray {
57 pub fn try_new(encoded: ArrayRef, reference: Scalar) -> VortexResult<Self> {
58 if reference.is_null() {
59 vortex_bail!("Reference value cannot be null");
60 }
61 let reference = reference.cast(
62 &reference
63 .dtype()
64 .with_nullability(encoded.dtype().nullability()),
65 )?;
66
67 Ok(Self {
68 encoded,
69 reference,
70 stats_set: Default::default(),
71 })
72 }
73
74 pub(crate) unsafe fn new_unchecked(encoded: ArrayRef, reference: Scalar) -> Self {
75 Self {
76 encoded,
77 reference,
78 stats_set: Default::default(),
79 }
80 }
81
82 #[inline]
83 pub fn ptype(&self) -> PType {
84 self.dtype().as_ptype()
85 }
86
87 #[inline]
88 pub fn encoded(&self) -> &ArrayRef {
89 &self.encoded
90 }
91
92 #[inline]
93 pub fn reference_scalar(&self) -> &Scalar {
94 &self.reference
95 }
96}
97
98impl ArrayVTable<FoRVTable> for FoRVTable {
99 fn len(array: &FoRArray) -> usize {
100 array.encoded().len()
101 }
102
103 fn dtype(array: &FoRArray) -> &DType {
104 array.reference_scalar().dtype()
105 }
106
107 fn stats(array: &FoRArray) -> StatsSetRef<'_> {
108 array.stats_set.to_ref(array.as_ref())
109 }
110}
111
112impl ValidityChild<FoRVTable> for FoRVTable {
113 fn validity_child(array: &FoRArray) -> &dyn Array {
114 array.encoded().as_ref()
115 }
116}
117
118impl CanonicalVTable<FoRVTable> for FoRVTable {
119 fn canonicalize(array: &FoRArray) -> Canonical {
120 Canonical::Primitive(decompress(array))
121 }
122}