Skip to content
  • hyukjinkwon's avatar
    01dd0083
    [SPARK-17764][SQL] Add `to_json` supporting to convert nested struct column to JSON string · 01dd0083
    hyukjinkwon authored
    ## What changes were proposed in this pull request?
    
    This PR proposes to add `to_json` function in contrast with `from_json` in Scala, Java and Python.
    
    It'd be useful if we can convert a same column from/to json. Also, some datasources do not support nested types. If we are forced to save a dataframe into those data sources, we might be able to work around by this function.
    
    The usage is as below:
    
    ``` scala
    val df = Seq(Tuple1(Tuple1(1))).toDF("a")
    df.select(to_json($"a").as("json")).show()
    ```
    
    ``` bash
    +--------+
    |    json|
    +--------+
    |{"_1":1}|
    +--------+
    ```
    ## How was this patch tested?
    
    Unit tests in `JsonFunctionsSuite` and `JsonExpressionsSuite`.
    
    Author: hyukjinkwon <gurwls223@gmail.com>
    
    Closes #15354 from HyukjinKwon/SPARK-17764.
    01dd0083
    [SPARK-17764][SQL] Add `to_json` supporting to convert nested struct column to JSON string
    hyukjinkwon authored
    ## What changes were proposed in this pull request?
    
    This PR proposes to add `to_json` function in contrast with `from_json` in Scala, Java and Python.
    
    It'd be useful if we can convert a same column from/to json. Also, some datasources do not support nested types. If we are forced to save a dataframe into those data sources, we might be able to work around by this function.
    
    The usage is as below:
    
    ``` scala
    val df = Seq(Tuple1(Tuple1(1))).toDF("a")
    df.select(to_json($"a").as("json")).show()
    ```
    
    ``` bash
    +--------+
    |    json|
    +--------+
    |{"_1":1}|
    +--------+
    ```
    ## How was this patch tested?
    
    Unit tests in `JsonFunctionsSuite` and `JsonExpressionsSuite`.
    
    Author: hyukjinkwon <gurwls223@gmail.com>
    
    Closes #15354 from HyukjinKwon/SPARK-17764.
Loading