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 enforcement for invariants to commit checker #1882

Closed
wants to merge 12 commits into from
10 changes: 5 additions & 5 deletions crates/deltalake-core/src/kernel/actions/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub enum WriterFeatures {
/// ID Columns
IdentityColumns,
/// Deletion vectors for merge, update, delete
DeleteionVecotrs,
DeletionVectors,
/// Row tracking on tables
RowTracking,
/// timestamps without timezone support
Expand All @@ -291,7 +291,7 @@ impl Into<usize> for WriterFeatures {
WriterFeatures::ChangeDataFeed | WriterFeatures::GeneratedColumns => 4,
WriterFeatures::ColumnMapping => 5,
WriterFeatures::IdentityColumns
| WriterFeatures::DeleteionVecotrs
| WriterFeatures::DeletionVectors
| WriterFeatures::RowTracking
| WriterFeatures::TimestampWithoutTimezone
| WriterFeatures::DomainMetadata
Expand All @@ -311,7 +311,7 @@ impl From<String> for WriterFeatures {
"generatedColumns" => WriterFeatures::GeneratedColumns,
"columnMapping" => WriterFeatures::ColumnMapping,
"identityColumns" => WriterFeatures::IdentityColumns,
"deletionVectors" => WriterFeatures::DeleteionVecotrs,
"deletionVectors" => WriterFeatures::DeletionVectors,
"rowTracking" => WriterFeatures::RowTracking,
"timestampNtz" => WriterFeatures::TimestampWithoutTimezone,
"domainMetadata" => WriterFeatures::DomainMetadata,
Expand All @@ -332,7 +332,7 @@ impl AsRef<str> for WriterFeatures {
WriterFeatures::GeneratedColumns => "generatedColumns",
WriterFeatures::ColumnMapping => "columnMapping",
WriterFeatures::IdentityColumns => "identityColumns",
WriterFeatures::DeleteionVecotrs => "deletionVectors",
WriterFeatures::DeletionVectors => "deletionVectors",
WriterFeatures::RowTracking => "rowTracking",
WriterFeatures::TimestampWithoutTimezone => "timestampNtz",
WriterFeatures::DomainMetadata => "domainMetadata",
Expand Down Expand Up @@ -361,7 +361,7 @@ impl From<&parquet::record::Field> for WriterFeatures {
"generatedColumns" => WriterFeatures::GeneratedColumns,
"columnMapping" => WriterFeatures::ColumnMapping,
"identityColumns" => WriterFeatures::IdentityColumns,
"deletionVectors" => WriterFeatures::DeleteionVecotrs,
"deletionVectors" => WriterFeatures::DeletionVectors,
"rowTracking" => WriterFeatures::RowTracking,
"timestampNtz" => WriterFeatures::TimestampWithoutTimezone,
"domainMetadata" => WriterFeatures::DomainMetadata,
Expand Down
19 changes: 19 additions & 0 deletions crates/deltalake-core/src/operations/transaction/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ impl ProtocolChecker {
})?;
}

// Does the table have invariants?
let invariants = snapshot
.current_metadata()
.and_then(|meta| meta.schema.get_invariants().ok())
.unwrap_or_default()
.is_empty();
hntd187 marked this conversation as resolved.
Show resolved Hide resolved

// The table is at least version 7, has actual invariants and has the proper writer feature
// enabled
if snapshot.min_writer_version() >= 7
&& !invariants
hntd187 marked this conversation as resolved.
Show resolved Hide resolved
&& !snapshot
.writer_features()
.unwrap()
.contains(&WriterFeatures::Invariants)
{
return Err(TransactionError::WriterFeaturesRequired);
}

Ok(())
}
}
Expand Down
Loading