Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18460#discussion_r127160057
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
 ---
    @@ -144,6 +145,16 @@ object TypeCoercion {
           .orElse((t1, t2) match {
             case (ArrayType(et1, containsNull1), ArrayType(et2, 
containsNull2)) =>
               findWiderTypeForTwo(et1, et2).map(ArrayType(_, containsNull1 || 
containsNull2))
    +        case (st1 @ StructType(fields1), st2 @ StructType(fields2)) if 
st1.sameType(st2) =>
    --- End diff --
    
    I don't think we should put this logic here, we are not finding a "wider" 
type here. I think a more proper place is in `findTightestCommonType` when we 
deal with data type equality. More generally, I think we should revisit when we 
should use `==` and when use `DataType.sameType` for data type equality check. 
For example, we can eliminate struct type cast if unnecessary.
    
    In this PR, even you fixed the struct type equality in type coercion, the 
`Cast` doesn't know it and we will end up executing unnecessary casts.


---
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]

Reply via email to