#24259·cudf

[BUG] ORC timestamps near the Unix epoch are one second off for non-UTC writers with ignore_timezone_in_stripe_footer

Author: igorpeshanskyCreated Sep 22, 2026Updated Sep 22, 2026
Labelsbuglibcudf

TL;DR: With ignore_timezone_in_stripe_footer set, the ORC reader decides the negative-timestamp borrow in UTC instead of the writer's timezone. So timestamps that straddle 0 (with a nanos field value of at least 1ms) are off by 1s.

In decode_column_data_kernel in stripe_data.cu, tz_epoch is used as the base for epoch-relative values (in :2038), which means it must be in the writer's timezone. In particular, the negative timestamp borrow at :2052 must unconditionally happen in the writer's timezone, because the writer's base offset can move a timestamp value across the epoch start. That kernel uses the tz_table parameter to both compute the base epoch (in :1701) and adjust each time value into the desired timezone (in :2056). However, when ignore_timezone_in_stripe_footer is in effect, an empty tz_table is passed in, which means that the kernel loses the writer's timezone, and computes tz_epoch in UTC. So the borrow is decided in the wrong timezone (UTC instead of the writer's), and may get erroneously applied (for negative writer offsets) or skipped (for positive ones).

cudf-spark-jni compensates in apply_orc_base_offset by inferring whether cuDF applied a borrow, undoing it, applying the writer's 2015 offset, and then redoing the borrow in Apache's frame. https://github.com/NVIDIA/cudf-spark-jni/pull/5171 is routing more paths through the workaround, which is how it came to my attention.

Specific example (from https://github.com/NVIDIA/cudf-spark-jni/pull/5171):

In the Asia/Shanghai timezone: cuDF decodes 21'087'883'873 µs against the UTC epoch and applies no borrow; the writer offset at the 2015 epoch is +28'800'000'000 µs, so in the writer's frame the value is -7'712'116'127 µs, which is negative and therefore should borrow, giving -7'713'116'127.

The negative timestamp borrow is an encoding artifact whose correctness depends on computing it in the writer's timezone. So one fix would be to compute an orc_base_epoch in the caller (where the writer's timezone offset is available) and pass it into the kernel as a separate parameter. The caller already reads selected_stripes[0].stripe_footer->writerTimezone (in reader_impl_chunking.cu:257), and, once #23449 adds get_ut_offset, its value could be computed in the same way as cudf::io::orc::detail::writer_timezone::compute_base_epoch (orc_utc_epoch - get_ut_offset(std::nullopt, writerTimezone, timestamp_s{duration_s{orc_utc_epoch}})), or even potentially expose and reuse the cudf::io::orc::detail::writer_timezone implementation.

Fixing it in cuDF would let cudf-spark-jni drop the apply_orc_base_offset workaround and the writer_2015_year_base_offset_us parameter that is propagated through multiple calls, as well as the Java-side computation feeding it.

Originally posted by @igorpeshansky in https://github.com/NVIDIA/cudf/pull/23449#discussion_r4068622560