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

vortex-data / vortex / 16665166725

01 Aug 2025 03:01AM UTC coverage: 83.346% (+0.7%) from 82.687%
16665166725

Pull #4050

github

web-flow
Merge 4ef638346 into e9c2c7c3b
Pull Request #4050: chore: C++ API improvement

46203 of 55435 relevant lines covered (83.35%)

452462.64 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> {
117✔
18
        let children = self
117✔
19
            .children()
117✔
20
            .into_iter()
117✔
21
            .map(|child| child.serialize_proto())
117✔
22
            .try_collect()?;
117✔
23

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

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

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

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

49
    encoding.build(expr.metadata(), children)
117✔
50
}
117✔
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