This is an automated email from the ASF dual-hosted git repository.

gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new eb2eb9e  [SPARK-37550][SQL][DOCS] Add an example of parsing jsonStr 
with complex types for from_json
eb2eb9e is described below

commit eb2eb9e1a41a0d040b5038521a7acc14617b0790
Author: Brian Yue <code.by...@gmail.com>
AuthorDate: Mon Dec 6 14:48:35 2021 +0900

    [SPARK-37550][SQL][DOCS] Add an example of parsing jsonStr with complex 
types for from_json
    
    ### What changes were proposed in this pull request?
    
    Adding an additional example to demonstrate how to parse jsonStr with 
nested types including ArrayType and StructType.
    
    ### Why are the changes needed?
    
    The documentation for from_json currently contains only examples of getting 
struct value from jsonStr with simple schema. It can take a lot of time to 
figure out how to parse jsonStr with complex types, especially for beginners. 
This change can make the documentation more intuitive.
    
    ### Does this PR introduce _any_ user-facing change?
    
    It will enrich the documentation of Spark SQL, Built-in Functions.
    
    ### How was this patch tested?
    
    The added example shows the real query result.
    
    Closes #34809 from byyue/dev-37550.
    
    Authored-by: Brian Yue <code.by...@gmail.com>
    Signed-off-by: Hyukjin Kwon <gurwls...@apache.org>
---
 .../org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala     | 2 ++
 1 file changed, 2 insertions(+)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
index 78e7e53..cbe8694 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
@@ -524,6 +524,8 @@ case class JsonTuple(children: Seq[Expression])
        {"a":1,"b":0.8}
       > SELECT _FUNC_('{"time":"26/08/2015"}', 'time Timestamp', 
map('timestampFormat', 'dd/MM/yyyy'));
        {"time":2015-08-26 00:00:00}
+      > SELECT _FUNC_('{"teacher": "Alice", "student": [{"name": "Bob", 
"rank": 1}, {"name": "Charlie", "rank": 2}]}', 'STRUCT<teacher: STRING, 
student: ARRAY<STRUCT<name: STRING, rank: INT>>>');
+       
{"teacher":"Alice","student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}
   """,
   group = "json_funcs",
   since = "2.2.0")

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to