chore: fallback for spark.sql.mapKeyDedupPolicy == LAST_WIN#4863
Merged
Conversation
andygrove
reviewed
Jul 8, 2026
Comment on lines
+98
to
+100
| def isDefault: Boolean = | ||
| SQLConf.get.getConf(SQLConf.MAP_KEY_DEDUP_POLICY) == | ||
| SQLConf.MAP_KEY_DEDUP_POLICY.defaultValueString |
Member
There was a problem hiding this comment.
Checking for default vs non-default value seems brittle. What if the default changes in a later Spark version? Shouldn't we check explicitly for EXCEPTION vs LAST_WIN?
spark.sql.mapKeyDedupPolicyspark.sql.mapKeyDedupPolicy == LAST_WIN
peterxcli
reviewed
Jul 8, 2026
andygrove
approved these changes
Jul 8, 2026
Co-authored-by: Peter Lee <peterxcli@gmail.com>
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.
Which issue does this PR close?
Narrows the
spark.sql.mapKeyDedupPolicydivergence formap_from_arraysandmap_from_entriesreported in #4680Rationale for this change
Spark's
ArrayBasedMapBuilder(used by both expressions) honors two dedup modes:EXCEPTION(default): raise[DUPLICATED_MAP_KEY]on duplicate keys.LAST_WIN: keep the last occurrence.Comet is currently pinned to
datafusion-spark 54.0.0, whosemap_from_arrays/map_from_entriesimplement neither mode — duplicates simply pass through. That means:EXCEPTION(the default) with duplicate keys, Comet silently keeps duplicates instead of erroring — a data divergence tracked separately.LAST_WIN, Comet's output shape disagrees with Spark's per-key dedup — a config-driven divergence we can detect at plan time.Upstream apache/datafusion#21720 wires both modes into
datafusion-spark, but that fix has not yet landed in a release Comet pins to.What changes are included in this PR?
MapKeyDedupPolicySupportinserde/maps.scala— one helper checksspark.sql.mapKeyDedupPolicy == LAST_WIN.CometMapFromArraysandCometMapFromEntriesreturnIncompatiblewhenLAST_WINis active, so planning falls back to Spark for that config only.EXCEPTION(default) continues to run natively.CreateMap,MapConcat,TransformKeys, ...) already delegate to Spark'sdoGenCodeviaCometCodegenDispatchand inherit dedup semantics for free — no gate needed.Are these changes tested?
Yes — new SQL file tests exercise the fallback with
spark.sql.mapKeyDedupPolicy=LAST_WINfor both expressions, on literal and column inputs:spark/src/test/resources/sql-tests/expressions/map/map_from_arrays_dedup_policy.sqlspark/src/test/resources/sql-tests/expressions/map/map_from_entries_dedup_policy.sqlThe
map_from_entriestest also disables the codegen dispatcher so the incompat branch surfaces as a genuine Spark fallback rather than in-pipeline codegen.Follow-up
When Comet bumps to a
datafusion-sparkrelease containing #21720, this gate can be replaced by propagatingspark.sql.mapKeyDedupPolicy→datafusion.spark.map_key_dedup_policyand removing theIncompatiblebranch.str_to_mapgets the same upgrade for free.