fix: use local midnight as the default range ALIGN TO origin (#10795)

Signed-off-by: Vishal Kotak <vishal.sanjiv.kotak@gmail.com>
Co-authored-by: dennis zhuang <killme2008@gmail.com>
This commit is contained in:
Vishal Kotak
2026-12-02 10:56:20 +00:00
committed by GitHub
co-authored by dennis zhuang
parent ea7e61e82a
commit d5ad08c1e3
2 changed files with 14 additions and 15 deletions
+6 -5
View File
@@ -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,
+8 -10
View File
@@ -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';