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

    https://github.com/apache/spark/pull/10431#discussion_r48248538
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala 
---
    @@ -467,13 +467,16 @@ object ScalaReflection extends ScalaReflection {
             case t if t <:< localTypeOf[Product] =>
               val params = getConstructorParameters(t)
     
    -          CreateNamedStruct(params.flatMap { case (fieldName, fieldType) =>
    -            val fieldValue = Invoke(inputObject, fieldName, 
dataTypeFor(fieldType))
    -            val clsName = getClassNameFromType(fieldType)
    -            val newPath = s"""- field (class: "$clsName", name: 
"$fieldName")""" +: walkedTypePath
    -
    -            expressions.Literal(fieldName) :: extractorFor(fieldValue, 
fieldType, newPath) :: Nil
    -          })
    +          expressions.If(
    +            IsNull(inputObject),
    +            expressions.Literal.create(null, silentSchemaFor(t).dataType),
    +            CreateNamedStruct(params.flatMap { case (fieldName, fieldType) 
=>
    +              val fieldValue = Invoke(inputObject, fieldName, 
dataTypeFor(fieldType))
    +              val clsName = getClassNameFromType(fieldType)
    +              val newPath = s"""- field (class: "$clsName", name: 
"$fieldName")""" +: walkedTypePath
    +              expressions.Literal(fieldName) :: extractorFor(fieldValue, 
fieldType, newPath) :: Nil
    +            })
    +          )
    --- End diff --
    
    nit: we can split this into 2 parts
    ```
    val row = CreateNamedStruct(...)
    expression.If(
      IsNull...
      expression.Literal.create(null, row.dataType),
      row
    )
    ```
    which looks arguably more clear.


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