Skip to content

Commit

Permalink
chore: add more robust regression tests for the checkpoint related fa…
Browse files Browse the repository at this point in the history
…ilure(s)

See #3030

Signed-off-by: R. Tyler Croy <[email protected]>
  • Loading branch information
rtyler committed Dec 3, 2024
1 parent ba671c9 commit b68c82d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
26 changes: 23 additions & 3 deletions crates/core/src/protocol/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,10 +1163,16 @@ mod tests {
}

/// <https://github.com/delta-io/delta-rs/issues/3030>
#[cfg(feature = "datafusion")]
#[tokio::test]
async fn test_create_checkpoint_overwrite() -> DeltaResult<()> {
use crate::protocol::SaveMode;
use crate::writer::test_utils::datafusion::get_data_sorted;
use crate::writer::test_utils::get_arrow_schema;
use datafusion::assert_batches_sorted_eq;

let tmp_dir = tempfile::tempdir().unwrap();
let tmp_path = std::fs::canonicalize(tmp_dir.path()).unwrap();

let batch = RecordBatch::try_new(
Arc::clone(&get_arrow_schema(&None)),
Expand All @@ -1177,13 +1183,15 @@ mod tests {
],
)
.unwrap();
let table = DeltaOps::try_from_uri_with_storage_options("memory://", HashMap::default())

let mut table = DeltaOps::try_from_uri(tmp_path.as_os_str().to_str().unwrap())
.await?
.write(vec![batch])
.await?;
table.load().await?;
assert_eq!(table.version(), 0);

create_checkpoint_for(0, table.snapshot().unwrap(), table.log_store.as_ref()).await?;
create_checkpoint(&table).await?;

let batch = RecordBatch::try_new(
Arc::clone(&get_arrow_schema(&None)),
Expand All @@ -1194,11 +1202,23 @@ mod tests {
],
)
.unwrap();
let table = DeltaOps(table)

let table = DeltaOps::try_from_uri(tmp_path.as_os_str().to_str().unwrap())
.await?
.write(vec![batch])
.with_save_mode(SaveMode::Overwrite)
.await?;
assert_eq!(table.version(), 1);

let expected = [
"+----+-------+------------+",
"| id | value | modified |",
"+----+-------+------------+",
"| A | 0 | 2021-02-02 |",
"+----+-------+------------+",
];
let actual = get_data_sorted(&table, "id,value,modified").await;
assert_batches_sorted_eq!(&expected, &actual);
Ok(())
}
}
25 changes: 13 additions & 12 deletions python/tests/test_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,18 +483,19 @@ def test_checkpoint_with_multiple_writes(tmp_path: pathlib.Path):
}
),
)
DeltaTable(tmp_path).create_checkpoint()
dt = DeltaTable(tmp_path)
dt.create_checkpoint()
assert dt.version() == 0
df = pd.DataFrame(
{
"a": ["a"],
"b": [100],
}
)
write_deltalake(tmp_path, df, mode="overwrite")

dt = DeltaTable(tmp_path)
assert dt.version() == 1
new_df = dt.to_pandas()
print(dt.to_pandas())

write_deltalake(
tmp_path,
pd.DataFrame(
{
"a": ["a"],
"b": [100],
}
),
mode="overwrite",
)
assert len(new_df) == 1, "We overwrote! there should only be one row"

0 comments on commit b68c82d

Please sign in to comment.