Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26187 +/- ##
==========================================
+ Coverage 82.77% 82.79% +0.01%
==========================================
Files 1148 1150 +2
Lines 451075 452027 +952
Branches 451075 452027 +952
==========================================
+ Hits 373397 374274 +877
- Misses 54930 54933 +3
- Partials 22748 22820 +72 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Which issue does this PR close?
Rationale for this change
There is no way to serialize a struct, or a set of columns, into a JSON string column without
collect()-ing theDataFrameand rebuilding it. Spark hasto_json(struct)and Polars hasstruct.json_encode(). This PR adds a Spark-compatibleto_jsontodatafusion-sparkso the conversion stays a lazy projection and runs batch by batch.What changes are included in this PR?
datafusion/spark/src/function/json/to_json.rs:ToJsonscalar UDF (Struct -> Utf8). Serializes each batch with thearrow-jsonrow encoder; NULL fields are omitted (SparkignoreNullFieldsdefault), a NULL struct yields NULL, nested structs/lists are handled recursively. Non-struct input is rejected at plan time.IntoJsonStructtrait +expr_fn::to_json(input): accepts either a structExpror a list of column names, which are packed withnamed_structkeyed by their unqualified names. The result is a plainExpr, sowith_columnneeds no changes.datafusion/spark/src/function/json/mod.rs: registration (functions(), expr_fn).datafusion/core/Cargo.toml:datafusion-sparkas adev-dependencyfor theDataFrametests.What is the testing strategy for this PR?
to_json.rs(array/scalar input, nulls, nested types, escaping, invalid input, name packing incl. qualified names).datafusion/core/tests/dataframe/mod.rs:with_column_to_json(add, overwrite, col(..) on a struct column, SQL equivalence, plan-time rejection) andwith_column_to_json_edge_cases(null handling, constant input, nested struct + list, escaping/UTF-8, qualified names, empty input, empty column list).Are there any user-facing changes?
Yes: new
to_jsonfunction indatafusion-spark(SQL via with_spark_features() / register_udf,DataFrameviadatafusion_spark::expr_fn::to_json). No changes to existing APIs.