From c3c73f8042ff6c39e7e84acb74d641690c974afb Mon Sep 17 00:00:00 2001 From: Nikolay Ulmasov Date: Mon, 1 Jan 2024 22:27:31 +0000 Subject: [PATCH] split unit test Signed-off-by: Nikolay Ulmasov --- crates/deltalake-core/src/operations/write.rs | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/crates/deltalake-core/src/operations/write.rs b/crates/deltalake-core/src/operations/write.rs index 9888404d31..0933701a02 100644 --- a/crates/deltalake-core/src/operations/write.rs +++ b/crates/deltalake-core/src/operations/write.rs @@ -1133,18 +1133,16 @@ mod tests { assert_batches_eq!(&expected, &data); } + // TODO: add tests for replaceWhere with partition column + #[tokio::test] async fn test_replace_where() { - // TODO: add tests for replaceWhere with partition column - let tmp_dir = tempdir::TempDir::new("test").unwrap(); - let tmp_path = std::fs::canonicalize(tmp_dir.path()).unwrap(); + // let tmp_dir = tempdir::TempDir::new("test").unwrap(); + // let tmp_path = std::fs::canonicalize(tmp_dir.path()).unwrap(); let schema = get_arrow_schema(&None); - // let table = DeltaOps::new_in_memory() - // let ops = DeltaOps::try_from_uri("/tmp/issue_1957_delta_rs").await.unwrap(); - // let table = ops - let table_path = tmp_path.as_os_str().to_str().unwrap(); - let ops = DeltaOps::try_from_uri(table_path).await.unwrap(); + // let table_path = tmp_path.as_os_str().to_str().unwrap(); + // let ops = DeltaOps::try_from_uri(table_path).await.unwrap(); let batch = RecordBatch::try_new( Arc::clone(&schema), @@ -1161,9 +1159,7 @@ mod tests { ) .unwrap(); - // write some data - // let table = DeltaOps(table) - let table = ops + let table = DeltaOps::new_in_memory() .write(vec![batch]) .with_save_mode(SaveMode::Append) .await @@ -1199,6 +1195,38 @@ mod tests { ]; let actual = get_data(&table).await; assert_batches_sorted_eq!(&expected, &actual); + } + + #[tokio::test] + async fn test_replace_where_fail_not_matching_predicate() { + let tmp_dir = tempdir::TempDir::new("test").unwrap(); + let tmp_path = std::fs::canonicalize(tmp_dir.path()).unwrap(); + + let schema = get_arrow_schema(&None); + let table_path = tmp_path.as_os_str().to_str().unwrap(); + let ops = DeltaOps::try_from_uri(table_path).await.unwrap(); + + let batch = RecordBatch::try_new( + Arc::clone(&schema), + vec![ + Arc::new(arrow::array::StringArray::from(vec!["A", "B", "C", "C"])), + Arc::new(arrow::array::Int32Array::from(vec![0, 20, 10, 100])), + Arc::new(arrow::array::StringArray::from(vec![ + "2021-02-02", + "2021-02-03", + "2021-02-02", + "2021-02-04", + ])), + ], + ) + .unwrap(); + + let table = ops + .write(vec![batch]) + .with_save_mode(SaveMode::Append) + .await + .unwrap(); + assert_eq!(table.version(), 0); let batch_fail = RecordBatch::try_new( Arc::clone(&schema), @@ -1218,9 +1246,6 @@ mod tests { assert!(table.is_err()); let table = crate::open_table(table_path).await.unwrap(); - assert_eq!(table.get_latest_version().await.unwrap(), 1); - - let actual = get_data(&table).await; - assert_batches_sorted_eq!(&expected, &actual); + assert_eq!(table.get_latest_version().await.unwrap(), 0); } }