[core] Reject map key type changes in schema merging - #10116
Open
LuciferYang wants to merge 1 commit into
Open
LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
merge() recursively merged the key type of a MAP column like any other nested type, so with merge-schema and type-widening enabled a MAP<INT, V> column could evolve into MAP<BIGINT, V>. The read layer cannot cast map keys (createMapCastExecutor requires equal key types), so after such a merge every pre-change file crashed with IllegalStateException on scan, compaction, or stats read. Throw a descriptive UnsupportedOperationException when the key types differ, mirroring the method's other merge guards, so the schema change fails up front with an actionable reason instead of producing an unreadable table. Nullability is ignored (matching merge()'s contract and the read layer), so a key that only changes nullability still merges; map value types keep merging as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
close #10115
SchemaMergingUtils.merge()recursively merged the key type of a MAP column like any other nested type, so withwrite.merge-schemaand type widening enabled aMAP<INT, V>column could evolve intoMAP<BIGINT, V>. The read layer cannot cast map keys:SchemaEvolutionUtil.createMapCastExecutorasserts the input and target key types are equal and throwsIllegalStateExceptionotherwise, so after such a merge every pre-change file crashed on scan, compaction, or stats read. The explicitALTER TABLE ... UPDATE COLUMNpath already rejects a map key change; only the merge-schema path let it through.This throws a descriptive
UnsupportedOperationExceptionwhen the base and update map key types differ, mirroring the method's other merge guards, so the schema change fails up front with an actionable reason instead of producing an unreadable table. The comparison ignores nullability, matchingmerge()'s contract and the read layer: Spark forces map keys toNOT NULLwhile core and Flink default to a nullable key, so a key that changes only in nullability is a benign no-op and still merges. Map value types keep merging as before.Tests
SchemaMergingUtilsTest#testMergeMapTypesWithDifferentKeyTypes: mergingMAP<INT,V>withMAP<BIGINT,V>throwsUnsupportedOperationExceptionnaming "different key types", with and without explicit-cast/type-widening. It fails against the pre-fix code, which widened the key toBIGINT.SchemaMergingUtilsTest#testMergeMapKeyChangeNestedInRowIsRejected: the same rejection fires on the recursive path, for a MAP nested inside a ROW.SchemaMergingUtilsTest#testMergeMapKeysDifferingOnlyInNullabilityStillMerges: a map key that differs only in nullability (nullableINTvsINT NOT NULL) still merges, the base key's nullability flows to the result, and the value widens. This guards the nullability-ignoring comparison; a plainequalswould wrongly reject the common Flink-table-plus-Spark-merge-write case.API and Format
no
Documentation
no