@@ -2,8 +2,8 @@ use std::fmt::{Debug, Display};
2
2
use std:: sync:: Arc ;
3
3
4
4
use serde:: { Deserialize , Serialize } ;
5
- use vortex_dtype:: { DType , Field , FieldName , FieldNames , StructDType } ;
6
- use vortex_error:: { vortex_bail, vortex_err, vortex_panic , VortexExpect as _, VortexResult } ;
5
+ use vortex_dtype:: { DType , FieldName , FieldNames , StructDType } ;
6
+ use vortex_error:: { vortex_bail, vortex_err, VortexExpect as _, VortexResult } ;
7
7
use vortex_mask:: Mask ;
8
8
9
9
use crate :: encoding:: encoding_ids;
@@ -51,9 +51,8 @@ impl StructArray {
51
51
52
52
pub fn children ( & self ) -> impl Iterator < Item = Array > + ' _ {
53
53
( 0 ..self . nfields ( ) ) . map ( move |idx| {
54
- self . maybe_null_field_by_idx ( idx) . unwrap_or_else ( || {
55
- vortex_panic ! ( "Field {} not found, nfields: {}" , idx, self . nfields( ) )
56
- } )
54
+ self . maybe_null_field_by_idx ( idx)
55
+ . vortex_expect ( "never out of bounds" )
57
56
} )
58
57
}
59
58
@@ -138,7 +137,7 @@ impl StructArray {
138
137
names. push ( self . names ( ) [ idx] . clone ( ) ) ;
139
138
children. push (
140
139
self . maybe_null_field_by_idx ( idx)
141
- . ok_or_else ( || vortex_err ! ( OutOfBounds : idx , 0 , self . nfields ( ) ) ) ? ,
140
+ . vortex_expect ( "never out of bounds" ) ,
142
141
) ;
143
142
}
144
143
@@ -160,25 +159,13 @@ impl VariantsVTable<StructArray> for StructEncoding {
160
159
}
161
160
162
161
impl StructArrayTrait for StructArray {
163
- fn maybe_null_field_by_idx ( & self , idx : usize ) -> Option < Array > {
164
- Some (
165
- self . field_info ( & Field :: Index ( idx) )
166
- . map ( |field_info| {
167
- self . as_ref ( )
168
- . child (
169
- idx,
170
- & field_info
171
- . dtype
172
- . value ( )
173
- . vortex_expect ( "FieldInfo could not access dtype" ) ,
174
- self . len ( ) ,
175
- )
176
- . unwrap_or_else ( |e| {
177
- vortex_panic ! ( e, "StructArray: field {} not found" , idx)
178
- } )
179
- } )
180
- . unwrap_or_else ( |e| vortex_panic ! ( e, "StructArray: field {} not found" , idx) ) ,
181
- )
162
+ fn maybe_null_field_by_idx ( & self , idx : usize ) -> VortexResult < Array > {
163
+ let dtype = self
164
+ . dtype ( )
165
+ . as_struct ( )
166
+ . vortex_expect ( "Not a struct dtype" )
167
+ . field_by_index ( idx) ?;
168
+ self . child ( idx, & dtype, self . len ( ) )
182
169
}
183
170
184
171
fn project ( & self , projection : & [ FieldName ] ) -> VortexResult < Array > {
@@ -210,9 +197,7 @@ impl ValidityVTable<StructArray> for StructEncoding {
210
197
impl VisitorVTable < StructArray > for StructEncoding {
211
198
fn accept ( & self , array : & StructArray , visitor : & mut dyn ArrayVisitor ) -> VortexResult < ( ) > {
212
199
for ( idx, name) in array. names ( ) . iter ( ) . enumerate ( ) {
213
- let child = array
214
- . maybe_null_field_by_idx ( idx)
215
- . ok_or_else ( || vortex_err ! ( OutOfBounds : idx, 0 , array. nfields( ) ) ) ?;
200
+ let child = array. maybe_null_field_by_idx ( idx) ?;
216
201
visitor. visit_child ( name. as_ref ( ) , & child) ?;
217
202
}
218
203
0 commit comments