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

vortex-data / vortex / 16331938722

16 Jul 2025 10:49PM UTC coverage: 80.702% (-0.9%) from 81.557%
16331938722

push

github

web-flow
feat: build with stable rust (#3881)

120 of 173 new or added lines in 28 files covered. (69.36%)

174 existing lines in 102 files now uncovered.

41861 of 51871 relevant lines covered (80.7%)

157487.71 hits per line

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

91.38
/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)]
22
pub struct GetItemExpr {
23
    field: FieldName,
24
    child: ExprRef,
25
}
26

27
impl PartialEq for GetItemExpr {
28
    fn eq(&self, other: &Self) -> bool {
39,183✔
29
        self.field == other.field && self.child.eq(&other.child)
39,183✔
30
    }
39,183✔
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

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

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

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

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

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

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

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

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

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

106
impl GetItemExpr {
107
    pub fn new(field: impl Into<FieldName>, child: ExprRef) -> Self {
24,894✔
108
        Self {
24,894✔
109
            field: field.into(),
24,894✔
110
            child,
24,894✔
111
        }
24,894✔
112
    }
24,894✔
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 {
42,549✔
119
        &self.field
42,549✔
120
    }
42,549✔
121

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

126
    pub fn is(expr: &ExprRef) -> bool {
1,699✔
127
        expr.is::<GetItemVTable>()
1,699✔
128
    }
1,699✔
129
}
130

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

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

139
pub fn get_item_scope(field: impl Into<FieldName>) -> ExprRef {
334✔
140
    GetItemExpr::new(field, root()).into_expr()
334✔
141
}
334✔
142

143
impl Display for GetItemExpr {
144
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22✔
145
        write!(f, "{}.{}", self.child, &self.field)
22✔
146
    }
22✔
147
}
148

149
impl AnalysisExpr for GetItemExpr {
150
    fn max(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
11✔
151
        catalog.stats_ref(&self.field_path()?, Stat::Max)
11✔
152
    }
11✔
153

154
    fn min(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
10✔
155
        catalog.stats_ref(&self.field_path()?, Stat::Min)
10✔
156
    }
10✔
157

158
    fn field_path(&self) -> Option<FieldPath> {
21✔
159
        self.child()
21✔
160
            .field_path()
21✔
161
            .map(|fp| fp.push(self.field.clone()))
21✔
162
    }
21✔
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 {
2✔
177
        StructArray::from_fields(&[
2✔
178
            ("a", buffer![0i32, 1, 2].into_array()),
2✔
179
            ("b", buffer![4i64, 5, 6].into_array()),
2✔
180
        ])
2✔
181
        .unwrap()
2✔
182
    }
2✔
183

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

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