[SPARK] Support CTAS from a table with a deleted default value #4142
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which Delta project/connector is this regarding?
Description
We are currently leaking values using the 'EXISTS_DEFAULT' config key that is used for default columns in Spark into table schemas. The 'EXISTS_DEFAULT' key holds values for rows that existed when a new column with a default value was added to the table. This use case is not supported in Delta.
In this PR, we remove the 'EXISTS_DEFAULT' entries every time we update the metadata of a table. This includes the case when a table is created. This ensures that new tables do not have 'EXISTS_DEFAULT' entries and operations that update metadata remove entries that existed before because previous versions added them.
This change also now allows us to CTAS from a table where a default value existed in the past but has been dropped. It does not enable CTAS from a table with an active default value.
The feature has a kill switch: REMOVE_EXISTS_DEFAULT_FROM_SCHEMA_ON_EVERY_METADATA_CHANGE
How was this patch tested?
Added new tests
Does this PR introduce any user-facing changes?
Previously it was not possible to CTAS from a table with a removed default without setting the delta.feature.allowColumnDefaults even though no default value was actually part of the new table. this is now possible.