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

    https://github.com/apache/spark/pull/13807#discussion_r67879774
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoder.scala
 ---
    @@ -110,16 +110,25 @@ object ExpressionEncoder {
     
         val cls = 
Utils.getContextOrSparkClassLoader.loadClass(s"scala.Tuple${encoders.size}")
     
    -    val serializer = encoders.map {
    -      case e if e.flat => e.serializer.head
    -      case other => CreateStruct(other.serializer)
    -    }.zipWithIndex.map { case (expr, index) =>
    -      expr.transformUp {
    -        case BoundReference(0, t, _) =>
    -          Invoke(
    -            BoundReference(0, ObjectType(cls), nullable = true),
    -            s"_${index + 1}",
    -            t)
    +    val serializer = encoders.zipWithIndex.map { case (enc, index) =>
    +      val originalInputObject = enc.serializer.head.collect { case b: 
BoundReference => b }.head
    +      val newInputObject = Invoke(
    +        BoundReference(0, ObjectType(cls), nullable = true),
    +        s"_${index + 1}",
    +        originalInputObject.dataType)
    +
    +      val newSerializer = enc.serializer.map(_.transformUp {
    +        case b: BoundReference if b == originalInputObject => 
newInputObject
    +      })
    +
    +      if (enc.flat) {
    +        newSerializer.head
    +      } else {
    +        val struct = CreateStruct(newSerializer)
    +        val nullCheck = Or(
    +          IsNull(newInputObject),
    +          Invoke(Literal.fromObject(None), "equals", BooleanType, 
newInputObject :: Nil))
    +        If(nullCheck, Literal.create(null, struct.dataType), struct)
    --- End diff --
    
    This part is quite tricky, let's add comment here to explain why we need to 
substitute the input object and add the extra null check.


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