Skip to content

Commit 0babb24

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

File tree

13 files changed

+94
-66
lines changed

13 files changed

+94
-66
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,20 @@ impl Kernel for FilterKernel {
4848
}
4949

5050
fn cost_for_dtype(dtype: &DType, selection: &Mask) -> f64 {
51+
if selection.true_count() == 0 {
52+
return 0.0;
53+
}
54+
5155
match dtype {
5256
DType::Null => 0.0,
57+
DType::Primitive(ptype, _) => {
58+
// Some estimate based on PType width and true-count or number of slices??
59+
// Maybe nullable types are more expensive?
60+
// ... No idea how to tune this yet.
61+
let width = ptype.byte_width() as f64;
62+
let selectivity = selection.true_count() as f64 / selection.len() as f64;
63+
width * selectivity
64+
}
5365
DType::Extension(ext) => cost_for_dtype(ext.storage_dtype(), selection),
5466
_ => f64::INFINITY,
5567
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
use vortex_error::VortexResult;
55
use vortex_scalar::Scalar;
6+
use vortex_vector::scalar_matches_dtype;
67
use vortex_vector::Datum;
78
use vortex_vector::VectorOps;
8-
use vortex_vector::scalar_matches_dtype;
99

10-
use crate::Array;
11-
use crate::ArrayRef;
12-
use crate::IntoArray;
1310
use crate::arrays::AnyScalarFn;
1411
use crate::arrays::ConstantArray;
1512
use crate::arrays::ConstantVTable;
1613
use crate::arrays::ScalarFnArray;
1714
use crate::expr::ExecutionArgs;
1815
use crate::optimizer::rules::ArrayReduceRule;
16+
use crate::Array;
17+
use crate::ArrayRef;
18+
use crate::IntoArray;
1919

2020
#[derive(Debug)]
2121
pub(crate) struct ScalarFnConstantRule;
@@ -56,6 +56,7 @@ impl ArrayReduceRule<AnyScalarFn> for ScalarFnConstantRule {
5656
};
5757
assert!(scalar_matches_dtype(&result, &array.dtype));
5858

59+
let _fn = format!("{}", array.scalar_fn);
5960
Ok(Some(
6061
ConstantArray::new(Scalar::from_vector_scalar(result, &array.dtype)?, array.len)
6162
.into_array(),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
use itertools::Itertools;
55
use vortex_error::VortexExpect;
66

7-
use crate::Array;
8-
use crate::Canonical;
9-
use crate::arrays::LEGACY_SESSION;
107
use crate::arrays::scalar_fn::array::ScalarFnArray;
118
use crate::arrays::scalar_fn::vtable::ScalarFnVTable;
9+
use crate::arrays::LEGACY_SESSION;
1210
use crate::executor::VectorExecutor;
1311
use crate::expr::ExecutionArgs;
1412
use crate::vectors::VectorIntoArray;
1513
use crate::vtable::CanonicalVTable;
14+
use crate::Array;
15+
use crate::Canonical;
1616

1717
impl CanonicalVTable<ScalarFnVTable> for ScalarFnVTable {
1818
fn canonicalize(array: &ScalarFnArray) -> Canonical {

vortex-array/src/executor.rs

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

4-
use vortex_error::VortexResult;
54
use vortex_error::vortex_ensure;
5+
use vortex_error::VortexResult;
66
use vortex_session::VortexSession;
77
use vortex_vector::Datum;
88
use vortex_vector::Vector;
99
use vortex_vector::VectorOps;
1010

11-
use crate::Array;
12-
use crate::ArrayRef;
1311
use crate::arrays::ConstantVTable;
1412
use crate::kernel::BindCtx;
1513
use crate::session::ArraySessionExt;
14+
use crate::Array;
15+
use crate::ArrayRef;
1616

1717
/// Executor for exporting a Vortex [`Vector`] or [`Datum`] from an [`ArrayRef`].
1818
pub trait VectorExecutor {

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ use vortex_dtype::DType;
99
use vortex_dtype::FieldName;
1010
use vortex_dtype::FieldPath;
1111
use vortex_dtype::Nullability;
12+
use vortex_error::vortex_err;
13+
use vortex_error::vortex_panic;
1214
use vortex_error::VortexExpect;
1315
use vortex_error::VortexResult;
14-
use vortex_error::vortex_err;
1516
use vortex_mask::Mask;
1617
use vortex_proto::expr as pb;
1718
use vortex_vector::Datum;
1819
use vortex_vector::ScalarOps;
1920
use vortex_vector::VectorOps;
2021

21-
use crate::ArrayRef;
22-
use crate::ToCanonical;
2322
use crate::compute::mask;
23+
use crate::expr::exprs::root::root;
24+
use crate::expr::stats::Stat;
2425
use crate::expr::Arity;
2526
use crate::expr::ChildName;
2627
use crate::expr::ExecutionArgs;
@@ -31,8 +32,9 @@ use crate::expr::SimplifyCtx;
3132
use crate::expr::StatsCatalog;
3233
use crate::expr::VTable;
3334
use crate::expr::VTableExt;
34-
use crate::expr::exprs::root::root;
35-
use crate::expr::stats::Stat;
35+
use crate::scalar_fns::ExprBuiltins;
36+
use crate::ArrayRef;
37+
use crate::ToCanonical;
3638

3739
pub struct GetItem;
3840

@@ -139,9 +141,10 @@ impl VTable for GetItem {
139141
&self,
140142
field_name: &FieldName,
141143
expr: &Expression,
142-
_ctx: &dyn SimplifyCtx,
144+
ctx: &dyn SimplifyCtx,
143145
) -> VortexResult<Option<Expression>> {
144146
let child = expr.child(0);
147+
let child_dtype = ctx.return_dtype(child)?;
145148

146149
// If the child is a Pack expression, we can directly return the corresponding child.
147150
if let Some(pack) = child.as_opt::<Pack>() {
@@ -157,7 +160,15 @@ impl VTable for GetItem {
157160
)
158161
})?;
159162

160-
return Ok(Some(child.child(idx).clone()));
163+
let mut field = child.child(idx).clone();
164+
165+
// If the pack expression is nullable but the child field is not, we need to
166+
// adjust the nullability of the resulting expression.
167+
if pack.nullability.is_nullable() && !child_dtype.is_nullable() {
168+
field = field.cast(child_dtype.as_nullable())?;
169+
}
170+
171+
return Ok(Some(field));
161172
}
162173

163174
Ok(None)
@@ -232,15 +243,15 @@ mod tests {
232243
use vortex_dtype::StructFields;
233244
use vortex_scalar::Scalar;
234245

235-
use crate::Array;
236-
use crate::IntoArray;
237246
use crate::arrays::StructArray;
238247
use crate::expr::exprs::binary::checked_add;
239248
use crate::expr::exprs::get_item::get_item;
240249
use crate::expr::exprs::literal::lit;
241250
use crate::expr::exprs::pack::pack;
242251
use crate::expr::exprs::root::root;
243252
use crate::validity::Validity;
253+
use crate::Array;
254+
use crate::IntoArray;
244255

245256
fn test_array() -> StructArray {
246257
StructArray::from_fields(&[

vortex-array/src/vtable/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ use vortex_dtype::DType;
2828
use vortex_error::VortexResult;
2929
use vortex_mask::Mask;
3030

31+
use crate::kernel::kernel;
32+
use crate::kernel::BindCtx;
33+
use crate::kernel::KernelRef;
34+
use crate::serde::ArrayChildren;
3135
use crate::Array;
3236
use crate::ArrayRef;
3337
use crate::IntoArray;
3438
use crate::VectorExecutor;
35-
use crate::kernel::BindCtx;
36-
use crate::kernel::KernelRef;
37-
use crate::kernel::kernel;
38-
use crate::serde::ArrayChildren;
3939

4040
/// The array [`VTable`] encapsulates logic for an Array type within Vortex.
4141
///
@@ -149,7 +149,7 @@ pub trait VTable: 'static + Sized + Send + Sync + Debug {
149149
let session = ctx.session().clone();
150150
Ok(kernel(move || {
151151
let canonical = Self::CanonicalVTable::canonicalize(&array);
152-
canonical.into_array().execute_vector_optimized(&session)
152+
canonical.into_array().execute_vector(&session)
153153
}))
154154
}
155155

vortex-compute/src/arrow/primitive.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@
33

44
use std::sync::Arc;
55

6-
use arrow_array::Array;
7-
use arrow_array::ArrayRef;
8-
use arrow_array::PrimitiveArray;
96
use arrow_array::types::Float16Type;
107
use arrow_array::types::Float32Type;
118
use arrow_array::types::Float64Type;
12-
use arrow_array::types::Int8Type;
139
use arrow_array::types::Int16Type;
1410
use arrow_array::types::Int32Type;
1511
use arrow_array::types::Int64Type;
16-
use arrow_array::types::UInt8Type;
12+
use arrow_array::types::Int8Type;
1713
use arrow_array::types::UInt16Type;
1814
use arrow_array::types::UInt32Type;
1915
use arrow_array::types::UInt64Type;
16+
use arrow_array::types::UInt8Type;
17+
use arrow_array::Array;
18+
use arrow_array::ArrayRef;
19+
use arrow_array::PrimitiveArray;
2020
use vortex_buffer::Buffer;
2121
use vortex_dtype::half::f16;
22+
use vortex_error::vortex_panic;
2223
use vortex_error::VortexResult;
2324
use vortex_vector::match_each_pvector;
2425
use vortex_vector::primitive::PVector;
2526
use vortex_vector::primitive::PrimitiveVector;
2627

28+
use crate::arrow::nulls_to_mask;
2729
use crate::arrow::IntoArrow;
2830
use crate::arrow::IntoVector;
29-
use crate::arrow::nulls_to_mask;
3031

3132
impl IntoArrow for PrimitiveVector {
3233
type Output = ArrayRef;

vortex-datafusion/src/persistent/opener.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ use arrow_schema::ArrowError;
99
use arrow_schema::DataType;
1010
use arrow_schema::Field;
1111
use arrow_schema::SchemaRef;
12+
use datafusion_common::arrow::array::RecordBatch;
1213
use datafusion_common::DataFusionError;
1314
use datafusion_common::Result as DFResult;
14-
use datafusion_common::arrow::array::RecordBatch;
15-
use datafusion_datasource::FileRange;
16-
use datafusion_datasource::PartitionedFile;
1715
use datafusion_datasource::file_meta::FileMeta;
1816
use datafusion_datasource::file_stream::FileOpenFuture;
1917
use datafusion_datasource::file_stream::FileOpener;
2018
use datafusion_datasource::schema_adapter::SchemaAdapterFactory;
21-
use datafusion_physical_expr::PhysicalExprRef;
19+
use datafusion_datasource::FileRange;
20+
use datafusion_datasource::PartitionedFile;
2221
use datafusion_physical_expr::simplifier::PhysicalExprSimplifier;
2322
use datafusion_physical_expr::split_conjunction;
23+
use datafusion_physical_expr::PhysicalExprRef;
2424
use datafusion_physical_expr_adapter::PhysicalExprAdapterFactory;
2525
use datafusion_physical_expr_common::physical_expr::is_dynamic_physical_expr;
2626
use datafusion_physical_plan::metrics::Count;
2727
use datafusion_pruning::FilePruner;
28+
use futures::stream;
2829
use futures::FutureExt;
2930
use futures::StreamExt;
3031
use futures::TryStreamExt;
31-
use futures::stream;
32-
use object_store::ObjectStore;
3332
use object_store::path::Path;
33+
use object_store::ObjectStore;
3434
use tracing::Instrument;
3535
use vortex::array::ArrayRef;
3636
use vortex::dtype::FieldName;
@@ -334,8 +334,8 @@ impl FileOpener for VortexOpener {
334334

335335
let stream = scan_builder
336336
.with_metrics(metrics)
337-
.with_projection(projection_expr)
338-
.with_some_filter(filter)
337+
.with_projection(projection_expr.clone())
338+
.with_some_filter(filter.clone())
339339
.with_ordered(has_output_ordering)
340340
.map(|chunk| RecordBatch::try_from(chunk.as_ref()))
341341
.into_stream()
@@ -428,15 +428,15 @@ mod tests {
428428
use datafusion::scalar::ScalarValue;
429429
use insta::assert_snapshot;
430430
use itertools::Itertools;
431-
use object_store::ObjectMeta;
432431
use object_store::memory::InMemory;
432+
use object_store::ObjectMeta;
433433
use rstest::rstest;
434-
use vortex::VortexSessionDefault;
435434
use vortex::array::arrow::FromArrowArray;
436435
use vortex::file::WriteOptionsSessionExt;
437436
use vortex::io::ObjectStoreWriter;
438437
use vortex::io::VortexWrite;
439438
use vortex::session::VortexSession;
439+
use vortex::VortexSessionDefault;
440440

441441
use super::*;
442442

vortex-io/src/runtime/handle.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
use std::pin::Pin;
55
use std::sync::Arc;
66
use std::sync::Weak;
7+
use std::task::ready;
78
use std::task::Context;
89
use std::task::Poll;
9-
use std::task::ready;
1010

11+
use futures::channel::mpsc;
1112
use futures::FutureExt;
1213
use futures::StreamExt;
13-
use futures::channel::mpsc;
14-
use vortex_error::VortexResult;
1514
use vortex_error::vortex_panic;
15+
use vortex_error::VortexResult;
1616
use vortex_metrics::VortexMetrics;
1717

1818
use crate::file::FileRead;
@@ -186,18 +186,19 @@ impl<T> Task<T> {
186186
impl<T> Future for Task<T> {
187187
type Output = T;
188188

189+
#[allow(clippy::panic)]
189190
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
190191
match ready!(self.recv.poll_unpin(cx)) {
191192
Ok(result) => Poll::Ready(result),
192-
Err(recv_err) => {
193+
Err(_recv_err) => {
193194
// If the other end of the channel was dropped, it means the runtime dropped
194195
// the future without ever completing it. If the caller aborted this task by
195196
// dropping it, then they wouldn't be able to poll it anymore.
196197
// So we consider a closed channel to be a Runtime programming error and therefore
197198
// we panic.
198-
vortex_panic!(
199-
"Runtime dropped task without completing it, likely it panicked: {recv_err}"
200-
)
199+
200+
// NOTE(ngates): we don't use vortex_panic to avoid printing a useless backtrace.
201+
panic!("Runtime dropped task without completing it, likely it panicked")
201202
}
202203
}
203204
}

0 commit comments

Comments
 (0)