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

vortex-data / vortex / 16268681402

14 Jul 2025 01:49PM UTC coverage: 81.464% (+0.2%) from 81.235%
16268681402

Pull #3856

github

web-flow
Merge 3f50333da into 52555adbb
Pull Request #3856: fix: Drain prefetch buffer

15 of 27 new or added lines in 2 files covered. (55.56%)

115 existing lines in 13 files now uncovered.

46110 of 56602 relevant lines covered (81.46%)

146503.08 hits per line

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

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

4
use std::fmt::Display;
5

6
use vortex_array::compute::cast as compute_cast;
7
use vortex_array::{ArrayRef, DeserializeMetadata, ProstMetadata};
8
use vortex_dtype::DType;
9
use vortex_error::{VortexResult, vortex_bail, vortex_err};
10
use vortex_proto::expr as pb;
11

12
use crate::{AnalysisExpr, ExprEncodingRef, ExprId, ExprRef, IntoExpr, Scope, VTable, vtable};
13

14
vtable!(Cast);
15

16
#[allow(clippy::derived_hash_with_manual_eq)]
17
#[derive(Debug, Clone, Hash)]
18
pub struct CastExpr {
19
    target: DType,
20
    child: ExprRef,
21
}
22

23
impl PartialEq for CastExpr {
24
    fn eq(&self, other: &Self) -> bool {
×
25
        self.target == other.target && self.child.eq(&other.child)
×
26
    }
×
27
}
28

29
pub struct CastExprEncoding;
30

31
impl VTable for CastVTable {
32
    type Expr = CastExpr;
33
    type Encoding = CastExprEncoding;
34
    type Metadata = ProstMetadata<pb::CastOpts>;
35

36
    fn id(_encoding: &Self::Encoding) -> ExprId {
×
37
        ExprId::new_ref("cast")
×
38
    }
×
39

40
    fn encoding(_expr: &Self::Expr) -> ExprEncodingRef {
×
41
        ExprEncodingRef::new_ref(CastExprEncoding.as_ref())
×
42
    }
×
43

44
    fn metadata(expr: &Self::Expr) -> Option<Self::Metadata> {
×
45
        Some(ProstMetadata(pb::CastOpts {
×
46
            target: Some((&expr.target).into()),
×
47
        }))
×
48
    }
×
49

50
    fn children(expr: &Self::Expr) -> Vec<&ExprRef> {
1✔
51
        vec![&expr.child]
1✔
52
    }
1✔
53

54
    fn with_children(expr: &Self::Expr, children: Vec<ExprRef>) -> VortexResult<Self::Expr> {
1✔
55
        Ok(CastExpr {
1✔
56
            target: expr.target.clone(),
1✔
57
            child: children[0].clone(),
1✔
58
        })
1✔
59
    }
1✔
60

61
    fn build(
×
62
        _encoding: &Self::Encoding,
×
63
        metadata: &<Self::Metadata as DeserializeMetadata>::Output,
×
64
        children: Vec<ExprRef>,
×
65
    ) -> VortexResult<Self::Expr> {
×
66
        if children.len() != 1 {
×
67
            vortex_bail!(
×
68
                "Cast expression must have exactly 1 child, got {}",
×
69
                children.len()
×
70
            );
×
71
        }
×
72
        let target: DType = metadata
×
73
            .target
×
74
            .as_ref()
×
75
            .ok_or_else(|| vortex_err!("missing target dtype in CastOpts"))?
×
76
            .try_into()?;
×
77
        Ok(CastExpr {
×
78
            target,
×
79
            child: children[0].clone(),
×
80
        })
×
81
    }
×
82

83
    fn evaluate(expr: &Self::Expr, scope: &Scope) -> VortexResult<ArrayRef> {
1✔
84
        let array = expr.child.evaluate(scope)?;
1✔
85
        compute_cast(&array, &expr.target)
1✔
86
    }
1✔
87

88
    fn return_dtype(expr: &Self::Expr, _scope: &DType) -> VortexResult<DType> {
2✔
89
        Ok(expr.target.clone())
2✔
90
    }
2✔
91
}
92

93
impl CastExpr {
94
    pub fn new(child: ExprRef, target: DType) -> Self {
3✔
95
        Self { target, child }
3✔
96
    }
3✔
97

UNCOV
98
    pub fn new_expr(child: ExprRef, target: DType) -> ExprRef {
×
UNCOV
99
        Self::new(child, target).into_expr()
×
100
    }
×
101
}
102

103
impl Display for CastExpr {
UNCOV
104
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
UNCOV
105
        write!(f, "cast({}, {})", self.child, self.target)
×
UNCOV
106
    }
×
107
}
108

109
impl AnalysisExpr for CastExpr {}
110

111
pub fn cast(child: ExprRef, target: DType) -> ExprRef {
3✔
112
    CastExpr::new(child, target).into_expr()
3✔
113
}
3✔
114

115
#[cfg(test)]
116
mod tests {
117
    use vortex_array::IntoArray;
118
    use vortex_array::arrays::StructArray;
119
    use vortex_buffer::buffer;
120
    use vortex_dtype::{DType, Nullability, PType};
121

122
    use crate::{ExprRef, Scope, cast, get_item, root, test_harness};
123

124
    #[test]
125
    fn dtype() {
1✔
126
        let dtype = test_harness::struct_dtype();
1✔
127
        assert_eq!(
1✔
128
            cast(root(), DType::Bool(Nullability::NonNullable))
1✔
129
                .return_dtype(&dtype)
1✔
130
                .unwrap(),
1✔
131
            DType::Bool(Nullability::NonNullable)
1✔
132
        );
1✔
133
    }
1✔
134

135
    #[test]
136
    fn replace_children() {
1✔
137
        let expr = cast(root(), DType::Bool(Nullability::Nullable));
1✔
138
        let _ = expr.with_children(vec![root()]);
1✔
139
    }
1✔
140

141
    #[test]
142
    fn evaluate() {
1✔
143
        let test_array = StructArray::from_fields(&[
1✔
144
            ("a", buffer![0i32, 1, 2].into_array()),
1✔
145
            ("b", buffer![4i64, 5, 6].into_array()),
1✔
146
        ])
1✔
147
        .unwrap()
1✔
148
        .into_array();
1✔
149

1✔
150
        let expr: ExprRef = cast(
1✔
151
            get_item("a", root()),
1✔
152
            DType::Primitive(PType::I64, Nullability::NonNullable),
1✔
153
        );
1✔
154
        let result = expr.evaluate(&Scope::new(test_array)).unwrap();
1✔
155

1✔
156
        assert_eq!(
1✔
157
            result.dtype(),
1✔
158
            &DType::Primitive(PType::I64, Nullability::NonNullable)
1✔
159
        );
1✔
160
    }
1✔
161
}
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