Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
28163bf
Add split and open to the Scan API
gatesn Nov 19, 2026
525b565
Let pool workers spawn onto the session runtime
gatesn Nov 19, 2026
1703302
Report pool progress and exhaustion, and plan-time scan size
gatesn Nov 19, 2026
5703e0e
Document split_concurrency for pool workers
gatesn Nov 20, 2026
b38e894
Merge develop into ngates/scan-split-open
gatesn Nov 20, 2026
3148faa
Say that hosts drive the runtime their pool workers spawn onto
gatesn Nov 20, 2026
f405ee3
Merge develop into ngates/scan-split-open
gatesn Nov 20, 2026
794ac0c
Make split and open the methods every scan implements
gatesn Nov 20, 2026
93e06a5
Require every scan pool to report when all its work is taken
gatesn Nov 20, 2026
1d002df
Keep only the scan and pool methods the stack's hosts call
gatesn Nov 20, 2026
39b4ebe
Require partitions again and drop ScanPool::dtype
gatesn Nov 20, 2026
6697509
Say that split_concurrency bounds each partition or worker
gatesn Nov 20, 2026
e36740d
Open scans into a cloneable ScanStream and define split by request order
gatesn Nov 20, 2026
17e58eb
Rename vortex_scan::pool to stream and state the scan contract exactly
gatesn Nov 20, 2026
cef16c6
Describe split's callers as hosts that read a fixed number of streams
gatesn Nov 20, 2026
f93a16d
Make split strictly partitioning and leave sharing to open
gatesn Nov 20, 2026
f213f73
Merge develop into ngates/scan-split-open
gatesn Nov 24, 2026
211d1b1
Split and open the test array scan, which develop added
gatesn Nov 24, 2026
db07453
Open a scan into a shared ScanExec that hands out streams
gatesn Nov 24, 2026
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
10 changes: 10 additions & 0 deletions vortex-datafusion/src/v2/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ fn estimate_to_df_precision(est: &Precision<u64>) -> DFPrecision<usize> {
#[cfg(test)]
mod tests {
use std::any::Any;
use std::num::NonZeroUsize;
use std::sync::Arc;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
Expand Down Expand Up @@ -1075,6 +1076,7 @@ mod tests {
use vortex::scan::Partition;
use vortex::scan::PartitionRef;
use vortex::scan::PartitionStream;
use vortex::scan::stream::ScanExec;
use vortex::session::VortexSession;
use vortex_arrow::ArrowSessionExt;

Expand Down Expand Up @@ -1221,6 +1223,14 @@ mod tests {
&self.dtype
}

fn split(self: Box<Self>, _n: NonZeroUsize) -> VortexResult<Vec<DataSourceScanRef>> {
Ok(vec![self])
}

fn open(self: Box<Self>) -> VortexResult<ScanExec> {
Ok(ScanExec::from_partitions(self))
}

fn partition_count(&self) -> Precision<usize> {
Precision::Exact(2)
}
Expand Down
17 changes: 17 additions & 0 deletions vortex-layout/src/scan/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use vortex_scan::PartitionRef;
use vortex_scan::PartitionStream;
use vortex_scan::ScanRequest;
use vortex_scan::selection::Selection;
use vortex_scan::stream::ScanExec;
use vortex_session::VortexSession;

use crate::LayoutReaderRef;
Expand Down Expand Up @@ -342,6 +343,14 @@ impl DataSourceScan for LayoutReaderScan {
&self.dtype
}

fn split(self: Box<Self>, _n: NonZeroUsize) -> VortexResult<Vec<DataSourceScanRef>> {
Ok(vec![self])
}

fn open(self: Box<Self>) -> VortexResult<ScanExec> {
Ok(ScanExec::from_partitions(self))
}

fn partition_count(&self) -> Precision<usize> {
let (lower, upper) = self.size_hint();
match upper {
Expand Down Expand Up @@ -518,6 +527,14 @@ impl DataSourceScan for EmptyScan {
&self.dtype
}

fn split(self: Box<Self>, _n: NonZeroUsize) -> VortexResult<Vec<DataSourceScanRef>> {
Ok(vec![self])
}

fn open(self: Box<Self>) -> VortexResult<ScanExec> {
Ok(ScanExec::from_partitions(self))
}

fn partition_count(&self) -> Precision<usize> {
let (lower, upper) = self.size_hint();
match upper {
Expand Down
9 changes: 9 additions & 0 deletions vortex-layout/src/scan/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use vortex_scan::PartitionRef;
use vortex_scan::PartitionStream;
use vortex_scan::ScanRequest;
use vortex_scan::selection::Selection;
use vortex_scan::stream::ScanExec;
use vortex_session::VortexSession;
use vortex_utils::parallelism::get_available_parallelism;

Expand Down Expand Up @@ -409,6 +410,14 @@ impl DataSourceScan for MultiLayoutScan {
&self.dtype
}

fn split(self: Box<Self>, _n: NonZeroUsize) -> VortexResult<Vec<DataSourceScanRef>> {
Ok(vec![self])
}

fn open(self: Box<Self>) -> VortexResult<ScanExec> {
Ok(ScanExec::from_partitions(self))
}

fn partition_count(&self) -> Precision<usize> {
let count = self.ready.len() + self.deferred.len();
if !self.deferred.is_empty() || matches!(self.request.filter, Ok(Some(_))) {
Expand Down
47 changes: 41 additions & 6 deletions vortex-scan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod prepare;
pub mod row_mask;
pub mod selection;
pub mod source;
pub mod stream;
pub mod strict_sorted_buffer;

use std::any::Any;
Expand All @@ -42,6 +43,7 @@ use futures::StreamExt;
use futures::TryStreamExt;
use futures::stream::BoxStream;
use selection::Selection;
use stream::ScanExec;
use vortex_array::aggregate_fn::AggregateFnRef;
use vortex_array::dtype::DType;
use vortex_array::dtype::FieldPath;
Expand Down Expand Up @@ -180,12 +182,15 @@ pub struct ScanRequest {
/// order is completion order, so each partition applies the limit locally and the caller must
/// trim the concatenated result.
pub limit: Option<u64>,
/// The most splits of each partition to decode at once, in all.
/// The most splits that each worker decodes at once, where a worker is a partition or a
/// stream of an opened scan.
///
/// `None` keeps the reader's default, which scales with the machine's cores. Each split being
/// decoded holds the decoded chunks of every column it overlaps, so a scan that runs alongside
/// others, such as one task of several on a machine, can set this to bound its memory. It does
/// not bound I/O: segment reads for later splits may still be coalesced ahead of them.
/// It bounds each worker on its own, not the whole scan: a scan read by several workers
/// decodes up to this many splits in each. `None` keeps the source's default. Each
/// split being decoded holds the decoded chunks of every column it overlaps, so a scan that
/// runs alongside others, such as one task of several on a machine, can set this to bound its
/// memory. It does not bound I/O: segment reads for later splits may still be coalesced ahead
/// of them.
pub split_concurrency: Option<NonZeroUsize>,
}

Expand All @@ -208,7 +213,19 @@ impl Default for ScanRequest {
/// A boxed data source scan.
pub type DataSourceScanRef = Box<dyn DataSourceScan>;

/// A data source scan produces partitions that can be executed to read data from the source.
/// A data source scan reads data from the source.
///
/// Each host reads every scan the same way, whatever the source: its execution model is fixed.
/// A host that needs a fixed number of partitions, such as DataFusion with its output partition
/// count, [splits](Self::split) the scan into fixed pieces that each own their rows. A host that
/// runs its own threads, such as DuckDB, or that wants its partitions to share work, never
/// splits: it [opens](Self::open) the scan once and has each of its threads or partitions read a
/// [stream](ScanExec::stream) of the returned [`ScanExec`]. The host states the properties it needs, such as row
/// order or a limit, on the [`ScanRequest`], and the source decides what the pieces are and how
/// they run.
///
/// A scan never starts threads. Its work may run as tasks on the session's runtime, which the
/// host owns.
pub trait DataSourceScan: 'static + Send {
/// The returned dtype of the scan.
fn dtype(&self) -> &DType;
Expand All @@ -218,6 +235,24 @@ pub trait DataSourceScan: 'static + Send {

/// Returns a stream of partitions to be processed.
fn partitions(self: Box<Self>) -> PartitionStream;

/// Partitions the scan into at most `n` fixed pieces.
///
/// Each piece owns its rows: the pieces together return every row of the scan exactly once,
/// and no two return the same row. When the request is ordered, the pieces are contiguous,
/// and reading them one after another returns the rows in scan order.
///
/// Splitting reads metadata only. The result is never empty, and a scan with no cut points
/// returns itself as the one piece. A host that wants its threads to share the scan's work
/// instead [opens](Self::open) the scan and reads a stream of it on each thread.
fn split(self: Box<Self>, n: NonZeroUsize) -> VortexResult<Vec<DataSourceScanRef>>;

/// Opens the scan into a [`ScanExec`], whose work host threads share by each reading a
/// [stream](ScanExec::stream) of it.
///
/// A source that has no queue of work of its own may return
/// [`ScanExec::from_partitions`] over itself.
fn open(self: Box<Self>) -> VortexResult<ScanExec>;
}

impl dyn DataSourceScan {
Expand Down
Loading