Skip to main content

Scan

Struct Scan 

Source
pub struct Scan { /* private fields */ }
Expand description

The result of building a scan over a table. This can be used to get the actual data from scanning the table.

Implementations§

Source§

impl Scan

Source

pub fn table_root(&self) -> &Url

The table’s root URL. Any relative paths returned from scan_data (or in a callback from ScanMetadata::visit_scan_files) must be resolved against this root to get the actual path to the file.

Source

pub fn snapshot(&self) -> &SnapshotRef

Get a shared reference to the Snapshot of this scan.

Source

pub fn logical_schema(&self) -> &SchemaRef

Get a shared reference to the logical Schema of the scan (i.e. the output schema of the scan). Note that the logical schema can differ from the physical schema due to e.g. partition columns which are present in the logical schema but not in the physical schema.

Source

pub fn physical_schema(&self) -> &SchemaRef

Get a shared reference to the physical Schema of the scan. This represents the schema of the underlying data files which must be read from storage.

Source

pub fn physical_predicate(&self) -> Option<PredicateRef>

Get the predicate PredicateRef of the scan.

Source

pub fn scan_metadata( &self, engine: &dyn Engine, ) -> DeltaResult<impl Iterator<Item = DeltaResult<ScanMetadata>>>

Get an iterator of ScanMetadatas that should be used to facilitate a scan. This handles log-replay, reconciling Add and Remove actions, and applying data skipping (if possible).

Reports metrics: MetricEvent::ScanMetadataCompleted when the returned iterator is fully exhausted.

Each item in the returned iterator is a struct of:

  • Box<dyn EngineData>: Data in engine format, where each row represents a file to be scanned. The schema for each row can be obtained by calling scan_row_schema.
  • Vec<bool>: A selection vector. If a row is at index i and this vector is false at index i, then that row should not be processed (i.e. it is filtered out). If the vector is true at index i the row should be processed. If the selection vector is shorter than the number of rows returned, missing elements are considered true, i.e. included in the query. NB: If you are using the default engine and plan to call arrow’s filter_record_batch, you need to extend this vector to the full length of the batch or arrow will drop the extra rows.
  • Vec<Option<Expression>>: Transformation expressions that need to be applied. For each row at index i in the above data, if an expression exists at index i in the Vec, the associated expression must be applied to the data read from the file specified by the row. The resultant schema for this expression is guaranteed to be Self::logical_schema(). If the item at index i in this Vec is None, or if the Vec contains fewer than i elements, no expression need be applied and the data read from disk is already in the correct logical state.
Source

pub fn parallel_scan_metadata( &self, engine: Arc<dyn Engine>, ) -> DeltaResult<SequentialScanMetadata>

Start a parallel scan metadata processing for the table.

This method returns a SequentialScanMetadata iterator that processes commits and checkpoint manifests sequentially. After exhausting this iterator, call finish() to determine if a distributed phase is needed.

Cancellation is not supported on this path: it errors if a token was set via ScanBuilder::with_cancellation_token, rather than silently running to completion. Only scan_metadata honors the token today.

§Example
let engine = Arc::new(DefaultEngineBuilder::new(Arc::new(LocalFileSystem::new())).build());
let table_root = Url::parse("file:///path/to/table")?;

// Build a snapshot
let snapshot = Snapshot::builder_for(table_root.clone())
    .at_version(5) // Optional: specify a time-travel version (default is latest version)
    .build(engine.as_ref())?;
let scan = snapshot.scan_builder().build()?;
let mut sequential = scan.parallel_scan_metadata(engine.clone())?;

// Process sequential phase
for result in sequential.by_ref() {
    let scan_metadata = result?;
    // Process scan metadata...
}

// Check if distributed phase is needed
match sequential.finish()? {
    AfterSequentialScanMetadata::Done => {
        // All processing complete
    }
    AfterSequentialScanMetadata::Parallel { state, files } => {
        // Distribute files for parallel processing (e.g., one file per worker)
        let state = Arc::new(*state);
        for file in files {
            let parallel = ParallelScanMetadata::try_new(
                engine.clone(),
                state.clone(),
                vec![file],
            )?;
            for result in parallel {
                let scan_metadata = result?;
                // Process scan metadata...
            }
        }
    }
}
Source

pub fn execute( &self, engine: Arc<dyn Engine>, ) -> DeltaResult<impl Iterator<Item = DeltaResult<Box<dyn EngineData>>>>

Perform an “all in one” scan. This will use the provided engine to read and process all the data for the query. Each EngineData in the resultant iterator is a portion of the final table data. Generally connectors/engines will want to use Scan::scan_metadata so they can have more control over the execution of the scan.

Returns an error if the scan was built with ScanBuilder::without_row_transforms; use Scan::scan_metadata instead.

Trait Implementations§

Source§

impl Debug for Scan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Scan

§

impl !RefUnwindSafe for Scan

§

impl Send for Scan

§

impl Sync for Scan

§

impl Unpin for Scan

§

impl UnsafeUnpin for Scan

§

impl !UnwindSafe for Scan

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any + Send + Sync,

Source§

fn any_ref(&self) -> &(dyn Any + Send + Sync + 'static)

Obtains a dyn Any reference to the object: Read more
Source§

fn as_any(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Obtains an Arc<dyn Any> reference to the object: Read more
Source§

fn into_any(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts the object to Box<dyn Any>: Read more
Source§

fn type_name(&self) -> &'static str

Convenient wrapper for std::any::type_name, since Any does not provide it and Any::type_id is useless as a debugging aid (its Debug is just a mess of hex digits).
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more