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
67 changes: 62 additions & 5 deletions vortex-file/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ use itertools::Itertools;
use vortex_array::ArrayRef;
use vortex_array::dtype::DType;
use vortex_array::dtype::FieldMask;
use vortex_array::expr::BoundExpression;
use vortex_array::expr::Expression;
use vortex_buffer::ByteBuffer;
use vortex_error::VortexResult;
use vortex_layout::LayoutReader;
use vortex_layout::scan::layout::LayoutReaderDataSource;
use vortex_layout::scan::metrics::ScanUsage;
use vortex_layout::scan::scan_builder::ScanBuilder;
use vortex_layout::scan::scan_builder::referenced_field_masks;
use vortex_layout::scan::split_by::SplitBy;
use vortex_layout::scan::v2::ScanFile;
use vortex_layout::segments::SegmentSource;
use vortex_layout::segments::UsageSegmentSource;
use vortex_scan::DataSourceRef;
use vortex_scan::prepare::ScanCache;
use vortex_scan::prepare::SegmentLocation;
use vortex_scan::source::PlanChild;
use vortex_scan::source::PlanDataSource;
use vortex_session::VortexSession;
use vortex_utils::aliases::hash_map::HashMap;

Expand Down Expand Up @@ -116,7 +120,8 @@ impl VortexFile {
///
/// Repeated calls to [`layout_reader`](Self::layout_reader), [`scan`](Self::scan), and
/// [`data_source`](Self::data_source) will share the same reader tree. Repeated V2 scans of
/// [`scan_file`](Self::scan_file) will share its segment locations and a [`ScanCache`].
/// [`scan_file`](Self::scan_file), and so of the plan data sources, will share its segment
/// locations and a [`ScanCache`].
pub fn with_caching(self) -> Self {
let scan_cache = FileScanCache {
locations: self.footer.segment_locations(),
Expand Down Expand Up @@ -245,18 +250,70 @@ impl VortexFile {

/// Create a [`DataSource`](vortex_scan::DataSource) from this file for scanning.
///
/// Wraps the file's layout reader with [`FileStatsLayoutReader`] (when file-level
/// statistics are available) and [`LayoutReaderDataSource`]. Stored footer aggregates are
/// available through the source statistics methods without reading payloads.
/// Scans run on the file's [layout reader](Self::layout_reader), as with
/// [`layout_reader_data_source`](Self::layout_reader_data_source). Stored footer aggregates
/// are available through the source statistics methods without reading payloads.
pub fn data_source(&self) -> VortexResult<DataSourceRef> {
let reader = self.layout_reader()?;
self.layout_reader_data_source()
}

/// Create a [`DataSource`](vortex_scan::DataSource) that scans this file with its
/// [layout reader](Self::layout_reader), whatever its layouts.
///
/// Use [`data_source`](Self::data_source) unless the layout reader is required, for example
/// to compare it with [`plan_data_source`](Self::plan_data_source). Stored footer aggregates
/// are available through the source statistics methods without reading payloads.
pub fn layout_reader_data_source(&self) -> VortexResult<DataSourceRef> {
let reader = self.layout_reader()?;
Ok(Arc::new(FileDataSource::new(
LayoutReaderDataSource::new(reader, self.session.clone()),
self.file_stats().cloned(),
)))
}

/// Create a [`DataSource`](vortex_scan::DataSource) from this file whose scans run on the
/// planner-driven executor.
///
/// The source is a [`PlanDataSource`] over [`plan_child`](Self::plan_child). Every scan of
/// the source shares one [`ScanCache`]: the file's, with [caching](Self::with_caching), or else
/// one of its own. A scan whose filter the file-level statistics prove false reads nothing.
/// Stored footer aggregates are available through the source statistics methods. Opening the
/// source reads nothing and builds no layout reader.
pub fn plan_data_source(&self) -> DataSourceRef {
let source = PlanDataSource::from_child(self.session.clone(), self.plan_child());
Arc::new(FileDataSource::new(source, self.file_stats().cloned()))
}

/// This file as a child of a [`PlanDataSource`]: its V2 scan input, row count, and a pruner
/// that skips scans whose filter the file-level statistics prove false.
///
/// An opened scan of the child cuts its work on the file's layout splits over the fields it
/// reads, as a V1 scan of the same fields does.
pub fn plan_child(&self) -> PlanChild {
let splitter = {
let file = self.clone();
Arc::new(
move |projection: &BoundExpression, filter: Option<&BoundExpression>| {
SplitBy::default().splits(
file.layout_reader()?.as_ref(),
&(0..file.row_count()),
&referenced_field_masks(projection, filter)?,
)
},
)
};
let file = PlanChild::new(self.scan_file().into())
.with_row_count(self.row_count())
.with_splitter(splitter);
let Some(statistics) = self.file_stats().cloned() else {
return file;
};
let (row_count, session) = (self.row_count(), self.session.clone());
file.with_pruner(Arc::new(move |filter| {
is_falsified_by_file_stats(filter, row_count, &statistics, &session)
}))
}

/// Initiate a scan of the file, returning a builder for projection, filtering, selection, and
/// execution options.
pub fn scan(&self) -> VortexResult<ScanBuilder<ArrayRef>> {
Expand Down
2 changes: 2 additions & 0 deletions vortex-file/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub mod flatbuffers;
mod footer;
pub mod multi;
mod open;
#[cfg(test)]
mod plan_tests;
mod pruning;
/// Segment sources, caches, and sinks used by file readers and writers.
pub mod segments;
Expand Down
Loading