You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "dongjoon-hyun (via GitHub)" <gi...@apache.org> on 2026/09/13 03:52:30 UTC

[PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

dongjoon-hyun opened a new pull request, #194:
URL: https://github.com/apache/arrow-swift/pull/194

   ## What's Changed
   
   Arrow `Date32` and `Date64` values are signed integers (days and milliseconds since the UNIX epoch), but `Date32Array` and `Date64Array` read them as `UInt32` and `UInt64`.
   
   - `Date32Array`: a negative day such as `-1` (`1969-12-31`) is read as `4294967295`, and `UInt32 * 86400` traps with `Swift runtime failure: arithmetic overflow`. Only days in `0...49710` (`1970-01-01` to `2106-02-07`) can be read. Any date before `1970-01-01` or after `2106-02-07` crashes the process, in both debug and release builds.
   - `Date64Array`: a negative millisecond value wraps around to a huge positive value, so `1969-12-31` is read as about `1.8e16` seconds after the epoch.
   - `Date32BufferBuilder`: `Int32(seconds / 86400)` truncates toward zero, so a pre-epoch `Date` that is not at UTC midnight is stored one day later. For example, `1969-12-31T12:00:00Z` becomes `1970-01-01`.
   
   This PR:
   
   - loads `Int32` in `Date32Array` and multiplies in `TimeInterval`. Loading `Int32` alone is not enough because `Int32 * 86400` overflows for dates after `2038-01-19`.
   - loads `Int64` in `Date64Array`.
   - uses `.rounded(.down)` in `Date32BufferBuilder`, so pre-epoch values are floored to their day just like post-epoch values.
   
   This was found in the Apache Spark Connect Swift client, which vendors these sources: collecting `DATE'1969-12-31'` crashed the client.
   
   ## Testing
   
   Added three regression tests to `ArrayTests`:
   
   - `testDate32ArrayOutsideUnsignedRange` checks both the stored `Int32` day and the decoded `Date` for `0001-01-01`, `1969-12-31`, `1970-01-01`, `2038-01-20`, `2106-02-07`, `2106-02-08`, and `9999-12-31`.
   - `testDate32BuilderPreEpochTimeOfDay` checks that pre-epoch times of day are floored to their day.
   - `testDate64ArrayPreEpoch` checks `0001-01-01` and `1969-12-31`.
   
   Without this fix, `testDate32ArrayOutsideUnsignedRange` crashes with signal 5, and the other two tests fail. With this fix, the full test suite passes (52 tests, 0 failures).
   
   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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #194:
URL: https://github.com/apache/arrow-swift/pull/194#discussion_r4003822192


##########
Sources/Arrow/ArrowArray.swift:
##########
@@ -229,7 +229,7 @@ public class Date64Array: ArrowArray<Date> {
         }
 
         let byteOffset = self.arrowData.stride * Int(index)
-        let milliseconds = self.arrowData.buffers[1].rawPointer.advanced(by: byteOffset).load(as: UInt64.self)
+        let milliseconds = self.arrowData.buffers[1].rawPointer.advanced(by: byteOffset).load(as: Int64.self)
         return Date(timeIntervalSince1970: TimeInterval(milliseconds / 1000))

Review Comment:
   Should we change this to `TimeInterval(milliseconds) / 1000` in this PR?
   
   
   ```suggestion
           return Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #194:
URL: https://github.com/apache/arrow-swift/pull/194


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #194:
URL: https://github.com/apache/arrow-swift/pull/194#issuecomment-5666797506

   Thank you, @kou !


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #194:
URL: https://github.com/apache/arrow-swift/pull/194#issuecomment-5706920060

   Merged. Thanks.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #194:
URL: https://github.com/apache/arrow-swift/pull/194#issuecomment-5651274562

   For the record, this is an upstream contribution from the following Apache Spark patch.
   - https://github.com/apache/spark-connect-swift/pull/555


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #194:
URL: https://github.com/apache/arrow-swift/pull/194#issuecomment-5661860118

   @willtemperley @maltzsama Do you want to review this?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Support pre-epoch dates in `Date32` and `Date64` arrays [arrow-swift]

Posted by "maltzsama (via GitHub)" <gi...@apache.org>.
maltzsama commented on PR #194:
URL: https://github.com/apache/arrow-swift/pull/194#issuecomment-5706823846

   @kou I check that. All good


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org