nitishagar opened a new pull request, #38617:
URL: https://github.com/apache/superset/pull/38617
### SUMMARY
ECharts time-series charts using **Time Grain = HOUR** on MySQL/StarRocks
databases were generating invalid SQL:
```sql
-- ❌ Actual (broken)
DATE_ADD(col, INTERVAL (HOUR(col)) HOUR)
-- ✅ Expected
DATE_ADD(DATE(col), INTERVAL HOUR(col) HOUR)
```
The bare `DATE({col})` call in the `_time_grain_expressions[TimeGrain.HOUR]`
template was being stripped by SQLGlot during SQL sanitization and/or by
SQLAlchemy's `_constructor` proxy mechanism when `TimestampExpression` is
proxied through a series-limit subquery.
Wrapping `DATE({col})` in `CAST(... AS DATETIME)` produces semantically
identical output but is immune to these normalizations. This matches the
confirmed workaround reported in the issue.
Regression tests added for:
- All MySQL time grain expression templates (parametrized)
- `TimestampExpression` compilation preserving the `CAST(DATE(...) AS
DATETIME)` wrapper
- StarRocks inheriting correct MySQL HOUR expression
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — SQL query generation change
### TESTING INSTRUCTIONS
1. Create a dataset with a DATETIME/TIMESTAMP column on MySQL or StarRocks
2. Create an ECharts Area Chart
3. Set Time Grain = **HOUR**
4. Inspect **View query**
5. Verify the time bucket expression is `DATE_ADD(CAST(DATE(col) AS
DATETIME), INTERVAL HOUR(col) HOUR)` (correct aggregation)
Unit tests cover the fix directly — run:
```
pytest tests/unit_tests/db_engine_specs/test_mysql.py
tests/unit_tests/db_engine_specs/test_starrocks.py -v
```
### ADDITIONAL INFORMATION
- [x] Has associated issue: Fixes #36798
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] 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]