From f73575ba6387ca18cdf5aea9669c9af43c947fd6 Mon Sep 17 00:00:00 2001 From: PierreDubrulle Date: Sun, 12 Nov 2023 23:03:28 +0100 Subject: [PATCH] done --- crates/deltalake-core/src/table/mod.rs | 46 +++++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/crates/deltalake-core/src/table/mod.rs b/crates/deltalake-core/src/table/mod.rs index 2d4511064b..53a59cb3d1 100644 --- a/crates/deltalake-core/src/table/mod.rs +++ b/crates/deltalake-core/src/table/mod.rs @@ -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, // 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, + #[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, } +#[derive(Default)] /// Builder for CheckPoint pub struct CheckPointBuilder { /// Delta table version @@ -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, } } @@ -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) -> 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, } } } @@ -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); }