@@ -14,7 +14,7 @@ use vortex_error::vortex_ensure_eq;
1414use vortex_mask:: AllOr ;
1515use vortex_mask:: Mask ;
1616
17- use super :: RowExecution ;
17+ use crate :: ArrayRef ;
1818use crate :: ExecutionCtx ;
1919use crate :: scalar_fn:: ExecutionArgs ;
2020use crate :: scalar_fn:: unstable:: row:: ElementTuple ;
@@ -32,7 +32,7 @@ pub(crate) fn execute_sink<Args, Prepared, Sink, ApplyResult, Options>(
3232 ctx : & mut ExecutionCtx ,
3333 prepare : impl FnOnce ( Args :: ConstElems < ' _ > ) -> Prepared ,
3434 apply : impl Fn ( & Prepared , Args :: Elems < ' _ > , <Sink as OutputSink < Options > >:: Row < ' _ > ) -> ApplyResult ,
35- ) -> VortexResult < RowExecution >
35+ ) -> VortexResult < ArrayRef >
3636where
3737 Args : ElementTuple ,
3838 Sink : OutputSink < Options > ,
@@ -60,13 +60,13 @@ where
6060
6161 let views = Args :: views_if_no_consts ( & columns) ;
6262 if let Some ( views) = views {
63- if Args :: ARITY != 0 && views. len ( ) != row_count {
63+ if ! Args :: view_lens_match ( & views, row_count) {
6464 decoded_length_error ( row_count) ?;
6565 }
6666
6767 for index in 0 ..row_count {
68- // SAFETY: the tuple length check proved every non-nullary view has `row_count`
69- // rows before the loop. Nullary tuples do not access an input view .
68+ // SAFETY: `view_lens_match` checked that these exact retained views address
69+ // `row_count` rows before the loop.
7070 let elements = unsafe { Args :: get_from_views_unchecked ( & views, index) } ;
7171 // SAFETY: the sink row-count check above proved every loop index is in bounds.
7272 let output =
@@ -92,21 +92,21 @@ where
9292 }
9393
9494 // SAFETY: every row callback completed successfully, so each returned the required write token.
95- unsafe { <Sink as OutputSink < Options > >:: finish ( sink) } . map ( RowExecution :: Output )
95+ unsafe { <Sink as OutputSink < Options > >:: finish ( sink) }
9696}
9797
9898/// Write only the rows set in `valid`, or decline when the inputs or sink cannot support
9999/// skip-invalid execution.
100100///
101- /// `Ok(None)` signals batch execution to filter every input to the valid rows, run the dense
102- /// kernel, and scatter the results back into a null-padded array .
101+ /// `Ok(None)` signals that direct skip-invalid execution is unavailable. Batch execution decides
102+ /// how to handle the decline .
103103pub ( crate ) fn execute_sink_valid_rows < Args , Prepared , Sink , ApplyResult , Options > (
104104 args : & dyn ExecutionArgs ,
105105 valid : & Mask ,
106106 ctx : & mut ExecutionCtx ,
107107 prepare : impl FnOnce ( Args :: ConstElems < ' _ > ) -> Prepared ,
108108 apply : impl Fn ( & Prepared , Args :: Elems < ' _ > , <Sink as OutputSink < Options > >:: Row < ' _ > ) -> ApplyResult ,
109- ) -> VortexResult < Option < RowExecution > >
109+ ) -> VortexResult < Option < ArrayRef > >
110110where
111111 Args : ElementTuple ,
112112 Sink : OutputSink < Options > ,
@@ -144,7 +144,7 @@ where
144144 ) ;
145145
146146 if let Some ( views) = views {
147- if Args :: ARITY != 0 && views. len ( ) != row_count {
147+ if ! Args :: view_lens_match ( & views, row_count) {
148148 decoded_length_error ( row_count) ?;
149149 }
150150
@@ -154,9 +154,8 @@ where
154154 let output =
155155 unsafe { <Sink as OutputSink < Options > >:: row_unchecked ( & mut rows, index) } ;
156156
157- // SAFETY: the tuple length check proved every non-nullary view has `row_count`
158- // rows, and mask indices are below `row_count`. Nullary tuples do not access an
159- // input view.
157+ // SAFETY: `view_lens_match` checked that these exact retained views address
158+ // `row_count` rows, and mask indices are below `row_count`.
160159 let elements = unsafe { Args :: get_from_views_unchecked ( & views, index) } ;
161160
162161 apply ( & prepared, elements, output) . into_result ( )
@@ -179,9 +178,7 @@ where
179178
180179 // SAFETY: the initializer completed before traversal, and every visited callback completed
181180 // successfully and returned the required write token.
182- unsafe { <Sink as OutputSink < Options > >:: finish ( sink) }
183- . map ( RowExecution :: Output )
184- . map ( Some )
181+ unsafe { <Sink as OutputSink < Options > >:: finish ( sink) } . map ( Some )
185182}
186183
187184/// Construct a decoded-length error outside the traversal branches.
@@ -267,21 +264,17 @@ mod tests {
267264 use vortex_error:: vortex_err;
268265 use vortex_mask:: Mask ;
269266
270- use super :: RowExecution ;
271267 use super :: execute_sink_valid_rows;
272268 use crate :: ArrayRef ;
273269 use crate :: IntoArray ;
274270 use crate :: VortexSessionExecute ;
275271 use crate :: array_session;
276272 use crate :: arrays:: PrimitiveArray ;
277- use crate :: assert_arrays_eq;
278273 use crate :: dtype:: DType ;
279274 use crate :: dtype:: NativePType ;
280275 use crate :: scalar_fn:: EmptyOptions ;
281276 use crate :: scalar_fn:: VecExecutionArgs ;
282- use crate :: scalar_fn:: unstable:: row:: InitializedElement ;
283277 use crate :: scalar_fn:: unstable:: row:: OutputSink ;
284- use crate :: scalar_fn:: unstable:: row:: UninitElementSink ;
285278 use crate :: validity:: Validity ;
286279
287280 struct NonSkippingSink ;
@@ -370,39 +363,6 @@ mod tests {
370363 Ok ( ( ) )
371364 }
372365
373- #[ test]
374- fn test_skip_invalid_sink_initializes_and_writes_addressed_rows ( ) -> VortexResult < ( ) > {
375- let input = PrimitiveArray :: from_iter ( [ 10_i64 , 20 , 30 ] ) . into_array ( ) ;
376- let args = VecExecutionArgs :: new ( vec ! [ input] , 3 ) ;
377- let valid = Mask :: from_iter ( [ true , false , true ] ) ;
378- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
379-
380- let execution = execute_sink_valid_rows :: <
381- ( i64 , ) ,
382- ( ) ,
383- UninitElementSink < i64 > ,
384- InitializedElement ,
385- EmptyOptions ,
386- > (
387- & args,
388- & valid,
389- & mut ctx,
390- |_| ( ) ,
391- |_, ( value, ) , output| {
392- // SAFETY: `output` is the row supplied to this callback.
393- unsafe { InitializedElement :: write ( output, value * 2 ) }
394- } ,
395- ) ?;
396- let Some ( RowExecution :: Output ( actual) ) = execution else {
397- vortex_bail ! ( "the skip-invalid sink must produce an output" ) ;
398- } ;
399- let expected = PrimitiveArray :: from_iter ( [ 20_i64 , 0 , 60 ] ) ;
400-
401- assert_arrays_eq ! ( & actual, expected. as_ref( ) , & mut ctx) ;
402-
403- Ok ( ( ) )
404- }
405-
406366 #[ test]
407367 fn test_skip_invalid_sink_rechecks_rows_after_initialization ( ) -> VortexResult < ( ) > {
408368 let input = PrimitiveArray :: from_iter ( [ 10_i64 , 20 ] ) . into_array ( ) ;
0 commit comments