-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] - Automatic schema evolution does not work in map value structs #1641
Comments
HI @Orpheuz - which version of Delta are you using? Also - thanks for offering to contribute the fix! |
Hey @scottsand-db the code snippet in the description was tested using DBR 12.2 LTS. I have also reproduced the bug in unit tests in master. I'll try to push a fix soon Update: I might have underestimated the effort while comparing this fix to the array of structs. Maps are much more tricky 😞 Update 2: Managed to solve the issue, had a typo that was throwing me off |
## Description This PR resolves issue #1641 to allow automatic schema evolution in structs that are inside maps. Assuming the target and source tables have the following schemas: target: `id string, map map<int, struct<a: int, b: int>>` source: `id string, map map<int, struct<a: int, b: int, c: int>>` ``` SET spark.databricks.delta.schema.autoMerge.enabled = true; MERGE INTO target t USING source s ON t.id = s.id WHEN MATCHED THEN UPDATE SET * ``` returns an analysis error today: ``` AnalysisException: cannot resolve 's.map' due to data type mismatch: cannot cast map<string,struct<a:int,b:int>> to map<string,struct<a:int,b:int,c:string>>; ``` With this change, the merge command succeeds and the target table schema evolves to include field `c` inside the map value. The same also works for map keys. - Tests are added to `MergeIntoSuiteBase` and `MergeIntoSQLSuite` to cover struct evolution inside of maps values and keys. ## Does this PR introduce _any_ user-facing changes? Yes, struct evolution inside of maps now succeeds instead of failing with an analysis error, see previous example. Closes #1868 GitOrigin-RevId: 07ce2531e03c4e2fa69e8a34f33ba8d2dc3a0228
Merged #1868 implementing struct evolution for map keys and values. |
Bug
Describe the problem
Automatic schema evolution in delta does not allow evolution of structs inside maps
Steps to reproduce
This can be replicated with
Observed results
Expected results
No exception to be thrown and maps being correctly casted to allow evolution.
Further details
Environment information
DBR 12.1 LTS
Willingness to contribute
The Delta Lake Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the Delta Lake code base?
The text was updated successfully, but these errors were encountered: