• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16139349253

08 Jul 2025 09:26AM UTC coverage: 78.057% (-0.2%) from 78.253%
16139349253

push

github

web-flow
VortexExpr VTables (#3713)

Adds the same vtable machinery as arrays and layouts already use. It
uses the "Encoding" naming scheme from arrays and layouts. I don't
particularly like it, but it's consistent. Open to renames later.

Further, adds an expression registry to the Vortex session that will be
used for deserialization.

Expressions only decide their "options" serialization. So in theory, can
support many container formats, not just proto, provided each expression
can deserialize their own options format.

---------

Signed-off-by: Nicholas Gates <nick@nickgates.com>

800 of 1190 new or added lines in 38 files covered. (67.23%)

40 existing lines in 13 files now uncovered.

44100 of 56497 relevant lines covered (78.06%)

54989.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.3
/vortex-expr/src/encoding.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::any::Any;
5
use std::fmt::{Debug, Display, Formatter};
6

7
use arcref::ArcRef;
8
use vortex_array::DeserializeMetadata;
9
use vortex_error::{VortexExpect, VortexResult};
10

11
use crate::{ExprRef, IntoExpr, VTable};
12

13
pub type ExprId = ArcRef<str>;
14
pub type ExprEncodingRef = ArcRef<dyn ExprEncoding>;
15

16
/// Encoding trait for a Vortex expression.
17
///
18
/// An [`ExprEncoding`] can be registered with a Vortex session in order to support deserialization
19
/// via the expression protobuf representation.
20
pub trait ExprEncoding: 'static + Send + Sync + Debug + private::Sealed {
21
    fn as_any(&self) -> &dyn Any;
22

23
    /// Returns the ID of the expression encoding.
24
    fn id(&self) -> ExprId;
25

26
    /// Deserializes an expression from its serialized form.
27
    ///
28
    /// Returns `None` if the expression is not serializable.
29
    fn build(&self, metadata: &[u8], children: Vec<ExprRef>) -> VortexResult<ExprRef>;
30
}
31

32
#[repr(transparent)]
33
pub struct ExprEncodingAdapter<V: VTable>(V::Encoding);
34

35
impl<V: VTable> ExprEncoding for ExprEncodingAdapter<V> {
NEW
36
    fn as_any(&self) -> &dyn Any {
×
NEW
37
        self
×
NEW
38
    }
×
39

40
    fn id(&self) -> ExprId {
1,177✔
41
        V::id(&self.0)
1,177✔
42
    }
1,177✔
43

44
    fn build(&self, metadata: &[u8], children: Vec<ExprRef>) -> VortexResult<ExprRef> {
11✔
45
        let metadata = <V::Metadata as DeserializeMetadata>::deserialize(metadata)?;
11✔
46
        Ok(V::build(&self.0, &metadata, children)?.into_expr())
11✔
47
    }
11✔
48
}
49

50
impl<V: VTable> Debug for ExprEncodingAdapter<V> {
NEW
51
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
NEW
52
        f.debug_struct("ExprEncoding")
×
NEW
53
            .field("id", &self.id())
×
NEW
54
            .finish()
×
NEW
55
    }
×
56
}
57

58
impl Display for dyn ExprEncoding + '_ {
59
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1,166✔
60
        write!(f, "{}", self.id())
1,166✔
61
    }
1,166✔
62
}
63

64
impl PartialEq for dyn ExprEncoding + '_ {
NEW
65
    fn eq(&self, other: &Self) -> bool {
×
NEW
66
        self.id() == other.id()
×
NEW
67
    }
×
68
}
69

70
impl Eq for dyn ExprEncoding + '_ {}
71

72
impl dyn ExprEncoding + '_ {
NEW
73
    pub fn is<V: VTable>(&self) -> bool {
×
NEW
74
        self.as_opt::<V>().is_some()
×
NEW
75
    }
×
76

NEW
77
    pub fn as_<V: VTable>(&self) -> &V::Encoding {
×
NEW
78
        self.as_opt::<V>()
×
NEW
79
            .vortex_expect("ExprEncoding is not of the expected type")
×
NEW
80
    }
×
81

NEW
82
    pub fn as_opt<V: VTable>(&self) -> Option<&V::Encoding> {
×
NEW
83
        self.as_any()
×
NEW
84
            .downcast_ref::<ExprEncodingAdapter<V>>()
×
NEW
85
            .map(|e| &e.0)
×
NEW
86
    }
×
87
}
88

89
mod private {
90
    use super::*;
91

92
    pub trait Sealed {}
93

94
    impl<V: VTable> Sealed for ExprEncodingAdapter<V> {}
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc