@@ -9,18 +9,19 @@ use vortex_dtype::DType;
99use vortex_dtype:: FieldName ;
1010use vortex_dtype:: FieldPath ;
1111use vortex_dtype:: Nullability ;
12+ use vortex_error:: vortex_err;
13+ use vortex_error:: vortex_panic;
1214use vortex_error:: VortexExpect ;
1315use vortex_error:: VortexResult ;
14- use vortex_error:: vortex_err;
1516use vortex_mask:: Mask ;
1617use vortex_proto:: expr as pb;
1718use vortex_vector:: Datum ;
1819use vortex_vector:: ScalarOps ;
1920use vortex_vector:: VectorOps ;
2021
21- use crate :: ArrayRef ;
22- use crate :: ToCanonical ;
2322use crate :: compute:: mask;
23+ use crate :: expr:: exprs:: root:: root;
24+ use crate :: expr:: stats:: Stat ;
2425use crate :: expr:: Arity ;
2526use crate :: expr:: ChildName ;
2627use crate :: expr:: ExecutionArgs ;
@@ -31,8 +32,9 @@ use crate::expr::SimplifyCtx;
3132use crate :: expr:: StatsCatalog ;
3233use crate :: expr:: VTable ;
3334use crate :: expr:: VTableExt ;
34- use crate :: expr:: exprs:: root:: root;
35- use crate :: expr:: stats:: Stat ;
35+ use crate :: scalar_fns:: ExprBuiltins ;
36+ use crate :: ArrayRef ;
37+ use crate :: ToCanonical ;
3638
3739pub struct GetItem ;
3840
@@ -139,9 +141,10 @@ impl VTable for GetItem {
139141 & self ,
140142 field_name : & FieldName ,
141143 expr : & Expression ,
142- _ctx : & dyn SimplifyCtx ,
144+ ctx : & dyn SimplifyCtx ,
143145 ) -> VortexResult < Option < Expression > > {
144146 let child = expr. child ( 0 ) ;
147+ let child_dtype = ctx. return_dtype ( child) ?;
145148
146149 // If the child is a Pack expression, we can directly return the corresponding child.
147150 if let Some ( pack) = child. as_opt :: < Pack > ( ) {
@@ -157,7 +160,15 @@ impl VTable for GetItem {
157160 )
158161 } ) ?;
159162
160- return Ok ( Some ( child. child ( idx) . clone ( ) ) ) ;
163+ let mut field = child. child ( idx) . clone ( ) ;
164+
165+ // If the pack expression is nullable but the child field is not, we need to
166+ // adjust the nullability of the resulting expression.
167+ if pack. nullability . is_nullable ( ) && !child_dtype. is_nullable ( ) {
168+ field = field. cast ( child_dtype. as_nullable ( ) ) ?;
169+ }
170+
171+ return Ok ( Some ( field) ) ;
161172 }
162173
163174 Ok ( None )
@@ -232,15 +243,15 @@ mod tests {
232243 use vortex_dtype:: StructFields ;
233244 use vortex_scalar:: Scalar ;
234245
235- use crate :: Array ;
236- use crate :: IntoArray ;
237246 use crate :: arrays:: StructArray ;
238247 use crate :: expr:: exprs:: binary:: checked_add;
239248 use crate :: expr:: exprs:: get_item:: get_item;
240249 use crate :: expr:: exprs:: literal:: lit;
241250 use crate :: expr:: exprs:: pack:: pack;
242251 use crate :: expr:: exprs:: root:: root;
243252 use crate :: validity:: Validity ;
253+ use crate :: Array ;
254+ use crate :: IntoArray ;
244255
245256 fn test_array ( ) -> StructArray {
246257 StructArray :: from_fields ( & [
0 commit comments