innovark37 opened a new pull request, #41579:
URL: https://github.com/apache/superset/pull/41579
### SUMMARY
Fixes ClickHouse temporal filter SQL generation for deployments where the
ClickHouse server/session timezone is not UTC.
Superset computes time filter bounds in UTC, but ClickHouse
`toDateTime('YYYY-MM-DD HH:mm:ss')` interprets the string in the server/session
timezone when no timezone argument is provided. This can shift the effective
filter bounds and cause expected rows to be excluded.
This change renders ClickHouse `DateTime` literals with an explicit UTC
timezone:
```sql
toDateTime('2026-06-30 09:20:00', 'UTC')
```
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
#### Setup
- ClickHouse configured with a non-UTC timezone (`Europe/Moscow`)
<img width="828" height="430" alt="{652E6CF9-B379-425E-8590-734A41D4C9F1}"
src="https://github.com/user-attachments/assets/99958744-815f-4e22-a680-7ba64be6ecef"
/>
- Test data
<img width="816" height="511" alt="{B612A6CE-CC74-45E4-81B0-1A05B402DDB6}"
src="https://github.com/user-attachments/assets/f52e18fb-f2ef-4ba7-8478-e8a5ae0a55ec"
/>
#### Before:
- The chart returns an empty result even when the selected UTC time range
contains matching rows.
<img width="1613" height="776" alt="{B2A9B64E-7D32-4A02-ADC5-3980B9464976}"
src="https://github.com/user-attachments/assets/e9c8eb5d-353c-4550-af81-8f96b47d224a"
/>
- The generated SQL uses `toDateTime('...', )` without an explicit timezone:
```
toDateTime('2026-06-30 09:20:00')
```
<img width="869" height="325" alt="{22E34CC4-39D6-4611-8928-31B66DB7F07A}"
src="https://github.com/user-attachments/assets/ce16ee22-c198-4a61-9e2f-b6485ed35645"
/>
#### After:
- The same chart returns the expected row.
<img width="1604" height="781" alt="{C1BCA014-512C-42C8-9424-AD584E6C1CB8}"
src="https://github.com/user-attachments/assets/c5488cc3-d12f-4889-b472-437cb1f4ea78"
/>
- The generated SQL includes the UTC timezone explicitly:
```
toDateTime('2026-06-30 09:20:00', 'UTC')
```
<img width="861" height="326" alt="{EE1C53FD-01A7-4876-BD9F-BFC5B22B6FDB}"
src="https://github.com/user-attachments/assets/d7862775-e986-4c0e-9f44-ca1cf8a1d9a1"
/>
### TESTING INSTRUCTIONS
1. Configure ClickHouse with a non-UTC timezone, for example `Europe/Moscow`.
2. Verify timezone behavior in SQL Lab:
```sql
SELECT
timezone() AS clickhouse_tz,
toUnixTimestamp(toDateTime('2026-06-30 09:00:00')) AS without_tz,
toUnixTimestamp(toDateTime('2026-06-30 09:00:00', 'UTC')) AS with_utc,
without_tz - with_utc AS diff_seconds;
```
3. Create test data:
```sql
CREATE DATABASE IF NOT EXISTS tz_bug_test;
DROP TABLE IF EXISTS tz_bug_test.events;
CREATE TABLE tz_bug_test.events
(
id UInt8,
name String,
createdAt DateTime('UTC')
)
ENGINE = MergeTree
ORDER BY createdAt;
INSERT INTO tz_bug_test.events VALUES
(1, 'event 12:00 Moscow', toDateTime('2026-06-30 09:00:00', 'UTC')),
(2, 'event 12:30 Moscow', toDateTime('2026-06-30 09:30:00', 'UTC')),
(3, 'event 13:00 Moscow', toDateTime('2026-06-30 10:00:00', 'UTC'));
```
4. Create a dataset for `tz_bug_test.events`.
5. Ensure `createdAt` is marked as temporal.
6. Create a Table chart with `id`, `name`, and `createdAt`.
7. Use `createdAt` as the time column.
8. Apply this custom time range:
```
2026-06-30 09:20:00 : 2026-06-30 09:40:00
```
9. Confirm that `event 12:30 Moscow` is returned.
10. Open the generated SQL and confirm the filter uses:
```
toDateTime('2026-06-30 09:20:00', 'UTC')
```
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]