Github user mn-mikke commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21687#discussion_r204340969
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
 ---
    @@ -695,6 +695,41 @@ abstract class TernaryExpression extends Expression {
       }
     }
     
    +/**
    + * A trait resolving nullable, containsNull, valueContainsNull flags of 
the output date type.
    + * This logic is usually utilized by expressions combining data from 
multiple child expressions
    + * of non-primitive types (e.g. [[CaseWhen]]).
    + */
    +trait ComplexTypeMergingExpression extends Expression {
    +
    +  /**
    +   * A collection of data types used for resolution the output type of the 
expression. By default,
    +   * data types of all child expressions. The collection must not be empty.
    +   */
    +  @transient
    +  lazy val inputTypesForMerging: Seq[DataType] = children.map(_.dataType)
    +
    +  /**
    +   * A method determining whether the input types are equal ignoring 
nullable, containsNull and
    +   * valueContainsNull flags and thus convenient for resolution of the 
final data type.
    +   */
    +  def areInputTypesForMergingEqual: Boolean = {
    +    inputTypesForMerging.length <= 1 || inputTypesForMerging.sliding(2, 
1).forall {
    +      case Seq(dt1, dt2) => dt1.sameType(dt2)
    +    }
    +  }
    +
    +  override def dataType: DataType = {
    +    require(
    +      inputTypesForMerging.nonEmpty,
    +      "The collection of input data types must not be empty.")
    +    require(
    +      areInputTypesForMergingEqual,
    +      "All input types must be the same except nullable, containsNull, 
valueContainsNull flags.")
    --- End diff --
    
    ```NullType``` is ```sameType``` equal only with itself. So it's up to 
coercion rules to cast ```NullType``` to a common type of other children. All 
the rules transitively utilize ```TypeCoercion.findTightestCommonType``` that 
does that job. (    ```case (NullType, t1) => Some(t1)```, ```case (t1, 
NullType) => Some(t1)```)
    
    If I don't miss anything, this behavior was the same before this PR. I can 
add more tests to cover this scenario if you wish. :-)


---

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

Reply via email to