Skip to content

Commit ef74f3b

Browse files
committed
Clarify docs in session accessors
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 0babb24 commit ef74f3b

File tree

7 files changed

+69
-55
lines changed

7 files changed

+69
-55
lines changed

vortex-array/src/arrays/filter/vtable.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,15 @@ use std::ops::Range;
77
use vortex_buffer::BufferHandle;
88
use vortex_compute::filter::Filter;
99
use vortex_dtype::DType;
10+
use vortex_error::vortex_bail;
1011
use vortex_error::VortexExpect;
1112
use vortex_error::VortexResult;
12-
use vortex_error::vortex_bail;
1313
use vortex_mask::Mask;
1414
use vortex_scalar::Scalar;
1515

16-
use crate::Array;
17-
use crate::ArrayBufferVisitor;
18-
use crate::ArrayChildVisitor;
19-
use crate::ArrayEq;
20-
use crate::ArrayHash;
21-
use crate::ArrayRef;
22-
use crate::Canonical;
23-
use crate::IntoArray;
24-
use crate::Precision;
25-
use crate::arrays::LEGACY_SESSION;
2616
use crate::arrays::filter::array::FilterArray;
2717
use crate::arrays::filter::kernel::FilterKernel;
18+
use crate::arrays::LEGACY_SESSION;
2819
use crate::kernel::BindCtx;
2920
use crate::kernel::KernelRef;
3021
use crate::kernel::PushDownResult;
@@ -42,6 +33,15 @@ use crate::vtable::OperationsVTable;
4233
use crate::vtable::VTable;
4334
use crate::vtable::ValidityVTable;
4435
use crate::vtable::VisitorVTable;
36+
use crate::Array;
37+
use crate::ArrayBufferVisitor;
38+
use crate::ArrayChildVisitor;
39+
use crate::ArrayEq;
40+
use crate::ArrayHash;
41+
use crate::ArrayRef;
42+
use crate::Canonical;
43+
use crate::IntoArray;
44+
use crate::Precision;
4545

4646
vtable!(Filter);
4747

@@ -108,15 +108,19 @@ impl VTable for FilterVTable {
108108
pushdown_cost
109109
);
110110

111-
if pushdown_cost < full_cost {
111+
// NOTE(ngates): for now we keep the same behavior as develop where we push-down any
112+
// query with <20% true values.
113+
let pushdown = (pushdown_cost < full_cost) || (array.mask.density() < 0.2);
114+
115+
if pushdown {
112116
// Try to push down the filter to the child if it's cheaper.
113117
child = match child.push_down_filter(&mask)? {
114118
PushDownResult::Pushed(new_k) => {
115119
log::debug!("Filter push down kernel:\n{:?}", new_k);
116120
return Ok(new_k);
117121
}
118122
PushDownResult::NotPushed(child) => {
119-
log::debug!(
123+
log::warn!(
120124
"Filter pushdown was cheaper but not supported by child array {}",
121125
array.child.display_tree()
122126
);

vortex-array/src/arrays/scalar_fn/kernel.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use itertools::Itertools;
54
use vortex_dtype::DType;
65
use vortex_error::VortexResult;
76
use vortex_mask::Mask;
@@ -40,14 +39,17 @@ pub(super) enum KernelInput {
4039

4140
impl Kernel for ScalarFnKernel {
4241
fn execute(self: Box<Self>) -> VortexResult<Vector> {
43-
let datums: Vec<_> = self
44-
.inputs
45-
.into_iter()
46-
.map(|input| match input {
47-
KernelInput::Scalar(s) => Ok(Datum::Scalar(s)),
48-
KernelInput::Vector(k) => k.execute().map(Datum::Vector),
49-
})
50-
.try_collect()?;
42+
let mut datums: Vec<Datum> = Vec::with_capacity(self.inputs.len());
43+
for input in self.inputs {
44+
match input {
45+
KernelInput::Scalar(s) => {
46+
datums.push(Datum::Scalar(s));
47+
}
48+
KernelInput::Vector(kernel) => {
49+
datums.push(Datum::Vector(kernel.execute()?));
50+
}
51+
}
52+
}
5153

5254
let args = ExecutionArgs {
5355
datums,
@@ -96,7 +98,7 @@ impl Kernel for ScalarFnKernel {
9698
scalar_fn: self.scalar_fn,
9799
inputs: new_inputs,
98100
input_dtypes: self.input_dtypes,
99-
row_count: self.row_count,
101+
row_count: selection.true_count(),
100102
return_dtype: self.return_dtype,
101103
})))
102104
}

vortex-array/src/arrays/scalar_fn/vtable/canonical.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use itertools::Itertools;
54
use vortex_error::VortexExpect;
65

76
use crate::arrays::scalar_fn::array::ScalarFnArray;
@@ -17,15 +16,16 @@ use crate::Canonical;
1716
impl CanonicalVTable<ScalarFnVTable> for ScalarFnVTable {
1817
fn canonicalize(array: &ScalarFnArray) -> Canonical {
1918
let child_dtypes: Vec<_> = array.children.iter().map(|c| c.dtype().clone()).collect();
20-
let child_datums: Vec<_> = array
21-
.children()
22-
.iter()
23-
.map(|child| child.execute_datum_optimized(&LEGACY_SESSION))
24-
.try_collect()
25-
// FIXME(ngates): canonicalizing really ought to be fallible
26-
.vortex_expect(
27-
"Failed to execute child array during canonicalization of ScalarFnArray",
28-
);
19+
20+
let mut child_datums = Vec::with_capacity(array.children.len());
21+
for child in array.children.iter() {
22+
let datum = child
23+
.execute_datum_optimized(&LEGACY_SESSION)
24+
.vortex_expect(
25+
"Failed to execute child array during canonicalization of ScalarFnArray",
26+
);
27+
child_datums.push(datum);
28+
}
2929

3030
let ctx = ExecutionArgs {
3131
datums: child_datums,

vortex-array/src/expr/exprs/get_item.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use vortex_dtype::FieldName;
1010
use vortex_dtype::FieldPath;
1111
use vortex_dtype::Nullability;
1212
use vortex_error::vortex_err;
13-
use vortex_error::vortex_panic;
1413
use vortex_error::VortexExpect;
1514
use vortex_error::VortexResult;
1615
use vortex_mask::Mask;

vortex-array/src/expr/exprs/pack.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ use vortex_error::VortexExpect;
1717
use vortex_error::VortexResult;
1818
use vortex_mask::Mask;
1919
use vortex_proto::expr as pb;
20+
use vortex_vector::struct_::StructVector;
2021
use vortex_vector::Datum;
2122
use vortex_vector::ScalarOps;
2223
use vortex_vector::VectorMutOps;
2324
use vortex_vector::VectorOps;
24-
use vortex_vector::struct_::StructVector;
2525

26-
use crate::ArrayRef;
27-
use crate::IntoArray;
2826
use crate::arrays::StructArray;
2927
use crate::expr::Arity;
3028
use crate::expr::ChildName;
@@ -34,6 +32,8 @@ use crate::expr::Expression;
3432
use crate::expr::VTable;
3533
use crate::expr::VTableExt;
3634
use crate::validity::Validity;
35+
use crate::ArrayRef;
36+
use crate::IntoArray;
3737

3838
/// Pack zero or more expressions into a structure with named fields.
3939
pub struct Pack;
@@ -157,7 +157,7 @@ impl VTable for Pack {
157157
.map(|v| v.ensure_vector(args.row_count))
158158
.collect();
159159
return Ok(Datum::Vector(
160-
StructVector::new(Arc::new(fields), Mask::new_true(args.row_count)).into(),
160+
StructVector::try_new(Arc::new(fields), Mask::new_true(args.row_count))?.into(),
161161
));
162162
}
163163

@@ -219,22 +219,22 @@ pub fn pack(
219219
mod tests {
220220
use vortex_buffer::buffer;
221221
use vortex_dtype::Nullability;
222-
use vortex_error::VortexResult;
223222
use vortex_error::vortex_bail;
223+
use vortex_error::VortexResult;
224224

225+
use super::pack;
225226
use super::Pack;
226227
use super::PackOptions;
227-
use super::pack;
228-
use crate::Array;
229-
use crate::ArrayRef;
230-
use crate::IntoArray;
231-
use crate::ToCanonical;
232228
use crate::arrays::PrimitiveArray;
233229
use crate::arrays::StructArray;
234-
use crate::expr::VTableExt;
235230
use crate::expr::exprs::get_item::col;
231+
use crate::expr::VTableExt;
236232
use crate::validity::Validity;
237233
use crate::vtable::ValidityHelper;
234+
use crate::Array;
235+
use crate::ArrayRef;
236+
use crate::IntoArray;
237+
use crate::ToCanonical;
238238

239239
fn test_array() -> ArrayRef {
240240
StructArray::from_fields(&[

vortex-compute/src/arrow/primitive.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use arrow_array::ArrayRef;
1919
use arrow_array::PrimitiveArray;
2020
use vortex_buffer::Buffer;
2121
use vortex_dtype::half::f16;
22-
use vortex_error::vortex_panic;
2322
use vortex_error::VortexResult;
2423
use vortex_vector::match_each_pvector;
2524
use vortex_vector::primitive::PVector;

vortex-vector/src/datum.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use vortex_dtype::NativeDecimalType;
5-
use vortex_dtype::NativePType;
6-
use vortex_dtype::PType;
7-
8-
use crate::Scalar;
9-
use crate::ScalarOps;
10-
use crate::Vector;
11-
use crate::VectorMutOps;
124
use crate::binaryview::BinaryType;
135
use crate::binaryview::BinaryViewScalar;
146
use crate::binaryview::BinaryViewType;
@@ -32,6 +24,15 @@ use crate::primitive::PrimitiveScalar;
3224
use crate::primitive::PrimitiveVector;
3325
use crate::struct_::StructScalar;
3426
use crate::struct_::StructVector;
27+
use crate::Scalar;
28+
use crate::ScalarOps;
29+
use crate::Vector;
30+
use crate::VectorMutOps;
31+
use crate::VectorOps;
32+
use vortex_dtype::NativeDecimalType;
33+
use vortex_dtype::NativePType;
34+
use vortex_dtype::PType;
35+
use vortex_error::vortex_panic;
3536

3637
/// Represents either a scalar or vector value.
3738
#[derive(Clone, Debug)]
@@ -59,7 +60,16 @@ impl Datum {
5960
pub fn ensure_vector(self, len: usize) -> Vector {
6061
match self {
6162
Datum::Scalar(scalar) => scalar.repeat(len).freeze(),
62-
Datum::Vector(vector) => vector,
63+
Datum::Vector(vector) => {
64+
if vector.len() != len {
65+
vortex_panic!(
66+
"Vector length mismatch: expected length {}, got {}",
67+
len,
68+
vector.len()
69+
);
70+
}
71+
vector
72+
}
6373
}
6474
}
6575

0 commit comments

Comments
 (0)