Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add high-level checking for append-only tables #1887

Merged
Merged
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
2 changes: 2 additions & 0 deletions crates/deltalake-core/src/operations/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ impl std::future::IntoFuture for DeleteBuilder {
let mut this = self;

Box::pin(async move {
PROTOCOL.check_append_only(&this.snapshot)?;

PROTOCOL.can_write_to(&this.snapshot)?;

let state = this.state.unwrap_or_else(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ impl ProtocolChecker {
2
}

/// Check append-only at the high level (operation level)
pub fn check_append_only(&self, snapshot: &DeltaTableState) -> Result<(), TransactionError> {
if snapshot.table_config().append_only() {
return Err(TransactionError::DeltaTableAppendOnly);
}
Ok(())
}

/// Check if delta-rs can read form the given delta table.
pub fn can_read_from(&self, snapshot: &DeltaTableState) -> Result<(), TransactionError> {
let required_features: Option<&HashSet<ReaderFeatures>> =
Expand Down
2 changes: 2 additions & 0 deletions crates/deltalake-core/src/operations/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ impl std::future::IntoFuture for UpdateBuilder {
let mut this = self;

Box::pin(async move {
PROTOCOL.check_append_only(&this.snapshot)?;

PROTOCOL.can_write_to(&this.snapshot)?;

let state = this.state.unwrap_or_else(|| {
Expand Down
4 changes: 4 additions & 0 deletions crates/deltalake-core/src/operations/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ impl std::future::IntoFuture for WriteBuilder {
let mut this = self;

Box::pin(async move {
if this.mode == SaveMode::Overwrite {
PROTOCOL.check_append_only(&this.snapshot)?;
}

// Create table actions to initialize table in case it does not yet exist and should be created
let mut actions = this.check_preconditions().await?;

Expand Down
2 changes: 1 addition & 1 deletion crates/deltalake-core/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl DeltaOperation {
}

/// The SaveMode used when performing a DeltaOperation
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum SaveMode {
/// Files will be appended to the target location.
Append,
Expand Down
Loading