dongjoon-hyun opened a new pull request, #588:
URL: https://github.com/apache/spark-connect-swift/pull/588
### What changes were proposed in this pull request?
This PR fixes two crashes in `Row`.
1. `Row.getAsTimestampNanos` converts a `Date` value by rounding to the
nearest microsecond and building `TimestampNanos(epochMicros:)`, instead of
computing `Int64` epoch nanoseconds. A `Date` that cannot be represented, such
as `infinity`, now throws `SparkConnectError.InvalidType`, like the other
type-safe getters.
2. `Row.==` compares integer values, and arrays of integer values, through
`Int128` instead of `Int64`.
### Why are the changes needed?
1. `DataFrame.collect()` returns `TIMESTAMP` and `TIMESTAMP_NTZ` columns as
`Date`. `Int64` epoch nanoseconds only cover the years 1677-2262, so
`getAsTimestampNanos` crashed on common sentinel values such as
`TIMESTAMP'0001-01-01'` or `TIMESTAMP'9999-12-31'`:
```
Fatal error: Double value cannot be converted to Int64 because the result
would be less than Int64.min
```
The old code also multiplied by `1_000_000_000` in `Double`, which added
rounding error and produced wrong sub-microsecond and even microsecond digits.
For example, `1_700_000_000.999999` became `999998` microseconds and `976`
nanoseconds. `Date` cannot hold nanosecond precision, and Spark `TIMESTAMP` has
microsecond precision, so rounding to the nearest microsecond gives the correct
value.
2. `Row(UInt64.max) == Row(UInt64.max)` crashed because `Int64(UInt64.max)`
traps:
```
Fatal error: Not enough bits to represent the passed value
```
### Does this PR introduce _any_ user-facing change?
Yes. These cases no longer crash. `getAsTimestampNanos` on a `Date` value
now returns a microsecond-precision `TimestampNanos` (`nanosWithinMicro == 0`).
### How was this patch tested?
Pass the CIs with the newly added test cases.
- `RowTests`: `getAsTimestampNanosOutOfInt64NanosRange`,
`getAsTimestampNanosRoundsDateToMicroseconds`, `compareUInt64`, `compareData`
- `DataFrameTests`: `collectTimestampAsTimestampNanos`, an end-to-end test
that collects `TIMESTAMP_NTZ'0001-01-01 00:00:00'`, `TIMESTAMP_NTZ'2026-01-01
00:00:00.999999'`, and `TIMESTAMP_NTZ'9999-12-31 00:00:00'`
I also ran the tests manually against an Apache Spark 4.2.0 Spark Connect
server.
```
$ swift test --no-parallel --filter 'RowTests|DataFrameTests'
...
Test run with 182 tests in 3 suites passed after 35.407 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]