From 4c3c70b28c3e7e32271da6dc1c46924e0cbcf727 Mon Sep 17 00:00:00 2001 From: Fred Storage Liu Date: Sat, 21 Sep 2024 06:37:27 +0800 Subject: [PATCH] Make CTAS with replace honor column mapping when writing first set of parquet files (#3696) #### Which Delta project/connector is this regarding? - [x] Spark - [ ] Standalone - [ ] Flink - [ ] Kernel - [ ] Other (fill in here) ## Description Make CTAS with replace honor column mapping when writing first set of parquet files; Otherwise the uniform table will end up with parquet files without column mapping and thus have null in query results. ## How was this patch tested? manual test with CTAS. ## Does this PR introduce _any_ user-facing changes? --- .../spark/sql/delta/commands/CreateDeltaTableCommand.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spark/src/main/scala/org/apache/spark/sql/delta/commands/CreateDeltaTableCommand.scala b/spark/src/main/scala/org/apache/spark/sql/delta/commands/CreateDeltaTableCommand.scala index 631b992b1c..c3cb0731db 100644 --- a/spark/src/main/scala/org/apache/spark/sql/delta/commands/CreateDeltaTableCommand.scala +++ b/spark/src/main/scala/org/apache/spark/sql/delta/commands/CreateDeltaTableCommand.scala @@ -733,6 +733,10 @@ case class CreateDeltaTableCommand( // When a table already exists, and we're using the DataFrameWriterV2 API to replace // or createOrReplace a table, we blindly overwrite the metadata. val newMetadata = getProvidedMetadata(table, schema.json) + val updatedConfig = UniversalFormat.enforceDependenciesInConfiguration( + newMetadata.configuration, + txn.snapshot) + newMetadata = newMetadata.copy(configuration = updatedConfig) txn.updateMetadataForNewTableInReplace(newMetadata) } }