dongjoon-hyun opened a new pull request, #565:
URL: https://github.com/apache/spark-connect-swift/pull/565

   ### What changes were proposed in this pull request?
   
   This PR aims to make `DataFrame.toJSON()` return a single column named 
`value`, like the Scala Spark Connect client.
   
   ```swift
   -    return selectExpr("to_json(struct(*))")
   +    return selectExpr("to_json(struct(*)) AS value")
   ```
   
   ### Why are the changes needed?
   
   The Scala Spark Connect client names the `toJSON` output column `value`.
   
   - [Apache Spark 4.2.0 (2026-07-11) 
`Dataset.toJSON`](https://github.com/apache/spark/blob/v4.2.0/sql/connect/common/src/main/scala/org/apache/spark/sql/connect/Dataset.scala#L1277-L1279)
   
   ```scala
   def toJSON: Dataset[String] = {
     select(to_json(struct(col("*"))).as("value")).as(StringEncoder)
   }
   ```
   
   The Swift client currently names the column after the expression, such as 
`to_json(struct(id))`. So the column name depends on the input schema, and code 
ported from Scala that refers to `value` fails.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The output column is renamed from `to_json(struct(...))` to `value`, 
matching the Scala Spark Connect client. The JSON content is unchanged.
   
   **BEFORE**
   
   ```swift
   try await spark.range(2).toJSON().columns  // ["to_json(struct(id))"]
   ```
   
   **AFTER**
   
   ```swift
   try await spark.range(2).toJSON().columns  // ["value"]
   try await spark.range(2).toJSON().schema   // value STRING (nullable)
   ```
   
   ### How was this patch tested?
   
   Pass the CIs with the updated test case. It checks the column name, the 
schema (`value STRING`, nullable), unchanged JSON content, a multi-column 
DataFrame, and a nested struct column.
   
   I also tested manually with an Apache Spark 4.2.0 Spark Connect server.
   
   ```
   $ swift test --no-parallel --filter DataFrameTests
   ...
   Test run with 152 tests in 2 suites passed after 22.965 seconds.
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to