spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloud-fan <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-12478][SQL] Bugfix: Dataset fields of p...
Date Tue, 22 Dec 2015 12:25:14 GMT
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message