dongjoon-hyun opened a new pull request, #553:
URL: https://github.com/apache/spark-connect-swift/pull/553
### What changes were proposed in this pull request?
This PR aims to throw `ArrowError.invalid` instead of crashing in
`DataFrame.collect(as:)` when a value cannot be decoded into the target Swift
type. It also allows Scala-style safe numeric upcasts (a narrower signed
integer into a wider one, and `Float` into `Double`).
```swift
// Upcast: INT -> Int64
try await spark.sql("SELECT 30 AS age").collect(as: Int64.self)
// Throws ArrowError.invalid("Cannot decode Int32 for column 0")
try await spark.sql("SELECT 30L AS age").collect(as: Int32.self)
```
### Why are the changes needed?
`ArrowDecoder` force-unwraps decoded values and converts signed values with
`UInt(val)`. As a result, a type mismatch, a `NULL` value, or a negative value
into `UInt` crashes the whole process.
```swift
spark.sql("SELECT CAST(NULL AS STRING) AS name, 1L AS age").collect(as:
Person.self)
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
```
### Does this PR introduce _any_ user-facing change?
No for the released versions because `DataFrame.collect(as:)` exists only in
the `main` branch.
### How was this patch tested?
Pass the CIs with the newly added test cases.
### 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]