Skip to content

Commit c638116

Browse files
committed
chore[vortex-array]: remove SerdeVTable
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 35d12a3 commit c638116

File tree

84 files changed

+3125
-3162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3125
-3162
lines changed

encodings/alp/src/alp/array.rs

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,31 @@
44
use std::fmt::Debug;
55
use std::hash::Hash;
66

7-
use vortex_array::patches::Patches;
7+
use vortex_array::patches::{Patches, PatchesMetadata};
8+
use vortex_array::serde::ArrayChildren;
89
use vortex_array::stats::{ArrayStats, StatsSetRef};
910
use vortex_array::vtable::{
10-
ArrayVTable, CanonicalVTable, NotSupported, VTable, ValidityChild, ValidityVTableFromChild,
11+
ArrayVTable, CanonicalVTable, EncodeVTable, NotSupported, VTable, ValidityChild,
12+
ValidityVTableFromChild, VisitorVTable,
1113
};
1214
use vortex_array::{
13-
Array, ArrayEq, ArrayHash, ArrayRef, Canonical, EncodingId, EncodingRef, Precision, vtable,
15+
Array, ArrayBufferVisitor, ArrayChildVisitor, ArrayEq, ArrayHash, ArrayRef, Canonical,
16+
DeserializeMetadata, EncodingId, EncodingRef, Precision, ProstMetadata, SerializeMetadata,
17+
vtable,
1418
};
19+
use vortex_buffer::ByteBuffer;
1520
use vortex_dtype::{DType, PType};
16-
use vortex_error::{VortexExpect, VortexResult, vortex_ensure};
21+
use vortex_error::{VortexError, VortexExpect, VortexResult, vortex_bail, vortex_ensure};
1722

1823
use crate::ALPFloat;
19-
use crate::alp::{Exponents, decompress};
24+
use crate::alp::{Exponents, alp_encode, decompress};
2025

2126
vtable!(ALP);
2227

2328
impl VTable for ALPVTable {
2429
type Array = ALPArray;
2530
type Encoding = ALPEncoding;
31+
type Metadata = ProstMetadata<ALPMetadata>;
2632

2733
type ArrayVTable = Self;
2834
type CanonicalVTable = Self;
@@ -31,7 +37,6 @@ impl VTable for ALPVTable {
3137
type VisitorVTable = Self;
3238
type ComputeVTable = NotSupported;
3339
type EncodeVTable = Self;
34-
type SerdeVTable = Self;
3540
type OperatorVTable = NotSupported;
3641

3742
fn id(_encoding: &Self::Encoding) -> EncodingId {
@@ -41,6 +46,73 @@ impl VTable for ALPVTable {
4146
fn encoding(_array: &Self::Array) -> EncodingRef {
4247
EncodingRef::new_ref(ALPEncoding.as_ref())
4348
}
49+
50+
fn metadata(array: &ALPArray) -> VortexResult<Self::Metadata> {
51+
let exponents = array.exponents();
52+
Ok(ProstMetadata(ALPMetadata {
53+
exp_e: exponents.e as u32,
54+
exp_f: exponents.f as u32,
55+
patches: array
56+
.patches()
57+
.map(|p| p.to_metadata(array.len(), array.dtype()))
58+
.transpose()?,
59+
}))
60+
}
61+
62+
fn serialize(metadata: Self::Metadata) -> VortexResult<Option<Vec<u8>>> {
63+
Ok(Some(metadata.serialize()))
64+
}
65+
66+
fn deserialize(buffer: &[u8]) -> VortexResult<Self::Metadata> {
67+
Ok(ProstMetadata(
68+
<ProstMetadata<ALPMetadata> as DeserializeMetadata>::deserialize(buffer)?,
69+
))
70+
}
71+
72+
fn build(
73+
_encoding: &ALPEncoding,
74+
dtype: &DType,
75+
len: usize,
76+
metadata: &Self::Metadata,
77+
_buffers: &[ByteBuffer],
78+
children: &dyn ArrayChildren,
79+
) -> VortexResult<ALPArray> {
80+
let encoded_ptype = match &dtype {
81+
DType::Primitive(PType::F32, n) => DType::Primitive(PType::I32, *n),
82+
DType::Primitive(PType::F64, n) => DType::Primitive(PType::I64, *n),
83+
d => vortex_bail!(MismatchedTypes: "f32 or f64", d),
84+
};
85+
let encoded = children.get(0, &encoded_ptype, len)?;
86+
87+
let patches = metadata
88+
.patches
89+
.map(|p| {
90+
let indices = children.get(1, &p.indices_dtype(), p.len())?;
91+
let values = children.get(2, dtype, p.len())?;
92+
let chunk_offsets = p
93+
.chunk_offsets_dtype()
94+
.map(|dtype| children.get(3, &dtype, usize::try_from(p.chunk_offsets_len())?))
95+
.transpose()?;
96+
97+
Ok::<_, VortexError>(Patches::new(
98+
len,
99+
p.offset(),
100+
indices,
101+
values,
102+
chunk_offsets,
103+
))
104+
})
105+
.transpose()?;
106+
107+
ALPArray::try_new(
108+
encoded,
109+
Exponents {
110+
e: u8::try_from(metadata.exp_e)?,
111+
f: u8::try_from(metadata.exp_f)?,
112+
},
113+
patches,
114+
)
115+
}
44116
}
45117

46118
#[derive(Clone, Debug)]
@@ -55,6 +127,16 @@ pub struct ALPArray {
55127
#[derive(Clone, Debug)]
56128
pub struct ALPEncoding;
57129

130+
#[derive(Clone, prost::Message)]
131+
pub struct ALPMetadata {
132+
#[prost(uint32, tag = "1")]
133+
pub(crate) exp_e: u32,
134+
#[prost(uint32, tag = "2")]
135+
pub(crate) exp_f: u32,
136+
#[prost(message, optional, tag = "3")]
137+
pub(crate) patches: Option<PatchesMetadata>,
138+
}
139+
58140
impl ALPArray {
59141
fn validate(
60142
encoded: &dyn Array,
@@ -285,3 +367,28 @@ impl CanonicalVTable<ALPVTable> for ALPVTable {
285367
Canonical::Primitive(decompress(array.clone()))
286368
}
287369
}
370+
371+
impl EncodeVTable<ALPVTable> for ALPVTable {
372+
fn encode(
373+
_encoding: &ALPEncoding,
374+
canonical: &Canonical,
375+
like: Option<&ALPArray>,
376+
) -> VortexResult<Option<ALPArray>> {
377+
let parray = canonical.clone().into_primitive();
378+
let exponents = like.map(|a| a.exponents());
379+
let alp = alp_encode(&parray, exponents)?;
380+
381+
Ok(Some(alp))
382+
}
383+
}
384+
385+
impl VisitorVTable<ALPVTable> for ALPVTable {
386+
fn visit_buffers(_array: &ALPArray, _visitor: &mut dyn ArrayBufferVisitor) {}
387+
388+
fn visit_children(array: &ALPArray, visitor: &mut dyn ArrayChildVisitor) {
389+
visitor.visit_child("encoded", array.encoded());
390+
if let Some(patches) = array.patches() {
391+
visitor.visit_patches(patches);
392+
}
393+
}
394+
}

encodings/alp/src/alp/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,36 @@ mod array;
1111
mod compress;
1212
mod compute;
1313
mod ops;
14-
mod serde;
14+
15+
#[cfg(test)]
16+
mod tests {
17+
use vortex_array::ProstMetadata;
18+
use vortex_array::patches::PatchesMetadata;
19+
use vortex_array::test_harness::check_metadata;
20+
use vortex_dtype::PType;
21+
22+
use crate::alp::array::ALPMetadata;
23+
24+
#[cfg_attr(miri, ignore)]
25+
#[test]
26+
fn test_alp_metadata() {
27+
check_metadata(
28+
"alp.metadata",
29+
ProstMetadata(ALPMetadata {
30+
patches: Some(PatchesMetadata::new(
31+
usize::MAX,
32+
usize::MAX,
33+
PType::U64,
34+
None,
35+
None,
36+
None,
37+
)),
38+
exp_e: u32::MAX,
39+
exp_f: u32::MAX,
40+
}),
41+
);
42+
}
43+
}
1544

1645
pub use array::*;
1746
pub use compress::*;

encodings/alp/src/alp/serde.rs

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)