stczwd opened a new pull request #26098: Add configuration to support 
JacksonGenrator to keep fields with null values
URL: https://github.com/apache/spark/pull/26098
 
 
   ### Why are the changes needed?
   As mentioned in jira, sometimes we need to be able to support the retention 
of null columns when writing JSON. 
   For example, sparkmagic(used widely in jupyter with livy) will generate sql 
query results based on DataSet.toJSON and parse JSON to pandas DataFrame to 
display. If there is a null column, it is easy to have some column missing or 
even the query result is empty. The loss of the null column in the first row, 
may cause parsing exceptions or loss of entire column data.
   
   ### Does this PR introduce any user-facing change?
   Example in spark-shell.
   scala> spark.sql("select null as a, 1 as b").toJSON.collect.foreach(println)
   {"b":1}                                                                      
   
   
   scala> spark.sql("set spark.sql.jsonGenerator.struct.ignore.null=false")
   res2: org.apache.spark.sql.DataFrame = [key: string, value: string]
   
   scala> spark.sql("select null as a, 1 as b").toJSON.collect.foreach(println)
   {"a":null,"b":1}
   
   ### How was this patch tested?
   Add new test to JacksonGeneratorSuite

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to