Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/10577#discussion_r48931170
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
---
@@ -212,22 +212,48 @@ object HiveTypeCoercion {
case other => None
}
- def castOutput(plan: LogicalPlan): LogicalPlan = {
- val casted = plan.output.zip(castedTypes).map {
- case (e, Some(dt)) if e.dataType != dt =>
- Alias(Cast(e, dt), e.name)()
- case (e, _) => e
- }
- Project(casted, plan)
+ if (castedTypes.exists(_.isDefined)) {
+ (castOutput(left, castedTypes), castOutput(right, castedTypes))
+ } else {
+ (left, right)
}
+ }
+
+ private[this] def widenOutputTypes(
+ planName: String,
+ children: Seq[LogicalPlan]): Seq[LogicalPlan] = {
+ require(children.forall(_.output.length ==
children.head.output.length))
+
+ val castedTypes: Seq[Option[DataType]] =
+ children.foldLeft(children.head.output.map(a =>
Option(a.dataType))) {
--- End diff --
this part is also a bit tricky to understand. i'd try to simplify it (or
write it in less functional way). also you should consider creating unit tests
for this function since it is getting more complicated.
---
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]