@@ -10,7 +10,7 @@ use std::hash::{BuildHasher, Hash, Hasher};
1010
1111use itertools:: Itertools ;
1212use vortex_dtype:: DType ;
13- use vortex_error:: { VortexResult , vortex_bail } ;
13+ use vortex_error:: { VortexResult , vortex_ensure } ;
1414use vortex_mask:: Mask ;
1515use vortex_utils:: aliases:: hash_map:: { HashMap , RandomState } ;
1616use vortex_vector:: { Vector , VectorMut , VectorMutOps } ;
@@ -270,7 +270,7 @@ impl Pipeline {
270270
271271 /// Perform a single step of the pipeline.
272272 fn step ( & mut self , selection : & BitView , output : & mut VectorMut ) -> VortexResult < ( ) > {
273- // Loop over the kernels in toposorted execution order
273+ // Loop over the kernels in toposorted execution order.
274274 for & node_idx in self . exec_order . iter ( ) {
275275 let kernel = & mut self . kernels [ node_idx] ;
276276
@@ -283,38 +283,43 @@ impl Pipeline {
283283 assert ! ( tail. is_empty( ) ) ;
284284
285285 kernel. step ( & self . ctx , selection, & mut tail) ?;
286- if tail. len ( ) != N && tail. len ( ) != selection. true_count ( ) {
287- vortex_bail ! (
288- "Kernel produced incorrect number of output elements, expected either {} or {}, got {}" ,
289- N ,
290- selection. true_count( ) ,
291- tail. len( )
292- ) ;
286+
287+ let len = tail. len ( ) ;
288+ vortex_ensure ! (
289+ len == N || len == selection. true_count( ) ,
290+ "Kernel produced incorrect number of output elements, \
291+ expected either {N} or {}, got {len}",
292+ selection. true_count( ) ,
293+ ) ;
294+
295+ // Since we are writing to the final vector, there are no other kernels who we
296+ // can delegate filtering the selection mask out to, so check if we need to do
297+ // a final filter before we return.
298+ if selection. true_count ( ) < N && len == N {
299+ // tail.filter(selection_mask)
300+ todo ! ( "Filter via a bit mask" )
293301 }
294302
295- // Now we append the produced output back to the main output vector.
303+ // Now we join the produced output back to the main output vector.
296304 output. unsplit ( tail) ;
297305 }
298306 OutputTarget :: IntermediateVector ( vector_id) => {
299307 let mut out_vector = self . ctx . take_output ( vector_id) ;
300308 out_vector. clear ( ) ;
309+ debug_assert ! ( out_vector. is_empty( ) ) ;
301310
302- assert ! ( out_vector. is_empty( ) ) ;
303311 kernel. step ( & self . ctx , selection, & mut out_vector) ?;
304312
305- match out_vector. len ( ) {
306- // Valid cases are all N elements, or only the selected elements.
307- n if n == N || n == selection. true_count ( ) => {
308- // If the kernel added N elements, the output is in-place.
309- self . ctx . replace_output ( vector_id, out_vector) ;
310- }
311- _ => vortex_bail ! (
312- "Kernel produced incorrect number of output elements, expected either {} or {}, got {}" ,
313- N ,
314- selection. true_count( ) ,
315- out_vector. len( )
316- ) ,
317- }
313+ let len = out_vector. len ( ) ;
314+ vortex_ensure ! (
315+ len == N || len == selection. true_count( ) ,
316+ "Kernel produced incorrect number of output elements, \
317+ expected either {N} or {}, got {len}",
318+ selection. true_count( ) ,
319+ ) ;
320+
321+ // If the kernel added N elements, the output is in-place.
322+ self . ctx . replace_output ( vector_id, out_vector) ;
318323 }
319324 } ;
320325 }
0 commit comments