AmoghAtreya opened a new pull request, #42329:
URL: https://github.com/apache/superset/pull/42329
### SUMMARY
Fixes #42254
When applying a time grain to a pure `DATE` column in PostgreSQL,
`DATE_TRUNC` implicitly converts the column value to a `TIMESTAMP WITH TIME
ZONE` evaluated at `00:00:00`. Downstream processing and client timezone
conversions then shift the value, causing plain calendar dates (e.g.,
`2026-03-30`) to display as the previous day (e.g., `2026-03-29`).
This PR overrides `get_timestamp_expr` in `PostgresBaseEngineSpec` to wrap
time grain truncation in `CAST(... AS DATE)` whenever the source column is a
pure `DATE` type. This preserves calendar date semantics across PostgreSQL and
dialect-derived engines (Redshift, Greenplum, etc.) without altering genuine
`TIMESTAMP` or `DATETIME` time-series behavior.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
* **Before SQL:** `DATE_TRUNC('day', event_date)` → returns `TIMESTAMP` →
triggers timezone offset shift.
* **After SQL:** `CAST(DATE_TRUNC('day', event_date) AS DATE)` → stays
`DATE` → no timezone shift.
### TESTING INSTRUCTIONS
1. Add a PostgreSQL table containing a column with type `DATE`.
2. Connect the dataset to Superset in a non-UTC timezone.
3. Select the `DATE` column with a `Day` time grain in Explore View.
4. Verify the generated SQL wraps the expression in `CAST(... AS DATE)` and
that the calendar date remains unshifted.
5. Added unit tests covering `DATE` vs `DATETIME` columns in
`tests/unit_tests/db_engine_specs/test_postgres.py`.
### ADDITIONAL INFORMATION
- [x] Has associated issue: #42254
- [ ] 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]