Github user adrian-wang commented on a diff in the pull request:
https://github.com/apache/spark/pull/2246#discussion_r17092407
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/json/JsonRDD.scala
---
@@ -125,12 +125,16 @@ private[sql] object JsonRDD extends Logging {
* Returns the most general data type for two given data types.
*/
private[json] def compatibleType(t1: DataType, t2: DataType): DataType =
{
- // Try and find a promotion rule that contains both types in question.
- val applicableConversion = HiveTypeCoercion.allPromotions.find(p =>
p.contains(t1) && p
- .contains(t2))
+ val returnType = if (t1 == t2) {
+ Some(t1)
+ } else {
+ // Try and find a promotion rule that contains both types in
question.
+ val applicableConversion = HiveTypeCoercion.allPromotions.find(p =>
p.contains(t1) && p
+ .contains(t2))
- // If found return the widest common type, otherwise None
- val returnType = applicableConversion.map(_.filter(t => t == t1 || t
== t2).last)
+ // If found return the widest common type, otherwise None
+ applicableConversion.map(_.filter(t => t == t1 || t == t2).last)
--- End diff --
But I think in the future we should also support complex type promotion in
`findTightestCommonType(t1, t2)`. Anyway we can extract the current
`findTightestCommonType(t1, t2)` as a util function. What do you prefer?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]