Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDubrulle authored and Pierre Dubrulle committed Nov 13, 2023
1 parent 6357a2c commit f73575b
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions crates/deltalake-core/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ pub struct CheckPoint {
pub(crate) version: i64, // 20 digits decimals
/// The number of actions that are stored in the checkpoint.
pub(crate) size: i64,
#[serde(skip_serializing_if = "Option::is_none")]
/// The number of fragments if the last checkpoint was written in multiple parts. This field is optional.
pub(crate) parts: Option<u32>, // 10 digits decimals
#[serde(skip_serializing_if = "Option::is_none")]
/// The number of bytes of the checkpoint. This field is optional.
pub(crate) size_in_bytes: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
/// The number of AddFile actions in the checkpoint. This field is optional.
pub(crate) num_of_add_files: Option<i64>,
}

#[derive(Default)]
/// Builder for CheckPoint
pub struct CheckPointBuilder {
/// Delta table version
Expand All @@ -76,9 +80,9 @@ impl CheckPointBuilder {
CheckPointBuilder {
version,
size,
parts: Some(0),
parts: None,
size_in_bytes: None,
num_of_add_files: Some(0),
num_of_add_files: None,
}
}

Expand Down Expand Up @@ -115,22 +119,12 @@ impl CheckPointBuilder {
impl CheckPoint {
/// Creates a new checkpoint from the given parameters.
pub fn new(version: i64, size: i64, parts: Option<u32>) -> Self {
if parts.is_some() {
Self {
version,
size,
parts,
size_in_bytes: None,
num_of_add_files: Some(0),
}
} else {
Self {
version,
size,
parts: Some(0),
size_in_bytes: None,
num_of_add_files: Some(0),
}
Self {
version,
size,
parts: parts.or_else(|| None),
size_in_bytes: None,
num_of_add_files: None,
}
}
}
Expand Down Expand Up @@ -920,12 +914,24 @@ mod tests {
}

#[tokio::test]
async fn checkpoint_checker() {
async fn checkpoint_without_added_files_and_no_parts() {
let (dt, tmp_dir) = create_test_table().await;
let check_point = CheckPointBuilder::new(0, 0).build();
let checkpoint_data_paths = dt.get_checkpoint_data_paths(&check_point);
assert_eq!(checkpoint_data_paths.len(), 1);
println!("{:?}", check_point);
assert_eq!(serde_json::to_string(&check_point).unwrap(), "{\"version\":0,\"size\":0}");
drop(tmp_dir);
}

#[tokio::test]
async fn checkpoint_with_added_files() {

let num_of_file_added: i64 = 4;
let (dt, tmp_dir) = create_test_table().await;
let check_point = CheckPointBuilder::new(0, 0).with_num_of_add_files(num_of_file_added).build();
let checkpoint_data_paths = dt.get_checkpoint_data_paths(&check_point);
assert_eq!(checkpoint_data_paths.len(), 1);
assert_eq!(serde_json::to_string(&check_point).unwrap(), "{\"version\":0,\"size\":0,\"num_of_add_files\":4}");
drop(tmp_dir);
}

Expand Down

0 comments on commit f73575b

Please sign in to comment.