-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21811][SQL] Fix the inconsistency behavior when finding the widest common type #21074
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 1 commit
803a6a4
571912f
d77f213
4ce5081
55eefe0
c2abce2
ff514af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,9 @@ object TypeCoercion { | |
| // to a op (b op c). This is only a problem for StringType. Excluding StringType, | ||
| // findWiderTypeForTwo satisfies the associative law. For instance, (TimestampType, | ||
| // IntegerType, StringType) should have StringType as the wider common type. | ||
| val (stringTypes, nonStringTypes) = types.partition(_ == StringType) | ||
| val (stringTypes, nonStringTypes) = types.partition { t => | ||
| t == StringType || t == ArrayType(StringType) | ||
|
||
| } | ||
| (stringTypes.distinct ++ nonStringTypes).foldLeft[Option[DataType]](Some(NullType))((r, c) => | ||
| r match { | ||
| case Some(d) => findWiderTypeForTwo(d, c) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -539,6 +539,9 @@ class TypeCoercionSuite extends AnalysisTest { | |
| val floatLit = Literal.create(1.0f, FloatType) | ||
| val timestampLit = Literal.create("2017-04-12", TimestampType) | ||
| val decimalLit = Literal(new java.math.BigDecimal("1000000000000000000000")) | ||
| val tsArrayLit = Literal(Array(new Timestamp(System.currentTimeMillis()))) | ||
| val strArrayLit = Literal(Array("c")) | ||
| val intArrayLit = Literal(Array(1)) | ||
|
|
||
| ruleTest(rule, | ||
| Coalesce(Seq(doubleLit, intLit, floatLit)), | ||
|
|
@@ -577,6 +580,11 @@ class TypeCoercionSuite extends AnalysisTest { | |
| Coalesce(Seq(timestampLit, intLit, stringLit)), | ||
| Coalesce(Seq(Cast(timestampLit, StringType), Cast(intLit, StringType), | ||
| Cast(stringLit, StringType)))) | ||
|
|
||
| ruleTest(rule, | ||
| Coalesce(Seq(tsArrayLit, intArrayLit, strArrayLit)), | ||
| Coalesce(Seq(Cast(tsArrayLit, ArrayType(StringType)), | ||
| Cast(intArrayLit, ArrayType(StringType)), Cast(strArrayLit, ArrayType(StringType))))) | ||
|
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. Could you add an end to end test case that can trigger this?
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 usually don't add end-to-end tests for type coercion changes, as the type coercion logic is pretty isolated, it's very unlikely that we can pass the unit test but not end-to-end test. |
||
| } | ||
|
|
||
| test("CreateArray casts") { | ||
|
|
||
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.
This is only a problem for StringType or nested StringType in ArrayType. Excluding these types, ...