naveenp2708 commented on code in PR #57644:
URL: https://github.com/apache/spark/pull/57644#discussion_r3767981372


##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/DatasetManager.scala:
##########
@@ -317,9 +317,19 @@ object DatasetManager extends Logging {
     val (catalog, identifier) =
       PipelinesCatalogUtils.resolveTableCatalog(context.spark, 
table.identifier)
 
-    val outputSchema = table.specifiedSchema.getOrElse(
-      inferredSchemas(table.identifier).asNullable
-    )
+    val outputSchema = table.specifiedSchema match {
+      case Some(ss) =>
+        // The user schema describes the logical table; the engine owns the 
reserved AUTO CDC
+        // metadata column(s). Append any that the incoming flows produce but 
the user omitted,
+        // so the created table matches what the AUTO CDC MERGE writes at 
runtime.
+        val specifiedNames = ss.fieldNames.toSet
+        val omittedReservedFields = AutoCdcMergeFlow
+          .reservedFields(inferredSchemas(table.identifier))
+          .filterNot(f => specifiedNames.contains(f.name))

Review Comment:
   Good catch. Switched this to match through the session resolver, so a 
reserved column declared in a different case is recognized and not re-appended 
as a duplicate. One note, I didn't add a unit test for the case-insensitive 
path. I tried, but schema inference reflects the declared column's case, which 
made a validation-level test unreliable. The duplicate-append case here is the 
one that really needs guarding, and that needs an integration test. Happy to 
add one if you'd prefer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to