-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24012][SQL] Union of map and other compatible column #21100
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
Changes from 4 commits
a422a7f
cb883d9
19b5c6a
0845739
670824f
8cb240f
4b1ce36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,14 @@ object TypeCoercion { | |
| val dataType = findTightestCommonType(f1.dataType, f2.dataType).get | ||
| StructField(f1.name, dataType, nullable = f1.nullable || f2.nullable) | ||
| })) | ||
| case (a1 @ ArrayType(et1, hasNull1), a2 @ ArrayType(et2, hasNull2)) | ||
| if a1.sameType(a2) => | ||
| findTightestCommonType(et1, et2).map(ArrayType(_, hasNull1 || hasNull2)) | ||
| case (m1 @ MapType(kt1, vt1, hasNull1), m2 @ MapType(kt2, vt2, hasNull2)) | ||
| if m1.sameType(m2) => | ||
| val keyType = findTightestCommonType(kt1, kt2) | ||
| val valueType = findTightestCommonType(vt1, vt2) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I think we should do the same thing in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something we should figure out: why Anyway it's orthogonal to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I was just wondering while reading it. However, doesn't that mean we don't do type widening for nested types in the same way? I was thinking we should do the same type widening for nested types too.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, I was thinking we should do that in both places in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, it's orthogonal. Yup, I was just wondering. I am okay to leave this out of this PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops, I misread your comment. Sorry. I was talking about the same thing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to look into
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with that given past discussions - I didn't mean we should change something now .. but was just wondering. |
||
| Some(MapType(keyType.get, valueType.get, hasNull1 || hasNull2)) | ||
|
|
||
| case _ => None | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,11 @@ FROM (SELECT col AS col | |
| SELECT col | ||
| FROM p3) T1) T2; | ||
|
|
||
| -- SPARK-24012 Union of map and other compatible columns. | ||
| SELECT map(1, 2), 'str' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we also add a test for array? |
||
| UNION ALL | ||
| SELECT map(1, 2, 3, NULL), 1; | ||
|
|
||
| -- Clean-up | ||
| DROP VIEW IF EXISTS t1; | ||
| DROP VIEW IF EXISTS t2; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -896,6 +896,19 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |
| } | ||
| } | ||
|
|
||
| test("SPARK-24012 Union of map and other compatible columns") { | ||
|
||
| checkAnswer( | ||
| sql( | ||
| """ | ||
| |SELECT map(1, 2), 'str' | ||
| |UNION ALL | ||
| |SELECT map(1, 2, 3, NULL), 1""".stripMargin), | ||
|
||
| Row.fromSeq(Seq(Map(1 -> 2), "str")):: | ||
| Row.fromSeq(Seq(Map(1 -> 2, 3 -> null), "1")):: | ||
| Nil | ||
| ) | ||
| } | ||
|
|
||
| test("EXCEPT") { | ||
| checkAnswer( | ||
| sql("SELECT * FROM lowerCaseData EXCEPT SELECT * FROM upperCaseData"), | ||
|
|
||
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.
after shortening the name, can we merge the
ifto thecase ...line?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.
also we need blank line between these cases