22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
44use vortex_error:: VortexResult ;
5- use vortex_error:: vortex_panic;
65use vortex_mask:: Mask ;
76
87use super :: super :: RowFnExecutionArgs ;
@@ -24,12 +23,7 @@ enum ResolvedValidity {
2423}
2524
2625impl RowFnExecutionArgs {
27- /// Resolve validity, then execute valid rows over the original inputs.
28- ///
29- /// # Panics
30- ///
31- /// Panics if the concrete row signature cannot use direct valid-row execution. Inputs must
32- /// support null-tolerant decoding, and output sinks must initialize skipped rows.
26+ /// Resolve validity and try direct valid-row execution before filter-and-scatter.
3327 pub ( super ) fn execute_valid_only (
3428 & self ,
3529 kernel : impl Fn ( BorrowedRowFnArgs < ' _ > , & mut ExecutionCtx ) -> VortexResult < ArrayRef > ,
@@ -40,19 +34,18 @@ impl RowFnExecutionArgs {
4034 ) -> VortexResult < Option < ArrayRef > > ,
4135 ctx : & mut ExecutionCtx ,
4236 ) -> VortexResult < ArrayRef > {
43- let valid = match self . resolve_validity ( & kernel, ctx) ? {
37+ let original_validity = match self . resolve_validity ( & kernel, ctx) ? {
4438 ResolvedValidity :: Output ( output) => return Ok ( output) ,
45- ResolvedValidity :: PartiallyValid ( valid ) => valid ,
39+ ResolvedValidity :: PartiallyValid ( original_validity ) => original_validity ,
4640 } ;
4741
48- if let Some ( result) = self . try_execute_valid_rows ( try_valid_rows, & valid, ctx) ? {
49- return Ok ( result) ;
42+ let direct_output = self . try_execute_valid_rows ( try_valid_rows, & original_validity, ctx) ?;
43+
44+ if let Some ( output) = direct_output {
45+ return Ok ( output) ;
5046 }
5147
52- vortex_panic ! (
53- "valid-only execution requires direct valid-row support; {} selected an unsupported signature" ,
54- self . id,
55- )
48+ self . filter_and_scatter ( kernel, & original_validity, ctx)
5649 }
5750
5851 /// Materialize validity and handle all-valid or all-null batches.
@@ -61,24 +54,24 @@ impl RowFnExecutionArgs {
6154 kernel : & impl Fn ( BorrowedRowFnArgs < ' _ > , & mut ExecutionCtx ) -> VortexResult < ArrayRef > ,
6255 ctx : & mut ExecutionCtx ,
6356 ) -> VortexResult < ResolvedValidity > {
64- let valid = self . validity . clone ( ) . execute_mask ( self . row_count , ctx) ?;
57+ let validity = self . validity . clone ( ) . execute_mask ( self . row_count , ctx) ?;
6558
6659 // An array-backed validity can materialize to all valid even though the cheap checks in
6760 // `RowFnExecutionArgs::execute` could not prove that. Run the full-row kernel in that
6861 // case. Check all-true before all-false because an empty mask is both.
69- if valid . all_true ( ) {
62+ if validity . all_true ( ) {
7063 let values = kernel ( self . execution_args ( & self . inputs , self . row_count ) , ctx) ?;
7164 let values = self . validate_kernel_output ( values, self . row_count , ctx) ?;
7265 let values = self . finalize_output ( values, self . row_count ) ?;
7366
7467 return Ok ( ResolvedValidity :: Output ( values) ) ;
7568 }
7669
77- if valid . all_false ( ) {
70+ if validity . all_false ( ) {
7871 return Ok ( ResolvedValidity :: Output ( self . all_null ( ) ) ) ;
7972 }
8073
81- Ok ( ResolvedValidity :: PartiallyValid ( valid ) )
74+ Ok ( ResolvedValidity :: PartiallyValid ( validity ) )
8275 }
8376
8477 /// Try execution against the original inputs, then mask a returned full-length result.
@@ -89,21 +82,22 @@ impl RowFnExecutionArgs {
8982 & Mask ,
9083 & mut ExecutionCtx ,
9184 ) -> VortexResult < Option < ArrayRef > > ,
92- valid : & Mask ,
85+ original_validity : & Mask ,
9386 ctx : & mut ExecutionCtx ,
9487 ) -> VortexResult < Option < ArrayRef > > {
95- let Some ( values) = try_valid_rows (
96- self . execution_args ( & self . inputs , self . row_count ) ,
97- valid,
98- ctx,
99- ) ?
100- else {
88+ let row_count = original_validity. len ( ) ;
89+ let args = self . execution_args ( & self . inputs , row_count) ;
90+
91+ let Some ( values) = try_valid_rows ( args, original_validity, ctx) ? else {
10192 return Ok ( None ) ;
10293 } ;
103- let values = self . validate_kernel_output ( values, valid. len ( ) , ctx) ?;
10494
105- let mask = BoolArray :: new ( valid. to_bit_buffer ( ) , Validity :: NonNullable ) . into_array ( ) ;
106- self . finalize_output ( values. mask ( mask) ?, valid. len ( ) )
107- . map ( Some )
95+ let values = self . validate_kernel_output ( values, row_count, ctx) ?;
96+
97+ let validity_array =
98+ BoolArray :: new ( original_validity. to_bit_buffer ( ) , Validity :: NonNullable ) . into_array ( ) ;
99+ let masked = values. mask ( validity_array) ?;
100+
101+ self . finalize_output ( masked, row_count) . map ( Some )
108102 }
109103}
0 commit comments