diff --git a/crates/core/src/operations/merge/mod.rs b/crates/core/src/operations/merge/mod.rs index cef7331cb3..e8f45745af 100644 --- a/crates/core/src/operations/merge/mod.rs +++ b/crates/core/src/operations/merge/mod.rs @@ -56,6 +56,7 @@ use datafusion_expr::{ UNNAMED_TABLE, }; +use delta_kernel::schema::StructType; use filter::try_construct_early_filter; use futures::future::BoxFuture; use parquet::file::properties::WriterProperties; @@ -1001,9 +1002,10 @@ async fn execute( )?; let schema = Arc::new(schema_bulider.finish()); new_schema = Some(schema.clone()); - if schema != snapshot.input_schema()? { + let schema_struct: StructType = schema.try_into()?; + if &schema_struct != snapshot.schema() { let schema_action = Action::Metadata(Metadata::try_new( - schema.try_into()?, + schema_struct, current_metadata.partition_columns.clone(), snapshot.metadata().configuration.clone(), )?); @@ -1594,6 +1596,7 @@ impl std::future::IntoFuture for MergeBuilder { #[cfg(test)] mod tests { + use crate::kernel::Action; use crate::kernel::DataType; use crate::kernel::PrimitiveType; use crate::kernel::StructField; @@ -1769,7 +1772,7 @@ mod tests { .unwrap(); let commit_info = table.history(None).await.unwrap(); - dbg!(&commit_info); + let last_commit = &commit_info[0]; let parameters = last_commit.operation_parameters.clone().unwrap(); assert!(!parameters.contains_key("predicate")); @@ -1843,7 +1846,7 @@ mod tests { let commit_info = after_table.history(None).await.unwrap(); let last_commit = &commit_info[0]; - dbg!(&commit_info); + let parameters = last_commit.operation_parameters.clone().unwrap(); assert!(!parameters.contains_key("predicate")); assert_eq!(parameters["mergePredicate"], json!("target.id = source.id")); @@ -1861,8 +1864,22 @@ mod tests { ); assert_eq!(table.schema(), after_table.schema()); - dbg!(after_table.snapshot().unwrap().add_actions_table(true)); + let snapshot_bytes = after_table + .log_store + .read_commit_entry(2) + .await + .unwrap() + .expect("failed to get snapshot bytes"); + let actions = crate::logstore::get_actions(2, snapshot_bytes) + .await + .unwrap(); + + let schema_actions = actions + .iter() + .any(|action| matches!(action, Action::Metadata(_))); + + assert!(!schema_actions); assert_merge(after_table, metrics).await; }