Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/2246#discussion_r17092489
--- 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 --
Yeah, I don't see any reason to over plan for possible extension in the
future. Since this code is the same in both places I think it'd be better to
just call findTightestCommonType instead of duplicating it. If we decide to
add more rules in the future we can add a new function that calls this simpler
version.
---
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]