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

    https://github.com/apache/spark/pull/8983#discussion_r41475573
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
 ---
    @@ -305,12 +305,22 @@ object HiveTypeCoercion {
     
       /**
        * Convert all expressions in in() list to the left operator type
    +   * except when the left operator type is NullType. In case when left hand
    +   * operator type is NullType create a Literal(Null).
        */
       object InConversion extends Rule[LogicalPlan] {
         def apply(plan: LogicalPlan): LogicalPlan = plan resolveExpressions {
           // Skip nodes who's children have not been resolved yet.
           case e if !e.childrenResolved => e
     
    +      case i @ In(a, b) if (a.dataType == NullType) =>
    +        var inTypes : Seq[DataType] = Seq.empty
    +        b.foreach(e => inTypes = inTypes ++ Seq(e.dataType))
    +        findWiderCommonType(inTypes) match {
    +          case Some(finalDataType) => Literal.create(null, BooleanType)
    +          case None => i
    +        }
    --- End diff --
    
    instead of returning literal null, I think we should just wider the types, 
as it does fix the bug(we can add a rule in `Optimizer` to return null for this 
case).
    
    the code can be:
    ```
    case i @ In(a, b) if b.exists(_.dataType != a.dataType) =>
      findWiderCommonType(i.children.map(_.dataType)) match {
        case Some(finalDataType) => i.withNewChildren(i.children.map(Cast(_, 
finalDataType)))
        case None => i
      }
    ```


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