Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ion-elgreco committed Sep 14, 2024
1 parent d5792c8 commit edc67b6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
84 changes: 82 additions & 2 deletions crates/core/src/operations/add_feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ impl AddTableFeatureBuilder {
}
}

/// Specify the feature to be added
pub fn with_feature<S: Into<TableFeatures>>(mut self, name: Vec<S>) -> Self {
/// Specify the features to be added
pub fn with_feature<S: Into<TableFeatures>>(mut self, name: S) -> Self {
self.name.push(name.into());
self
}

/// Specify the features to be added
pub fn with_features<S: Into<TableFeatures>>(mut self, name: Vec<S>) -> Self {
self.name
.extend(name.into_iter().map(Into::into).collect_vec());
self
Expand Down Expand Up @@ -114,3 +120,77 @@ impl std::future::IntoFuture for AddTableFeatureBuilder {
})
}
}

#[cfg(feature = "datafusion")]
#[cfg(test)]
mod tests {
use delta_kernel::DeltaResult;

use crate::{
kernel::TableFeatures,
writer::test_utils::{create_bare_table, get_record_batch},
DeltaOps,
};

#[tokio::test]
async fn add_feature() -> DeltaResult<()> {
let batch = get_record_batch(None, false);
let write = DeltaOps(create_bare_table())
.write(vec![batch.clone()])
.await
.unwrap();
let table = DeltaOps(write);
let result = table
.add_feature()
.with_feature(TableFeatures::ChangeDataFeed)
.with_allow_protocol_versions_increase(true)
.await
.unwrap();

assert!(&result
.protocol()
.cloned()
.unwrap()
.writer_features
.unwrap_or_default()
.contains(&crate::kernel::WriterFeatures::ChangeDataFeed));

let result = DeltaOps(result)
.add_feature()
.with_feature(TableFeatures::DeletionVectors)
.with_allow_protocol_versions_increase(true)
.await
.unwrap();

let current_protocol = &result.protocol().cloned().unwrap();
assert!(&current_protocol
.writer_features
.clone()
.unwrap_or_default()
.contains(&crate::kernel::WriterFeatures::DeletionVectors));
assert!(&current_protocol
.reader_features
.clone()
.unwrap_or_default()
.contains(&crate::kernel::ReaderFeatures::DeletionVectors));
assert_eq!(result.version(), 2);
Ok(())
}

#[tokio::test]
async fn add_feature_disallowed_increase() -> DeltaResult<()> {
let batch = get_record_batch(None, false);
let write = DeltaOps(create_bare_table())
.write(vec![batch.clone()])
.await
.unwrap();
let table = DeltaOps(write);
let result = table
.add_feature()
.with_feature(TableFeatures::ChangeDataFeed)
.await;

assert!(result.is_err());
Ok(())
}
}
2 changes: 1 addition & 1 deletion python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ impl RawDeltaTable {
self._table.log_store(),
self._table.snapshot().map_err(PythonError::from)?.clone(),
)
.with_feature(feature)
.with_features(feature)
.with_allow_protocol_versions_increase(allow_protocol_versions_increase);

if let Some(commit_properties) =
Expand Down
3 changes: 3 additions & 0 deletions python/tests/test_alter.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ def test_add_feature_variations(existing_table: DeltaTable, feature):
feature=feature,
allow_protocol_versions_increase=False,
)
last_action = existing_table.history(1)[0]
assert last_action["operation"] == "ADD FEATURE"
assert existing_table.version() == 1


def test_add_features_disallowed_protocol_increase(existing_sample_table: DeltaTable):
Expand Down

0 comments on commit edc67b6

Please sign in to comment.