From d5ad08c1e3cff24e970c972774072f7529301537 Mon Sep 17 00:00:00 2001 From: Vishal Kotak Date: Wed, 2 Dec 2026 10:56:20 +0000 Subject: [PATCH] fix: use local midnight as the default range ALIGN TO origin (#10795) Signed-off-by: Vishal Kotak Co-authored-by: dennis zhuang --- src/query/src/range_select/plan_rewrite.rs | 11 ++++++----- tests/cases/standalone/common/range/to.result | 18 ++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/query/src/range_select/plan_rewrite.rs b/src/query/src/range_select/plan_rewrite.rs index 27c84ce66ac..2948a71f2d2 100644 --- a/src/query/src/range_select/plan_rewrite.rs +++ b/src/query/src/range_select/plan_rewrite.rs @@ -260,8 +260,9 @@ fn parse_align_to( .map(|dt| dt.timestamp_millis()) .unwrap_or_else(|| Timestamp::current_millis().value())); } - // default align to unix epoch 0 (timezone aware) - "" => return Ok(timezone.map(|tz| tz.local_minus_utc() * 1000).unwrap_or(0)), + // default align to unix epoch 0 (timezone aware): 1970-01-01T00:00:00 in the session + // timezone, which is `-local_minus_utc` in UTC. + "" => return Ok(timezone.map(|tz| -tz.local_minus_utc() * 1000).unwrap_or(0)), _ => (), } @@ -1786,10 +1787,10 @@ mod test { // test default let args = vec!["".lit()]; assert_eq!(0, parse_align_to(&args, 0, None, None).unwrap()); - // test default with timezone + // test default with timezone: local midnight of 1970-01-01 in the session timezone let args = vec!["".lit()]; assert_eq!( - -36000 * 1000, + 36000 * 1000, parse_align_to( &args, 0, @@ -1799,7 +1800,7 @@ mod test { .unwrap() ); assert_eq!( - 28800 * 1000, + -28800 * 1000, parse_align_to( &args, 0, diff --git a/tests/cases/standalone/common/range/to.result b/tests/cases/standalone/common/range/to.result index 5a94fc2c52b..8d75d1d63cb 100644 --- a/tests/cases/standalone/common/range/to.result +++ b/tests/cases/standalone/common/range/to.result @@ -117,10 +117,10 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts; +---------------------+-------+------------------------+ | ts | host | min(host.val) RANGE 1d | +---------------------+-------+------------------------+ -| 2024-01-23T08:00:00 | host1 | 0 | -| 2024-01-24T08:00:00 | host1 | 2 | -| 2024-01-23T08:00:00 | host2 | 4 | -| 2024-01-24T08:00:00 | host2 | 6 | +| 2024-01-23T16:00:00 | host1 | 0 | +| 2024-01-24T16:00:00 | host1 | 2 | +| 2024-01-23T16:00:00 | host2 | 4 | +| 2024-01-24T16:00:00 | host2 | 6 | +---------------------+-------+------------------------+ set time_zone='+23:00'; @@ -133,12 +133,10 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts; +---------------------+-------+------------------------+ | ts | host | min(host.val) RANGE 1d | +---------------------+-------+------------------------+ -| 2024-01-22T23:00:00 | host1 | 0 | -| 2024-01-23T23:00:00 | host1 | 1 | -| 2024-01-24T23:00:00 | host1 | 3 | -| 2024-01-22T23:00:00 | host2 | 4 | -| 2024-01-23T23:00:00 | host2 | 5 | -| 2024-01-24T23:00:00 | host2 | 7 | +| 2024-01-23T01:00:00 | host1 | 0 | +| 2024-01-24T01:00:00 | host1 | 2 | +| 2024-01-23T01:00:00 | host2 | 4 | +| 2024-01-24T01:00:00 | host2 | 6 | +---------------------+-------+------------------------+ set time_zone='UTC';