• 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

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

4
use std::fmt::{Debug, Display, Formatter};
5
use std::hash::Hash;
6

7
use vortex_array::stats::Stat;
8
use vortex_array::{ArrayRef, DeserializeMetadata, ProstMetadata, ToCanonical};
9
use vortex_dtype::{DType, FieldName, FieldPath};
10
use vortex_error::{VortexResult, vortex_bail, vortex_err};
11
use vortex_proto::expr as pb;
12

13
use crate::{
14
    AnalysisExpr, ExprEncodingRef, ExprId, ExprRef, IntoExpr, Scope, StatsCatalog, VTable, root,
15
    vtable,
16
};
17

18
vtable!(GetItem);
19

20
#[allow(clippy::derived_hash_with_manual_eq)]
21
#[derive(Debug, Clone, Hash, Eq)]
22
pub struct GetItemExpr {
23
    field: FieldName,
24
    child: ExprRef,
25
}
26

27
impl PartialEq for GetItemExpr {
28
    fn eq(&self, other: &Self) -> bool {
20✔
29
        self.field == other.field && self.child.eq(&other.child)
20✔
30
    }
20✔
31
}
32

33
pub struct GetItemExprEncoding;
34

35
impl VTable for GetItemVTable {
36
    type Expr = GetItemExpr;
37
    type Encoding = GetItemExprEncoding;
38
    type Metadata = ProstMetadata<pb::GetItemOpts>;
39

UNCOV
40
    fn id(_encoding: &Self::Encoding) -> ExprId {
×
UNCOV
41
        ExprId::new_ref("get_item")
×
UNCOV
42
    }
×
43

UNCOV
44
    fn encoding(_expr: &Self::Expr) -> ExprEncodingRef {
×
UNCOV
45
        ExprEncodingRef::new_ref(GetItemExprEncoding.as_ref())
×
UNCOV
46
    }
×
47

UNCOV
48
    fn metadata(expr: &Self::Expr) -> Option<Self::Metadata> {
×
UNCOV
49
        Some(ProstMetadata(pb::GetItemOpts {
×
UNCOV
50
            path: expr.field.to_string(),
×
UNCOV
51
        }))
×
UNCOV
52
    }
×
53

54
    fn children(expr: &Self::Expr) -> Vec<&ExprRef> {
88✔
55
        vec![&expr.child]
88✔
56
    }
88✔
57

UNCOV
58
    fn with_children(expr: &Self::Expr, children: Vec<ExprRef>) -> VortexResult<Self::Expr> {
×
UNCOV
59
        Ok(GetItemExpr {
×
UNCOV
60
            field: expr.field.clone(),
×
UNCOV
61
            child: children[0].clone(),
×
UNCOV
62
        })
×
UNCOV
63
    }
×
64

UNCOV
65
    fn build(
×
UNCOV
66
        _encoding: &Self::Encoding,
×
UNCOV
67
        metadata: &<Self::Metadata as DeserializeMetadata>::Output,
×
UNCOV
68
        children: Vec<ExprRef>,
×
UNCOV
69
    ) -> VortexResult<Self::Expr> {
×
UNCOV
70
        if children.len() != 1 {
×
71
            vortex_bail!(
×
72
                "GetItem expression must have exactly 1 child, got {}",
×
73
                children.len()
×
74
            );
UNCOV
75
        }
×
76

UNCOV
77
        let field = FieldName::from(metadata.path.clone());
×
UNCOV
78
        Ok(GetItemExpr {
×
UNCOV
79
            field,
×
UNCOV
80
            child: children[0].clone(),
×
UNCOV
81
        })
×
UNCOV
82
    }
×
83

84
    fn evaluate(expr: &Self::Expr, scope: &Scope) -> VortexResult<ArrayRef> {
8✔
85
        expr.child
8✔
86
            .unchecked_evaluate(scope)?
8✔
87
            .to_struct()?
8✔
88
            .field_by_name(expr.field())
8✔
89
            .cloned()
8✔
90
    }
8✔
91

92
    fn return_dtype(expr: &Self::Expr, scope: &DType) -> VortexResult<DType> {
12✔
93
        let input = expr.child.return_dtype(scope)?;
12✔
94
        input
12✔
95
            .as_struct()
12✔
96
            .and_then(|st| st.field(expr.field()))
12✔
97
            .ok_or_else(|| {
12✔
98
                vortex_err!(
×
99
                    "Couldn't find the {} field in the input scope",
×
100
                    expr.field()
×
101
                )
102
            })
×
103
    }
12✔
104
}
105

106
impl GetItemExpr {
107
    pub fn new(field: impl Into<FieldName>, child: ExprRef) -> Self {
20✔
108
        Self {
20✔
109
            field: field.into(),
20✔
110
            child,
20✔
111
        }
20✔
112
    }
20✔
113

114
    pub fn new_expr(field: impl Into<FieldName>, child: ExprRef) -> ExprRef {
×
115
        Self::new(field, child).into_expr()
×
116
    }
×
117

118
    pub fn field(&self) -> &FieldName {
24✔
119
        &self.field
24✔
120
    }
24✔
121

122
    pub fn child(&self) -> &ExprRef {
44✔
123
        &self.child
44✔
124
    }
44✔
125

UNCOV
126
    pub fn is(expr: &ExprRef) -> bool {
×
UNCOV
127
        expr.is::<GetItemVTable>()
×
UNCOV
128
    }
×
129
}
130

131
pub fn col(field: impl Into<FieldName>) -> ExprRef {
8✔
132
    GetItemExpr::new(field, root()).into_expr()
8✔
133
}
8✔
134

135
pub fn get_item(field: impl Into<FieldName>, child: ExprRef) -> ExprRef {
12✔
136
    GetItemExpr::new(field, child).into_expr()
12✔
137
}
12✔
138

139
impl Display for GetItemExpr {
UNCOV
140
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
UNCOV
141
        write!(f, "{}.{}", self.child, &self.field)
×
UNCOV
142
    }
×
143
}
144

145
impl AnalysisExpr for GetItemExpr {
UNCOV
146
    fn max(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
×
UNCOV
147
        catalog.stats_ref(&self.field_path()?, Stat::Max)
×
UNCOV
148
    }
×
149

UNCOV
150
    fn min(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
×
UNCOV
151
        catalog.stats_ref(&self.field_path()?, Stat::Min)
×
UNCOV
152
    }
×
153

UNCOV
154
    fn nan_count(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
×
UNCOV
155
        catalog.stats_ref(&self.field_path()?, Stat::NaNCount)
×
UNCOV
156
    }
×
157

UNCOV
158
    fn field_path(&self) -> Option<FieldPath> {
×
UNCOV
159
        self.child()
×
UNCOV
160
            .field_path()
×
UNCOV
161
            .map(|fp| fp.push(self.field.clone()))
×
UNCOV
162
    }
×
163
}
164

165
#[cfg(test)]
166
mod tests {
167
    use vortex_array::IntoArray;
168
    use vortex_array::arrays::StructArray;
169
    use vortex_buffer::buffer;
170
    use vortex_dtype::DType;
171
    use vortex_dtype::PType::I32;
172

173
    use crate::get_item::get_item;
174
    use crate::{Scope, root};
175

176
    fn test_array() -> StructArray {
177
        StructArray::from_fields(&[
178
            ("a", buffer![0i32, 1, 2].into_array()),
179
            ("b", buffer![4i64, 5, 6].into_array()),
180
        ])
181
        .unwrap()
182
    }
183

184
    #[test]
185
    pub fn get_item_by_name() {
186
        let st = test_array();
187
        let get_item = get_item("a", root());
188
        let item = get_item.evaluate(&Scope::new(st.to_array())).unwrap();
189
        assert_eq!(item.dtype(), &DType::from(I32))
190
    }
191

192
    #[test]
193
    pub fn get_item_by_name_none() {
194
        let st = test_array();
195
        let get_item = get_item("c", root());
196
        assert!(get_item.evaluate(&Scope::new(st.to_array())).is_err());
197
    }
198
}
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