GitHub user gatorsmile opened a pull request:

    https://github.com/apache/spark/pull/16745

    [SPARK-19406] [SQL] Fix function to_json to respect user-provided options

    ### What changes were proposed in this pull request?
    Currently, the function `to_json` allows users to provide options for 
generating JSON. However, it does not pass it to `JacksonGenerator`. Thus, it 
ignores the user-provided options. This PR is to fix it. Below is an example.
    
    ```Scala
    val df = Seq(Tuple1(Tuple1(java.sql.Timestamp.valueOf("2015-08-26 
18:00:00.0")))).toDF("a")
    val options = Map("timestampFormat" -> "dd/MM/yyyy HH:mm")
    df.select(to_json($"a", options)).show(false)
    ```
    The current output is like
    ```
    +--------------------------------------+
    |structtojson(a)                       |
    +--------------------------------------+
    |{"_1":"2015-08-26T18:00:00.000-07:00"}|
    +--------------------------------------+
    ```
    
    After the fix, the output is like
    ```
    +-------------------------+
    |structtojson(a)          |
    +-------------------------+
    |{"_1":"26/08/2015 18:00"}|
    +-------------------------+
    ```
    ### How was this patch tested?
    Added test cases for both `from_json` and `to_json`

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/gatorsmile/spark toJson

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/16745.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #16745
    
----
commit 99756eb3b19fe430a8981acdd6fb92a7e990f514
Author: gatorsmile <[email protected]>
Date:   2017-01-30T21:38:59Z

    fix.

----


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