Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion vortex-array/src/scalar_fn/unstable/row/batch/execute/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ use vortex_mask::MaskValuesRef;

use super::super::RowFnExecutionArgs;
use super::super::args::BorrowedRowFnArgs;
use crate::AnyCanonical;
use crate::ArrayRef;
use crate::Canonical;
use crate::ExecutionCtx;
use crate::IntoArray;
use crate::arrays::masked::mask_validity_canonical;
use crate::builtins::ArrayBuiltins;
use crate::scalar_fn::unstable::row::execute::DenseAttempt;
use crate::validity::Validity;
Expand Down Expand Up @@ -99,7 +103,20 @@ impl RowFnExecutionArgs {
Validity::NonNullable | Validity::AllValid => {
self.finalize_output(values, self.row_count)
}
Validity::Array(valid) => self.finalize_output(values.mask(valid)?, self.row_count),
Validity::Array(validity_array) => {
let values = if let Some(canonical) = values.as_opt::<AnyCanonical>() {
mask_validity_canonical(
Canonical::from(canonical),
Validity::Array(validity_array),
ctx,
)?
.into_array()
} else {
values.mask(validity_array)?
};

self.finalize_output(values, self.row_count)
}
Comment on lines +106 to +119

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something sketchy in the profile here and I would have to trace more of the code to figure out what's wrong. In the develop version we seem to execute the mask while in the new one we don't. Ah... I think this is because the benchmark is executing to AnyCanonical and this change here immediately flattens the mask into value instead of doing another execution round. Ultimately I think this is not useful benchmaxxing.

Validity::AllInvalid => {
unreachable!("all-invalid validity is handled before dense row execution")
}
Expand Down
34 changes: 32 additions & 2 deletions vortex-array/src/scalar_fn/unstable/row/batch/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ use crate::ExecutionCtx;
use crate::IntoArray;
use crate::VortexSessionExecute;
use crate::array_session;
#[cfg(not(codspeed))]
use crate::arrays::Bool;
use crate::arrays::BoolArray;
use crate::arrays::ConstantArray;
use crate::arrays::ExtensionArray;
use crate::arrays::FixedSizeListArray;
#[cfg(not(codspeed))]
use crate::arrays::Primitive;
use crate::arrays::PrimitiveArray;
use crate::assert_arrays_eq;
use crate::dtype::DType;
Expand All @@ -45,6 +49,8 @@ use crate::scalar_fn::unstable::row::RowFn;
use crate::scalar_fn::unstable::row::RowVisitor;
use crate::scalar_fn::unstable::row::execute_rows;
use crate::scalar_fn::unstable::row::row_fn_return_dtype;
#[cfg(not(codspeed))]
use crate::test_harness::trace::trace_op;
use crate::validity::Validity;

#[derive(Clone, Default)]
Expand Down Expand Up @@ -682,6 +688,7 @@ fn test_kernel_output_rejects_nulls_at_function_boundary() -> VortexResult<()> {
Ok(())
}

#[cfg(not(codspeed))]
#[test]
fn test_bool_output_builds_packed_values() -> VortexResult<()> {
let input = PrimitiveArray::new(
Expand All @@ -692,10 +699,21 @@ fn test_bool_output_builds_packed_values() -> VortexResult<()> {
let args = VecExecutionArgs::new(vec![input], 5);
let mut ctx = array_session().create_execution_ctx();

let actual = execute_rows(&PackedPositive, &EmptyOptions, &args, &mut ctx)?;
let traced = trace_op(|| execute_rows(&PackedPositive, &EmptyOptions, &args, &mut ctx))?;
let actual = traced.output;
let expected =
BoolArray::from_iter([Some(true), Some(false), None, Some(false), Some(true)]).into_array();

assert!(
actual.is::<Bool>(),
"dense Boolean output must remain canonical, got {}",
actual.encoding_id(),
);
let trace = traced.trace.to_string();
assert!(
!trace.contains("vortex.mask"),
"dense canonical output must bypass the lazy mask path, got:\n{trace}",
);
assert_arrays_eq!(&actual, &expected, &mut ctx);
Ok(())
}
Expand Down Expand Up @@ -929,6 +947,7 @@ fn test_dense_retry_filters_when_direct_valid_rows_are_unavailable() -> VortexRe
Ok(())
}

#[cfg(not(codspeed))]
#[test]
fn test_deferred_owned_execution_does_not_retry_partially_valid_success() -> VortexResult<()> {
let function = DeferredAdd::default();
Expand All @@ -938,9 +957,20 @@ fn test_deferred_owned_execution_does_not_retry_partially_valid_success() -> Vor
let args = VecExecutionArgs::new(vec![lhs, rhs], 2);
let mut ctx = array_session().create_execution_ctx();

let actual = execute_rows(&function, &EmptyOptions, &args, &mut ctx)?;
let traced = trace_op(|| execute_rows(&function, &EmptyOptions, &args, &mut ctx))?;
let actual = traced.output;
let expected = PrimitiveArray::new(vec![2_i64, 0], validity).into_array();

assert!(
actual.is::<Primitive>(),
"dense primitive output must remain canonical, got {}",
actual.encoding_id(),
);
let trace = traced.trace.to_string();
assert!(
!trace.contains("vortex.mask"),
"dense canonical output must bypass the lazy mask path, got:\n{trace}",
);
assert_arrays_eq!(&actual, &expected, &mut ctx);
assert_eq!(function.prepare_count(), 1);
Ok(())
Expand Down
Loading