sharmavikas18 opened a new pull request, #37702:
URL: https://github.com/apache/superset/pull/37702
SUMMARY
This PR fixes the Oracle time-grain behavior described in #37608, where
charts (such as Box Plot visualizations) could display incorrect date values
(for example, years like 8959) when grouping by time.
The issue occurs because Oracle’s TRUNC() function returns a DATE, while
Superset expects a TIMESTAMP for time-series grouping. This mismatch causes
incorrect date interpretation downstream.
This PR ensures that all Oracle time-grain expressions return a TIMESTAMP.
Changes made
Oracle engine spec update
File:
superset/db_engine_specs/oracle.py
Time-grain expressions now cast truncated values to TIMESTAMP:
SECOND now returns:
CAST({col} as TIMESTAMP)
Other grains now follow the pattern:
CAST(TRUNC(CAST({col} as DATE), '<grain>') AS TIMESTAMP)
This guarantees consistent timestamp typing across all time grains.
Unit test update
File:
tests/unit_tests/db_engine_specs/test_oracle.py
Updated the monthly-grain test assertion to verify the new SQL output:
Before:
TRUNC(CAST("decimal" as DATE), 'MONTH')
After:
CAST(TRUNC(CAST("decimal" as DATE), 'MONTH') AS TIMESTAMP)
This ensures future changes do not regress Oracle time-grain behavior.
Why this fix works
Oracle:
TRUNC(date) → returns DATE
Superset expects:
TIMESTAMP for temporal grouping
By explicitly casting:
CAST(... AS TIMESTAMP)
the engine spec now produces consistent temporal values, preventing
incorrect year rendering and ensuring correct chart grouping.
Fixes #37608
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable — this change affects SQL generation and backend type
handling.
TESTING INSTRUCTIONS
Connect Superset to an Oracle database.
Create a dataset with a datetime column.
Build a chart (e.g., Box Plot or time-series chart).
Apply a time grain such as Month.
Verify:
Dates render correctly.
No incorrect year values appear.
Run unit tests:
pytest tests/unit_tests/db_engine_specs/test_oracle.py
Confirm the updated test passes.
ADDITIONAL INFORMATION
- [x] Has associated issue: Fixes #37608
- [ ] 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]