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

vortex-data / vortex / 16935267080

13 Aug 2025 11:00AM UTC coverage: 24.312% (-63.3%) from 87.658%
16935267080

Pull #4226

github

web-flow
Merge 81b48c7fb into baa6ea202
Pull Request #4226: Support converting TimestampTZ to and from duckdb

0 of 2 new or added lines in 1 file covered. (0.0%)

20666 existing lines in 469 files now uncovered.

8726 of 35892 relevant lines covered (24.31%)

147.74 hits per line

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

0.0
/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, Eq)]
18
pub struct CastExpr {
19
    target: DType,
20
    child: ExprRef,
21
}
22

23
impl PartialEq for CastExpr {
UNCOV
24
    fn eq(&self, other: &Self) -> bool {
×
UNCOV
25
        self.target == other.target && self.child.eq(&other.child)
×
UNCOV
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

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

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

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

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

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

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

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

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

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

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

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

109
impl AnalysisExpr for CastExpr {}
110

UNCOV
111
pub fn cast(child: ExprRef, target: DType) -> ExprRef {
×
UNCOV
112
    CastExpr::new(child, target).into_expr()
×
UNCOV
113
}
×
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() {
126
        let dtype = test_harness::struct_dtype();
127
        assert_eq!(
128
            cast(root(), DType::Bool(Nullability::NonNullable))
129
                .return_dtype(&dtype)
130
                .unwrap(),
131
            DType::Bool(Nullability::NonNullable)
132
        );
133
    }
134

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

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

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

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