Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10577#discussion_r48931351
  
    --- 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 --
    
    Already updated a test case to cover a simple case. Will add more 
complicates cases to ensure all the cases are covered. True, the code looks 
hard to understand now. Will make it readable. 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to