suhuruli opened a new pull request, #60463:
URL: https://github.com/apache/spark/pull/60463

   ### What changes were proposed in this pull request?
   
   On incremental (additive) schema evolution of a pipeline table, 
`DatasetManager.evolveTable` computes the target schema as 
`SchemaMergingUtils.mergeSchemas(currentSchema, desiredSchema, caseSensitive)`, 
which delegates to `StructType.merge`. For a column present in both schemas, 
`StructType.merge` keeps the left (current) field's metadata. Any change to an 
existing column's comment or other field metadata in the desired schema is 
therefore dropped before `diffSchemas` computes the `TableChange`s.
   
   This PR:
   - Adds `SchemaMergingUtils.mergeSchemasWithDataMetadata`. It performs the 
same additive merge as `mergeSchemas`. For fields present in both schemas, it 
takes field metadata from the desired (data) schema, recursing into structs, 
arrays, and maps. Field names, positions, types, and nullability still follow 
the merge. Fields present only in the current schema keep their metadata.
   - Uses it in `DatasetManager.evolveTable` when `mergeWithExistingSchema = 
true`. This applies to incrementally updated streaming tables and to auxiliary 
tables.
   - Leaves `mergeSchemas` unchanged. Its other callers rely on the left side 
winning. For example, the user-specified schema's metadata takes precedence 
over the inferred schema's.
   
   With this change, the merge path treats metadata on shared columns the same 
way as the non-merging path (materialized views, full refresh), where the 
desired schema is used as-is. Default-value changes now reach `diffSchemas`, 
but `diffSchemas` does not apply them yet; that is tracked in SPARK-59269, 
which this issue blocks.
   
   ### Why are the changes needed?
   
   When a user changes, adds, or removes a column comment on a streaming table 
between runs, the change is never applied to the table. The same change on a 
materialized view is applied.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. On incremental updates of a streaming table, column comment changes in 
the declared schema are now applied to the table. Previously they were ignored. 
This includes added, changed, and removed comments, and comments on nested 
fields.
   
   ### How was this patch tested?
   
   - New `MaterializeTablesSuite` test: re-materializes a streaming table with 
one comment changed, one comment removed, and one nested comment changed. It 
asserts that the expected `UpdateColumnComment` changes are issued and that the 
persisted columns match. The test fails without the fix because no `alterTable` 
is issued.
   - New `SchemaMergingUtilsSuite` tests for `mergeSchemasWithDataMetadata`: 
changed, added, and removed comments; default values; columns present on only 
one side; nested structs inside arrays and maps; and case-insensitive folding 
that keeps the current column name.
   - `build/sbt pipelines/test` (861 tests pass), `pipelines/scalastyle`, and 
`pipelines/Test/scalastyle`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
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