@@ -11,7 +11,11 @@ use std::ops::BitOrAssign;
1111
1212use vortex_compute:: lane_kernels:: IndexedSourceExt ;
1313use vortex_error:: VortexResult ;
14+ use vortex_error:: vortex_bail;
1415use vortex_error:: vortex_ensure;
16+ use vortex_error:: vortex_ensure_eq;
17+ use vortex_mask:: AllOr ;
18+ use vortex_mask:: Mask ;
1519
1620use crate :: ArrayRef ;
1721use crate :: ExecutionCtx ;
@@ -49,6 +53,103 @@ where
4953 )
5054}
5155
56+ /// Decode nullable inputs, then store one output for each valid row from an infallible kernel.
57+ pub ( crate ) fn execute_owned_infallible_valid_rows < Args , Out , Prepared > (
58+ args : & dyn ExecutionArgs ,
59+ valid : & Mask ,
60+ ctx : & mut ExecutionCtx ,
61+ prepare : impl FnOnce ( Args :: ConstElems < ' _ > ) -> Prepared ,
62+ apply : impl Fn ( & Prepared , Args :: Elems < ' _ > ) -> Out ,
63+ ) -> VortexResult < Option < ArrayRef > >
64+ where
65+ Args : IndexedElementTuple ,
66+ Out : OutputElement ,
67+ {
68+ execute_owned_valid_rows :: < Args , Out , Prepared , NoFailure > (
69+ args,
70+ valid,
71+ ctx,
72+ prepare,
73+ move |prepared, args| ( apply ( prepared, args) , NoFailure ) ,
74+ |_| Ok ( ( ) ) ,
75+ )
76+ }
77+
78+ /// Decode nullable inputs, then store outputs and combine failure evidence for valid rows.
79+ pub ( crate ) fn execute_owned_valid_rows < Args , Out , Prepared , Fail > (
80+ args : & dyn ExecutionArgs ,
81+ valid : & Mask ,
82+ ctx : & mut ExecutionCtx ,
83+ prepare : impl FnOnce ( Args :: ConstElems < ' _ > ) -> Prepared ,
84+ apply : impl Fn ( & Prepared , Args :: Elems < ' _ > ) -> ( Out , Fail ) ,
85+ finish_failure : impl FnOnce ( Fail ) -> VortexResult < ( ) > ,
86+ ) -> VortexResult < Option < ArrayRef > >
87+ where
88+ Args : IndexedElementTuple ,
89+ Out : OutputElement ,
90+ Fail : FailureEvidence ,
91+ {
92+ const { assert_owned_output_needs_no_drop :: < Out > ( ) } ;
93+
94+ let Some ( columns) = Args :: decode_null_tolerant ( args, ctx) ? else {
95+ return Ok ( None ) ;
96+ } ;
97+
98+ let row_count = args. row_count ( ) ;
99+ let AllOr :: Some ( valid_rows) = valid. bit_buffer ( ) else {
100+ vortex_bail ! (
101+ "execute_owned_valid_rows requires valid and invalid rows, got an all-valid or all-invalid mask"
102+ ) ;
103+ } ;
104+ vortex_ensure_eq ! (
105+ valid_rows. len( ) ,
106+ row_count,
107+ "the validity mask must address exactly {row_count} rows, got {}" ,
108+ valid_rows. len( ) ,
109+ ) ;
110+
111+ let prepared = prepare ( Args :: const_values ( & columns) ) ;
112+ let mut values: Vec < Out > = std:: iter:: repeat_with ( Out :: default)
113+ . take ( row_count)
114+ . collect ( ) ;
115+ let mut failure = Fail :: default ( ) ;
116+
117+ if let Some ( views) = Args :: views_if_no_consts ( & columns) {
118+ vortex_ensure ! (
119+ Args :: view_lens_match( & views, row_count) ,
120+ "a decoded row input does not address exactly {row_count} rows" ,
121+ ) ;
122+
123+ valid_rows. for_each_set_index ( |index| {
124+ // SAFETY: the tuple-wide length check proved every view has `row_count` rows, and mask
125+ // indices are below `row_count`. Nullary tuples do not access an input view.
126+ let elements = unsafe { Args :: get_from_views_unchecked ( & views, index) } ;
127+ let ( value, row_failure) = apply ( & prepared, elements) ;
128+
129+ // SAFETY: the mask length check proved that every set index is below `row_count`.
130+ unsafe { * values. get_unchecked_mut ( index) = value } ;
131+ failure |= row_failure;
132+ } ) ;
133+ } else {
134+ vortex_ensure ! (
135+ Args :: decoded_lens_match( & columns, row_count) ,
136+ "a decoded row input does not address exactly {row_count} rows" ,
137+ ) ;
138+
139+ valid_rows. for_each_set_index ( |index| {
140+ let ( value, row_failure) = apply ( & prepared, Args :: get ( & columns, index) ) ;
141+
142+ // SAFETY: the mask length check proved that every set index is below `row_count`.
143+ unsafe { * values. get_unchecked_mut ( index) = value } ;
144+ failure |= row_failure;
145+ } ) ;
146+ }
147+
148+ finish_failure ( failure) ?;
149+
150+ Ok ( Some ( Out :: build ( values) ) )
151+ }
152+
52153/// Decode every input column, then store outputs and combine per-row failure evidence.
53154pub ( crate ) fn execute_owned < Args , Out , Prepared , Fail > (
54155 args : & dyn ExecutionArgs ,
0 commit comments