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

vortex-data / vortex / 16653606492

31 Jul 2025 03:42PM UTC coverage: 83.029% (-0.02%) from 83.045%
16653606492

push

github

web-flow
feat: Add serialization support for Select expression (#4077)

Signed-off-by: Adam Gutglick <adam@spiraldb.com>

3 of 16 new or added lines in 2 files covered. (18.75%)

1 existing line in 1 file now uncovered.

46014 of 55419 relevant lines covered (83.03%)

452831.93 hits per line

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

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

4
use itertools::Itertools;
5
use vortex_error::{VortexResult, vortex_err};
6
use vortex_proto::expr as pb;
7

8
use crate::registry::ExprRegistry;
9
use crate::{ExprRef, VortexExpr};
10

11
pub trait ExprSerializeProtoExt {
12
    /// Serialize the expression to its protobuf representation.
13
    fn serialize_proto(&self) -> VortexResult<pb::Expr>;
14
}
15

16
impl ExprSerializeProtoExt for dyn VortexExpr + '_ {
17
    fn serialize_proto(&self) -> VortexResult<pb::Expr> {
11✔
18
        let children = self
11✔
19
            .children()
11✔
20
            .into_iter()
11✔
21
            .map(|child| child.serialize_proto())
11✔
22
            .try_collect()?;
11✔
23

24
        let metadata = self.metadata().ok_or_else(|| {
11✔
NEW
25
            vortex_err!("Expression '{}' is not serializable: {}", self.id(), self)
×
NEW
26
        })?;
×
27

28
        Ok(pb::Expr {
11✔
29
            id: self.id().to_string(),
11✔
30
            children,
11✔
31
            metadata: Some(metadata),
11✔
32
        })
11✔
33
    }
11✔
34
}
35

36
/// Deserialize a [`ExprRef`] from the protobuf representation.
37
pub fn deserialize_expr_proto(expr: &pb::Expr, registry: &ExprRegistry) -> VortexResult<ExprRef> {
11✔
38
    let expr_id = expr.id.as_str();
11✔
39
    let encoding = registry
11✔
40
        .get(expr_id)
11✔
41
        .ok_or_else(|| vortex_err!("unknown expression id: {}", expr_id))?;
11✔
42

43
    let children = expr
11✔
44
        .children
11✔
45
        .iter()
11✔
46
        .map(|e| deserialize_expr_proto(e, registry))
11✔
47
        .collect::<VortexResult<Vec<_>>>()?;
11✔
48

49
    encoding.build(expr.metadata(), children)
11✔
50
}
11✔
51

52
#[cfg(test)]
53
mod tests {
54
    use prost::Message;
55
    use vortex_array::compute::{BetweenOptions, StrictComparison};
56
    use vortex_proto::expr as pb;
57

58
    use crate::proto::{ExprSerializeProtoExt, deserialize_expr_proto};
59
    use crate::registry::ExprRegistryExt;
60
    use crate::{ExprRef, ExprRegistry, and, between, eq, get_item, lit, or, root};
61

62
    #[test]
63
    fn expression_serde() {
1✔
64
        let registry = ExprRegistry::default();
1✔
65
        let expr: ExprRef = or(
1✔
66
            and(
1✔
67
                between(
1✔
68
                    lit(1),
1✔
69
                    root(),
1✔
70
                    get_item("a", root()),
1✔
71
                    BetweenOptions {
1✔
72
                        lower_strict: StrictComparison::Strict,
1✔
73
                        upper_strict: StrictComparison::Strict,
1✔
74
                    },
1✔
75
                ),
1✔
76
                lit(1),
1✔
77
            ),
1✔
78
            eq(lit(1), root()),
1✔
79
        );
1✔
80

81
        let s_expr = expr.serialize_proto().unwrap();
1✔
82
        let buf = s_expr.encode_to_vec();
1✔
83
        let s_expr = pb::Expr::decode(buf.as_slice()).unwrap();
1✔
84
        let deser_expr = deserialize_expr_proto(&s_expr, &registry).unwrap();
1✔
85

86
        assert_eq!(&deser_expr, &expr);
1✔
87
    }
1✔
88
}
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