delta-io / delta

An open-source storage framework that enables building a Lakehouse architecture with compute engines including Spark, PrestoDB, Flink, Trino, and Hive and APIs
https://delta.io
Apache License 2.0
7.62k stars 1.71k forks source link

[Spark] Allow setting both allowTypeWidening and keepExistingTypes to true in mergeSchemas #3759

Closed aldenlau-db closed 1 month ago

aldenlau-db commented 1 month ago

Which Delta project/connector is this regarding?

Description

Currently, SchemaMergingUtils.mergeSchemas will not widen fields when both keepExistingTypes and allowTypeWidening are set to true. This change will allow types to be widened when both keepExistingTypes and allowTypeWidening are true, and in the case of non-widening type changes, the existing type will be kept. This change can be used to fall back to existing types instead of throwing a DeltaAnalysisException when we want to merge a schema with widened fields that may also have non-widenable type changes.

How was this patch tested?

New unit test in SchemaUtilsSuite.scala

Does this PR introduce any user-facing changes?

No