Skip to content

Conversation

@cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

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.

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

@cloud-fan
Copy link
Contributor Author

cc @maropu @HyukjinKwon

@SparkQA
Copy link

SparkQA commented Mar 16, 2020

Test build #119875 has finished for PR 27926 at commit 125d094.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

checkAnswer(
sql("(SELECT map()) UNION ALL (SELECT map(1, 2))"),
Seq(Row(Map[Int, Int]()), Row(Map(1 -> 2))))
}
Copy link
Member

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.

@cloud-fan cloud-fan closed this in d7b97a1 Mar 17, 2020
@cloud-fan
Copy link
Contributor Author

thanks for review, merging to master/3.0!

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cloud-fan added a commit that referenced this pull request Mar 17, 2020
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]>
HyukjinKwon added a commit that referenced this pull request Mar 24, 2020
…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]>
HyukjinKwon added a commit that referenced this pull request Mar 24, 2020
…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]>
sjincho pushed a commit to sjincho/spark that referenced this pull request Apr 15, 2020
### 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]>
sjincho pushed a commit to sjincho/spark that referenced this pull request Apr 15, 2020
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants