Skip to content

[SPARK-51152][PYTHON][SQL][DOCS] Add usage examples for the get_json_object function#49875

Closed
fusheng9399 wants to merge 15 commits intoapache:masterfrom
fusheng9399:add-json-example
Closed

[SPARK-51152][PYTHON][SQL][DOCS] Add usage examples for the get_json_object function#49875
fusheng9399 wants to merge 15 commits intoapache:masterfrom
fusheng9399:add-json-example

Conversation

@fusheng9399
Copy link
Copy Markdown

@fusheng9399 fusheng9399 commented Feb 11, 2025

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 JSON is an array, some users may not know how to retrieve its data through get_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_object to obtain JSON data of type array through examples.

How was this patch tested?

  • Pass GA
  • Manually Test.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Feb 11, 2025
@fusheng9399 fusheng9399 changed the title Add an example for get_json_object when the JSON object is of JSON array type [SPARK-51152][SQL]Add an example for get_json_object when the JSON object is of JSON array type Feb 11, 2025
@fusheng9399
Copy link
Copy Markdown
Author

Please help review it when you have free time, thanks! @panbingkun

@panbingkun
Copy link
Copy Markdown
Contributor

Are there any other examples of wide characters that need to be shown?
Additionally, the PySpark example also needs to be updated.

@fusheng9399
Copy link
Copy Markdown
Author

fusheng9399 commented Feb 11, 2025

No, I have added a more comprehensive example. The PySpark example has been updated.

@fusheng9399 fusheng9399 changed the title [SPARK-51152][SQL]Add an example for get_json_object when the JSON object is of JSON array type [SPARK-51152][SQL]Add a more intuitive example for get_json_object Feb 12, 2025
@fusheng9399 fusheng9399 changed the title [SPARK-51152][SQL]Add a more intuitive example for get_json_object [SPARK-51152][SQL] Add richer examples for the get_json_object function Feb 12, 2025
@fusheng9399 fusheng9399 changed the title [SPARK-51152][SQL] Add richer examples for the get_json_object function [SPARK-51152][Python][SQL] Add richer examples for the get_json_object function Feb 14, 2025
@fusheng9399 fusheng9399 changed the title [SPARK-51152][Python][SQL] Add richer examples for the get_json_object function [SPARK-51152][Python][SQL] Add usage examples for the get_json_object function Feb 14, 2025
@zhengruifeng zhengruifeng changed the title [SPARK-51152][Python][SQL] Add usage examples for the get_json_object function [SPARK-51152][PYTHON][SQL][DOCS] Add usage examples for the get_json_object function Feb 17, 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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use show(), and shows both the input column and output column

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done~

@panbingkun
Copy link
Copy Markdown
Contributor

Welcome to the Apache Spark community, @fusheng9399 !
I added you to the Apache Spark contributor group and assigned SPARK-51152 to you.

@panbingkun
Copy link
Copy Markdown
Contributor

Thanks for the review @HyukjinKwon @zhengruifeng.
Merging to master!

@fusheng9399
Copy link
Copy Markdown
Author

Thanks all @panbingkun @HyukjinKwon @zhengruifeng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants