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

    https://github.com/apache/spark/pull/3213#discussion_r20406534
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala ---
    @@ -131,6 +134,69 @@ class SchemaRDD(
        */
       lazy val schema: StructType = queryExecution.analyzed.schema
     
    +  /** Transforms a single Row to JSON using Jackson
    +    *
    +    * @param jsonFactory a JsonFactory object to construct a JsonGenerator
    +    * @param rowSchema the schema object used for conversion
    +    * @param row The row to convert
    +    */
    +  private def rowToJSON(rowSchema: StructType, jsonFactory: 
JsonFactory)(row: Row): String = {
    +    val writer = new StringWriter()
    +    val gen = jsonFactory.createGenerator(writer)
    +
    +    def valWriter: (DataType, Any) => Unit = {
    +      case(_, null)  => //do nothing
    +      case(StringType, v: String) => gen.writeString(v)
    +      case(TimestampType, v: java.sql.Timestamp) => 
gen.writeString(v.toString)
    +      case(IntegerType, v: Int) => gen.writeNumber(v)
    +      case(ShortType, v: Short) => gen.writeNumber(v)
    +      case(FloatType, v: Float) => gen.writeNumber(v)
    +      case(DoubleType, v: Double) => gen.writeNumber(v)
    +      case(LongType, v: Long) => gen.writeNumber(v)
    +      case(DecimalType(), v: java.math.BigDecimal) => gen.writeNumber(v)
    +      case(ByteType, v: Byte) => gen.writeNumber(v.toInt)
    +      case(BinaryType, v: Array[Byte]) => gen.writeBinary(v)
    +      case(BooleanType, v: Boolean) => gen.writeBoolean(v)
    +
    +      case(ArrayType(ty, _), v: Seq[_] ) =>
    +         gen.writeStartArray()
    +         v.foreach(valWriter(ty,_))
    --- End diff --
    
    I think we need to keep `null`s in an array. Otherwise, the information 
carried by the array will be changed.


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