dhruv-techdev opened a new pull request, #45435:
URL: https://github.com/apache/superset/pull/45435

   ### SUMMARY
   
   The Hive `Week` time grain (`P1W`) in 
`HiveEngineSpec._time_grain_expressions` didn't group the days of a week into 
one bucket. `from_unixtime(..., 'u')` returns the ISO day of week (Monday=1 … 
Sunday=7), and the expression subtracted `7 - u` days, so each weekday landed 
on a different date. Weekly charts on Hive showed roughly one point every two 
days, each with a partial total.
   
   This changes the subtraction to `u - 1`, which truncates every date to the 
Monday of its week. It is a one-line change in 
`superset/db_engine_specs/hive.py`; no other grains or engines are touched. 
`SparkEngineSpec` and `DatabricksHiveEngineSpec` define their own grains and 
are unaffected.
   
   ```diff
   - date_sub({col}, CAST(7-from_unixtime(unix_timestamp({col}),'u') as int))
   + date_sub({col}, CAST(from_unixtime(unix_timestamp({col}),'u') as int)-1)
   ```
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Week bucket assigned to each day:
   
   | Date | Day | Before | After |
   |---|---|---|---|
   | 2025-01-06 | Mon | 2024-12-31 | 2025-01-06 |
   | 2025-01-07 | Tue | 2025-01-02 | 2025-01-06 |
   | 2025-01-08 | Wed | 2025-01-04 | 2025-01-06 |
   | 2025-01-09 | Thu | 2025-01-06 | 2025-01-06 |
   | 2025-01-10 | Fri | 2025-01-08 | 2025-01-06 |
   | 2025-01-11 | Sat | 2025-01-10 | 2025-01-06 |
   | 2025-01-12 | Sun | 2025-01-12 | 2025-01-06 |
   
   ### TESTING INSTRUCTIONS
   
   1. Run this in SQL Lab against a Hive database. All seven rows should return 
`2025-01-06`; with the old expression they return seven different dates.
   
      ```sql
      SELECT d,
             date_format(date_sub(d, CAST(from_unixtime(unix_timestamp(d),'u') 
AS int)-1), 'yyyy-MM-dd') AS week_bucket
      FROM (SELECT 
explode(array('2025-01-06','2025-01-07','2025-01-08','2025-01-09',
                                 '2025-01-10','2025-01-11','2025-01-12')) AS d) 
t;
      ```
   
   2. In Explore, build a Line Chart on a Hive dataset with daily rows and set 
**Time grain = Week**. The X-axis should show one point per week.
   
   The new arithmetic was checked over four consecutive weeks (28 days) with 
Java's `SimpleDateFormat`, which Hive 1.x–3.x uses for `from_unixtime`: every 
day mapped to its week's Monday. It has not yet been run against a live Hive 
server.
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: Fixes #45434 
   - [ ] 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]

Reply via email to