[SPARK-51152][PYTHON][SQL][DOCS] Add usage examples for the get_json_object function#49875
Closed
fusheng9399 wants to merge 15 commits intoapache:masterfrom
Closed
[SPARK-51152][PYTHON][SQL][DOCS] Add usage examples for the get_json_object function#49875fusheng9399 wants to merge 15 commits intoapache:masterfrom
fusheng9399 wants to merge 15 commits intoapache:masterfrom
Conversation
Author
|
Please help review it when you have free time, thanks! @panbingkun |
Contributor
|
Are there any other examples of |
Author
|
No, I have added a more comprehensive example. The PySpark example has been updated. |
HyukjinKwon
reviewed
Feb 12, 2025
panbingkun
reviewed
Feb 12, 2025
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala
Show resolved
Hide resolved
panbingkun
reviewed
Feb 12, 2025
panbingkun
reviewed
Feb 12, 2025
| >>> data = [("1", '''{"f1": "value1", "f2": "value2"}'''), ("2", '''{"f1": "value12"}''')] | ||
| >>> df = spark.createDataFrame(data, ("key", "jstring")) | ||
| >>> df.select(df.key, get_json_object(df.jstring, '$.f1').alias("c0"), \\ | ||
| ... get_json_object(df.jstring, '$.f2').alias("c1") ).collect() |
Contributor
There was a problem hiding this comment.
let's use show(), and shows both the input column and output column
zhengruifeng
approved these changes
Feb 18, 2025
panbingkun
approved these changes
Feb 18, 2025
panbingkun
reviewed
Feb 18, 2025
added 2 commits
February 18, 2025 11:19
Contributor
|
Welcome to the Apache Spark community, @fusheng9399 ! |
Contributor
|
Thanks for the review @HyukjinKwon @zhengruifeng. |
Author
|
Thanks all @panbingkun @HyukjinKwon @zhengruifeng |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
The pr aims to add some usage examples for function
get_json_object, including:get_json_object('[{"a":"b"},{"a":"c"}]', '$[0].a'),get_json_object('[{"a":"b"},{"a":"c"}]', '$[*].a').Why are the changes needed?
When
JSONis anarray, some users may not know how to retrieve its data throughget_json_object.Let's add some usage examples.
Does this PR introduce any user-facing change?
Yes, Spark end-users will learn how to use
get_json_objectto obtain JSON data of type array through examples.How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
No.