FrancescoCastaldi commented on issue #45857:
URL: https://github.com/apache/superset/issues/45857#issuecomment-6524014338

   ### Root Cause Analysis & Solution
   
   In `superset/db_engine_specs/oracle.py` and `impala.py`, `TimeGrain.WEEK` is 
defined as:
   ```python
   TimeGrain.WEEK: "TRUNC(CAST({col} as DATE), 'WW')"
   ```
   In Oracle SQL, the `'WW'` format code calculates 7-day increments starting 
from the day of the week of January 1st of that calendar year, rather than a 
fixed standard Monday. As a result:
   - The starting day of the week shifts each year depending on January 1st.
   - Year-end boundary conditions produce 1-day or 2-day stub weeks around 
December 31st.
   
   #### Solution
   1. In `oracle.py`: replace `'WW'` with `'IW'` (ISO week, which strictly 
begins on Monday independent of `NLS_TERRITORY`):
   ```python
   TimeGrain.WEEK: "TRUNC(CAST({col} as DATE), 'IW')"
   ```
   2. In `impala.py`: use `DATE_TRUNC('week', {col})`, which adheres to 
standard calendar weeks beginning on Monday.
   
   This fix has been verified with unit tests in 
`tests/unit_tests/db_engine_specs/test_oracle.py` and committed to branch 
`fix/community-unanswered-issues` (commit `8df7794c4e2`) at 
https://github.com/FrancescoCastaldi/superset/tree/fix/community-unanswered-issues.
   


-- 
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]

Reply via email to