From 05cad10b42410db1e94248800ca849087d581289 Mon Sep 17 00:00:00 2001 From: Robert Pack Date: Sat, 11 Nov 2023 19:21:41 +0100 Subject: [PATCH] fix: define snapshot trait outside of arrow module --- .../src/kernel/arrow/snapshot.rs | 22 +--------------- crates/deltalake-core/src/kernel/mod.rs | 1 + crates/deltalake-core/src/kernel/snapshot.rs | 26 +++++++++++++++++++ crates/deltalake-core/src/table/state.rs | 2 +- 4 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 crates/deltalake-core/src/kernel/snapshot.rs diff --git a/crates/deltalake-core/src/kernel/arrow/snapshot.rs b/crates/deltalake-core/src/kernel/arrow/snapshot.rs index 165cf4600f..1f83c7114f 100644 --- a/crates/deltalake-core/src/kernel/arrow/snapshot.rs +++ b/crates/deltalake-core/src/kernel/arrow/snapshot.rs @@ -20,31 +20,11 @@ use std::task::{ready, Poll}; use super::checkpoint::{parse_action, parse_actions}; use super::schemas::get_log_schema; use crate::kernel::error::{DeltaResult, Error}; +use crate::kernel::snapshot::Snapshot; use crate::kernel::{Action, ActionType, Add, Metadata, Protocol, StructType}; use crate::storage::path::{commit_version, is_checkpoint_file, is_commit_file, FileMeta, LogPath}; use crate::table::config::TableConfig; -/// A snapshot of a Delta table at a given version. -pub trait Snapshot: std::fmt::Display + Send + Sync + std::fmt::Debug + 'static { - /// The version of the table at this [`Snapshot`]. - fn version(&self) -> i64; - - /// Table [`Schema`](crate::kernel::schema::StructType) at this [`Snapshot`]'s version. - fn schema(&self) -> Option<&StructType>; - - /// Table [`Metadata`] at this [`Snapshot`]'s version. - fn metadata(&self) -> DeltaResult; - - /// Table [`Protocol`] at this [`Snapshot`]'s version. - fn protocol(&self) -> DeltaResult; - - /// Iterator over the [`Add`] actions at this [`Snapshot`]'s version. - fn files(&self) -> DeltaResult + '_>>; - - /// Well known table [configuration](crate::table::config::TableConfig). - fn table_config(&self) -> TableConfig<'_>; -} - /// A [`Snapshot`] that is dynamically typed. pub type DynSnapshot = dyn Snapshot; diff --git a/crates/deltalake-core/src/kernel/mod.rs b/crates/deltalake-core/src/kernel/mod.rs index c8d01c138d..a550f76731 100644 --- a/crates/deltalake-core/src/kernel/mod.rs +++ b/crates/deltalake-core/src/kernel/mod.rs @@ -8,6 +8,7 @@ pub mod client; pub mod error; pub mod expressions; pub mod schema; +pub mod snapshot; pub use actions::*; pub use error::*; diff --git a/crates/deltalake-core/src/kernel/snapshot.rs b/crates/deltalake-core/src/kernel/snapshot.rs new file mode 100644 index 0000000000..2475db0dfa --- /dev/null +++ b/crates/deltalake-core/src/kernel/snapshot.rs @@ -0,0 +1,26 @@ +//! Snapshot of a Delta table. + +use crate::kernel::error::DeltaResult; +use crate::kernel::{Add, Metadata, Protocol, StructType}; +use crate::table::config::TableConfig; + +/// A snapshot of a Delta table at a given version. +pub trait Snapshot: std::fmt::Display + Send + Sync + std::fmt::Debug + 'static { + /// The version of the table at this [`Snapshot`]. + fn version(&self) -> i64; + + /// Table [`Schema`](crate::kernel::schema::StructType) at this [`Snapshot`]'s version. + fn schema(&self) -> Option<&StructType>; + + /// Table [`Metadata`] at this [`Snapshot`]'s version. + fn metadata(&self) -> DeltaResult; + + /// Table [`Protocol`] at this [`Snapshot`]'s version. + fn protocol(&self) -> DeltaResult; + + /// Iterator over the [`Add`] actions at this [`Snapshot`]'s version. + fn files(&self) -> DeltaResult + '_>>; + + /// Well known table [configuration](crate::table::config::TableConfig). + fn table_config(&self) -> TableConfig<'_>; +} diff --git a/crates/deltalake-core/src/table/state.rs b/crates/deltalake-core/src/table/state.rs index cb1626cfd2..7049649ffc 100644 --- a/crates/deltalake-core/src/table/state.rs +++ b/crates/deltalake-core/src/table/state.rs @@ -12,8 +12,8 @@ use serde::{Deserialize, Serialize}; use super::config::TableConfig; use crate::errors::DeltaTableError; -use crate::kernel::arrow::snapshot::Snapshot; use crate::kernel::error::DeltaResult; +use crate::kernel::snapshot::Snapshot; use crate::kernel::{ Action, Add, CommitInfo, DataType, DomainMetadata, ReaderFeatures, Remove, StructType, WriterFeatures,