[SPARK-56164][SQL] Fix SPJ merged key ordering#54961
[SPARK-56164][SQL] Fix SPJ merged key ordering#54961peter-toth wants to merge 2 commits intoapache:masterfrom
Conversation
|
cc @szehon-ho , @dongjoon-hyun |
There was a problem hiding this comment.
Thank you, @peter-toth . This is only for 4.2.0, right?
This PR fixes a theoretical bug, a real world example is unlikely to exist.
Yes, I intend to fix in 4.2 only. I'm working on a new feature that can make this bug appear in real world scenarios. |
| fn | ||
| } | ||
| catalog.createFunction(id, fn) | ||
| def withFunctions[T](fns: UnboundFunction*)(f: => T): T = { |
There was a problem hiding this comment.
We don't use plural form for the helper functions, do we? The previous name withFunction looks better to me.
dongjoon-hyun
left a comment
There was a problem hiding this comment.
+1, LGTM (with only one nit naming comment).
| } | ||
| } | ||
|
|
||
| case class YearsToYearsReducerWithLogResult() extends Reducer[Int, Long] { |
| try f finally { | ||
| catalog.dropFunction(id) | ||
| oldFn.foreach(catalog.createFunction(id, _)) | ||
| oldFns.foreach { case (id, oldFn ) => |
| rightReducedDataTypes = rightReducedDataTypes) | ||
| } | ||
|
|
||
| val reducedKeyRowOrdering = RowOrdering.createNaturalAscendingOrdering(leftReducedDataTypes) |
There was a problem hiding this comment.
optional: maybe we can use:
val reducedDataTypes = (leftReducedDataTypes, rightReducedDataTypes) match {
case (l, r) if l == r => l
case (l, r) =>
throw QueryExecutionErrors.storagePartitionJoinIncompatibleReducedTypesError(
leftReducers = leftReducers,
leftReducedDataTypes = l,
rightReducers = rightReducers,
rightReducedDataTypes = r)
}
to avoid referring to left specifically and make it clearer
What changes were proposed in this pull request?
Fix a bug in
EnsureRequirementswhere the ordering used to merge and dedup partition keys after reduction was based on the original partition key types rather than the reduced types.When compatible partition transform reducers are applied (e.g. reducing days keys to years keys), the resulting partition key values may have a different
DataTypethan the originals.Please note that #54884 fixed the issue when left and right side reduced key types are not equal, but this PR fixes the issue when the common reduced types differ to the left side original types.
Why are the changes needed?
Without this fix, when reducers change the data type of partition keys (e.g.
DateType→LongType), the ordering used to merge partition values is built for the wrong type, which can produce incorrect merge results or runtime failures during storage-partitioned joins with compatible transform reducers.Does this PR introduce any user-facing change?
This PR fixes a theoretical bug, a real world example is unlikely to exist.
How was this patch tested?
Added a new test case.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Sonnet 4.6