-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-31166][SQL] UNION map<null, null> and other maps should not fail #27926
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
Conversation
|
Test build #119875 has finished for PR 27926 at commit
|
| checkAnswer( | ||
| sql("(SELECT map()) UNION ALL (SELECT map(1, 2))"), | ||
| Seq(Row(Map[Int, Int]()), Row(Map(1 -> 2)))) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! It seems #27542 broke some other queries merging map<null,null> and map<some type, some type>, e.g., map_concat;
// the current master
scala> sql("select map_concat(map(), map(1, 2))").show()
org.apache.spark.sql.AnalysisException: cannot resolve 'map_concat(map(), map(1, 2))' due to data type mismatch: input to function map_concat should all be the same type, but it's [map<null,null>, map<int,int>]; line 1 pos 7;
'Project [unresolvedalias(map_concat(map(), map(1, 2)), None)]
+- OneRowRelation
at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42)
This PR can fix this query, too.
|
thanks for review, merging to master/3.0! |
HyukjinKwon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
After #27542, `map()` returns `map<null, null>` instead of `map<string, string>`. However, this breaks queries which union `map()` and other maps. The reason is, `TypeCoercion` rules and `Cast` think it's illegal to cast null type map key to other types, as it makes the key nullable, but it's actually legal. This PR fixes it. To avoid breaking queries. Yes, now some queries that work in 2.x can work in 3.0 as well. new test Closes #27926 from cloud-fan/bug. Authored-by: Wenchen Fan <[email protected]> Signed-off-by: Wenchen Fan <[email protected]> (cherry picked from commit d7b97a1) Signed-off-by: Wenchen Fan <[email protected]>
…lex and Cast.canCast in null <> complex types ### What changes were proposed in this pull request? This PR (SPARK-31229) is rather a followup of #27926 (SPARK-31166). It adds unittests for `TypeCoercion.findTypeForComplex` and `Cast.canCast` about struct, map and array with the respect to null types. ### Why are the changes needed? To detect which scope was broken in the future easily. ### Does this PR introduce any user-facing change? No, it's a test-only. ### How was this patch tested? Unittests were added. Closes #27990 from HyukjinKwon/SPARK-31166-followup. Authored-by: HyukjinKwon <[email protected]> Signed-off-by: HyukjinKwon <[email protected]>
…lex and Cast.canCast in null <> complex types ### What changes were proposed in this pull request? This PR (SPARK-31229) is rather a followup of #27926 (SPARK-31166). It adds unittests for `TypeCoercion.findTypeForComplex` and `Cast.canCast` about struct, map and array with the respect to null types. ### Why are the changes needed? To detect which scope was broken in the future easily. ### Does this PR introduce any user-facing change? No, it's a test-only. ### How was this patch tested? Unittests were added. Closes #27990 from HyukjinKwon/SPARK-31166-followup. Authored-by: HyukjinKwon <[email protected]> Signed-off-by: HyukjinKwon <[email protected]> (cherry picked from commit bd32400) Signed-off-by: HyukjinKwon <[email protected]>
### What changes were proposed in this pull request? After apache#27542, `map()` returns `map<null, null>` instead of `map<string, string>`. However, this breaks queries which union `map()` and other maps. The reason is, `TypeCoercion` rules and `Cast` think it's illegal to cast null type map key to other types, as it makes the key nullable, but it's actually legal. This PR fixes it. ### Why are the changes needed? To avoid breaking queries. ### Does this PR introduce any user-facing change? Yes, now some queries that work in 2.x can work in 3.0 as well. ### How was this patch tested? new test Closes apache#27926 from cloud-fan/bug. Authored-by: Wenchen Fan <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
…lex and Cast.canCast in null <> complex types ### What changes were proposed in this pull request? This PR (SPARK-31229) is rather a followup of apache#27926 (SPARK-31166). It adds unittests for `TypeCoercion.findTypeForComplex` and `Cast.canCast` about struct, map and array with the respect to null types. ### Why are the changes needed? To detect which scope was broken in the future easily. ### Does this PR introduce any user-facing change? No, it's a test-only. ### How was this patch tested? Unittests were added. Closes apache#27990 from HyukjinKwon/SPARK-31166-followup. Authored-by: HyukjinKwon <[email protected]> Signed-off-by: HyukjinKwon <[email protected]>
What changes were proposed in this pull request?
After #27542,
map()returnsmap<null, null>instead ofmap<string, string>. However, this breaks queries which unionmap()and other maps.The reason is,
TypeCoercionrules andCastthink it's illegal to cast null type map key to other types, as it makes the key nullable, but it's actually legal. This PR fixes it.Why are the changes needed?
To avoid breaking queries.
Does this PR introduce any user-facing change?
Yes, now some queries that work in 2.x can work in 3.0 as well.
How was this patch tested?
new test