From e597d8bff11fb51a0a7f3aa3240d7d5131faef3d Mon Sep 17 00:00:00 2001 From: Vedaant Jain Date: Thu, 5 Nov 2026 18:17:54 +0000 Subject: [PATCH 1/3] Read integer %Y%m%d times without formatting them as text An integer time column declared with timestamp_format "%Y%m%d" was formatted as a string and parsed by chrono for every row. Eight-digit values that form a valid date now go straight to the date; everything else takes the existing text parse, so results are unchanged. Co-Authored-By: Claude Opus 5.5 --- .../diskgraph/diskgraph-rowpack/src/access.rs | 3 +++ .../diskgraph/diskgraph-rowpack/src/parser.rs | 16 ++++++++++++ .../diskgraph-rowpack/src/tests_unit.rs | 25 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/packages/diskgraph/diskgraph-rowpack/src/access.rs b/packages/diskgraph/diskgraph-rowpack/src/access.rs index 8c5f65a48..4cfa3260d 100644 --- a/packages/diskgraph/diskgraph-rowpack/src/access.rs +++ b/packages/diskgraph/diskgraph-rowpack/src/access.rs @@ -2700,6 +2700,9 @@ impl<'p> RowAccess<'p> { // a string and parse with the format. This handles date-encoded // integers like YYYYMMDD (20240301) that are NOT epoch values. if let Some(fmt) = format { + if let Some(secs) = fast.and_then(|parser| parser.parse_compact_ymd_int(value)) { + return Ok(Some(in_clock(floor_parts::(secs, || 0))?)); + } let text = value.to_string(); if let Some((secs, nanos)) = parse_timestamp_text_parts(&text, Some(fmt)) { return Ok(Some(in_clock(floor_parts::(secs, || nanos))?)); diff --git a/packages/diskgraph/diskgraph-rowpack/src/parser.rs b/packages/diskgraph/diskgraph-rowpack/src/parser.rs index 46a21eb81..94ff70b2c 100644 --- a/packages/diskgraph/diskgraph-rowpack/src/parser.rs +++ b/packages/diskgraph/diskgraph-rowpack/src/parser.rs @@ -412,6 +412,22 @@ impl TimestampFormatParser { } } + /// Epoch seconds of an eight-digit integer that `%Y%m%d` reads as a valid + /// date, without formatting it as text. + pub(crate) fn parse_compact_ymd_int(&self, value: i64) -> Option { + if !matches!(self.kind, TimestampFormatKind::CompactYmd) + || !(10_000_000..=99_999_999).contains(&value) + { + return None; + } + let date = NaiveDate::from_ymd_opt( + (value / 10_000) as i32, + (value / 100 % 100) as u32, + (value % 100) as u32, + )?; + Some(date.and_hms_opt(0, 0, 0)?.and_utc().timestamp()) + } + pub(crate) fn parse_date(&self, value: &str) -> Option { let secs = self.parse_timestamp(value)?; Some(days_from_secs(secs)) diff --git a/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs b/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs index 2af4287c2..e28f844ce 100644 --- a/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs +++ b/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs @@ -1832,6 +1832,31 @@ fn int32_yyyymmdd_format_takes_priority_over_unit() { assert_eq!(secs, expected); } +#[test] +fn integer_yyyymmdd_matches_text_parse() { + let mut values = vec![i64::MIN, -20240301, 0, 2024031, 9_999_999, 100_000_000, i64::MAX]; + for year in [1000, 1969, 2000, 2023, 2024, 9999] { + for month in 0..=13 { + for day in 0..=32 { + values.push(year * 10_000 + month * 100 + day); + } + } + } + for value in values { + let array = || Arc::new(arrow_array::Int64Array::from(vec![value])) as ArrayRef; + let expected = match parse_timestamp_text(&value.to_string(), Some("%Y%m%d")) { + Some(secs) => Ok(Some(secs)), + None => get_timestamp_from_array(array(), None, None), + }; + let actual = get_timestamp_from_array(array(), Some("%Y%m%d"), None); + assert_eq!( + actual.map_err(|error| error.to_string()), + expected.map_err(|error| error.to_string()), + "{value}" + ); + } +} + // ---- detect_encoded_int_format tests ---- #[test] From 7a0994f181c157ea956d634f19507db5263509b1 Mon Sep 17 00:00:00 2001 From: Vedaant Jain Date: Thu, 5 Nov 2026 18:20:30 +0000 Subject: [PATCH 2/3] Format the integer %Y%m%d fast path and its test Co-Authored-By: Claude Opus 5.5 --- packages/diskgraph/diskgraph-rowpack/src/access.rs | 4 +++- packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/diskgraph/diskgraph-rowpack/src/access.rs b/packages/diskgraph/diskgraph-rowpack/src/access.rs index 4cfa3260d..1add9c227 100644 --- a/packages/diskgraph/diskgraph-rowpack/src/access.rs +++ b/packages/diskgraph/diskgraph-rowpack/src/access.rs @@ -2699,8 +2699,10 @@ impl<'p> RowAccess<'p> { // If a format hint is set (e.g., "%Y%m%d"), convert the integer to // a string and parse with the format. This handles date-encoded // integers like YYYYMMDD (20240301) that are NOT epoch values. + // Eight-digit "%Y%m%d" values skip the text round-trip. if let Some(fmt) = format { - if let Some(secs) = fast.and_then(|parser| parser.parse_compact_ymd_int(value)) { + if let Some(secs) = fast.and_then(|parser| parser.parse_compact_ymd_int(value)) + { return Ok(Some(in_clock(floor_parts::(secs, || 0))?)); } let text = value.to_string(); diff --git a/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs b/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs index e28f844ce..63d35b122 100644 --- a/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs +++ b/packages/diskgraph/diskgraph-rowpack/src/tests_unit.rs @@ -1834,7 +1834,15 @@ fn int32_yyyymmdd_format_takes_priority_over_unit() { #[test] fn integer_yyyymmdd_matches_text_parse() { - let mut values = vec![i64::MIN, -20240301, 0, 2024031, 9_999_999, 100_000_000, i64::MAX]; + let mut values = vec![ + i64::MIN, + -20240301, + 0, + 2024031, + 9_999_999, + 100_000_000, + i64::MAX, + ]; for year in [1000, 1969, 2000, 2023, 2024, 9999] { for month in 0..=13 { for day in 0..=32 { From 9ec4b54302ab18e917c31b7ec37090c0bc07bbcb Mon Sep 17 00:00:00 2001 From: Vedaant Jain Date: Thu, 5 Nov 2026 18:26:58 +0000 Subject: [PATCH 3/3] Say only valid eight-digit dates skip the text parse Co-Authored-By: Claude Opus 5.5 --- packages/diskgraph/diskgraph-rowpack/src/access.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/diskgraph/diskgraph-rowpack/src/access.rs b/packages/diskgraph/diskgraph-rowpack/src/access.rs index 1add9c227..f823e6c0d 100644 --- a/packages/diskgraph/diskgraph-rowpack/src/access.rs +++ b/packages/diskgraph/diskgraph-rowpack/src/access.rs @@ -2699,7 +2699,7 @@ impl<'p> RowAccess<'p> { // If a format hint is set (e.g., "%Y%m%d"), convert the integer to // a string and parse with the format. This handles date-encoded // integers like YYYYMMDD (20240301) that are NOT epoch values. - // Eight-digit "%Y%m%d" values skip the text round-trip. + // Valid eight-digit "%Y%m%d" dates skip the text round-trip. if let Some(fmt) = format { if let Some(secs) = fast.and_then(|parser| parser.parse_compact_ymd_int(value)) {