Skip to content

Commit 4de0898

Browse files
authored
feat: clamp ts before convert to Zoned. (#721)
1 parent d3070e9 commit 4de0898

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

sql/src/value/arrow_decoder.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ const MICROS_MASK: i128 = 0xFFFFFFFFFFFFFFFF;
4545
/// Mask for extracting the middle 32 bits (days or months).
4646
const DAYS_MONTHS_MASK: i128 = 0xFFFFFFFF;
4747

48+
// 9999-12-30T22:00:00.999999Z
49+
const TIMESTAMP_MAX: i64 = 253402207200999999;
50+
// -009999-01-02T01:59:59Z
51+
const TIMESTAMP_MIN: i64 = -377705023201000000;
52+
53+
// required by jiff
54+
fn clamp_ts(ts: i64) -> i64 {
55+
ts.clamp(TIMESTAMP_MIN, TIMESTAMP_MAX)
56+
}
57+
4858
impl months_days_micros {
4959
#[inline]
5060
pub fn months(&self) -> i32 {
@@ -101,7 +111,7 @@ impl
101111
match array.as_any().downcast_ref::<Decimal128Array>() {
102112
Some(array) => {
103113
let v = array.value(seq);
104-
let unix_ts = v as u64 as i64;
114+
let unix_ts = clamp_ts(v as u64 as i64);
105115
let offset = (v >> 64) as i32;
106116
let offset = tz::Offset::from_seconds(offset).map_err(|e| {
107117
Error::Parsing(format!("invalid offset: {offset}, {e}"))
@@ -343,7 +353,7 @@ impl
343353
))
344354
.into());
345355
}
346-
let ts = array.value(seq);
356+
let ts = clamp_ts(array.value(seq));
347357
match tz {
348358
None => {
349359
let timestamp = Timestamp::from_microsecond(ts).map_err(|e| {

0 commit comments

Comments
 (0)