adwaitm1301 opened a new pull request, #42639:
URL: https://github.com/apache/superset/pull/42639
### SUMMARY
Fixes #42386
When a string column on a physical dataset is manually marked as temporal,
Superset passes it straight into `DATE_TRUNC`, which PostgreSQL rejects because
`DATE_TRUNC` has no overload for `character varying`:
```
SELECT DATE_TRUNC('day', event_timestamp) AS event_timestamp, ...
```
This change makes `PostgresBaseEngineSpec.get_timestamp_expr` cast the
column to `TIMESTAMP` before applying the grain when the underlying SQLAlchemy
type is a string type. It builds on the existing override that handles pure
`DATE` columns (see #42254), so both cases stay in one place.
Behavior that is intentionally left unchanged:
- `DATE` columns are still cast back to `DATE` after truncation, preserving
the fix from #42254.
- `TIMESTAMP`/`DATETIME` columns are not cast.
- Epoch-based formats (`epoch_s`, `epoch_ms`) and bare years (`%Y`) keep
their existing expressions.
- Columns without a grain, or without a known type, are not touched.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable.
### TESTING INSTRUCTIONS
1. Create a PostgreSQL table with a `VARCHAR` column holding timestamps,
following the repro steps in #42386.
2. Create a physical dataset and mark the column as temporal.
3. Build a time series chart with a day grain and run it. The query now
renders as:
```sql
SELECT DATE_TRUNC('day', CAST(event_timestamp AS TIMESTAMP)) AS
event_timestamp, ...
```
4. Run the new unit tests:
```
pytest tests/unit_tests/db_engine_specs/test_postgres.py -k
get_timestamp_expr
```
### ADDITIONAL INFORMATION
- [x] Has associated issue: #42386
- [ ] 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]