jesperct opened a new pull request, #40586:
URL: https://github.com/apache/superset/pull/40586

   ### SUMMARY
   
   When a chart with a Custom SQL X-axis (adhoc column whose label differs from 
the underlying time column) uses a relative time comparison like "1 year ago", 
the offset query's temporal filter never gets shifted. The original time range 
and the granularity-derived shifted range both end up in the WHERE clause, 
AND'd together. The intersection is empty for most rows, so the comparison 
series plots as `null`.
   
   In `processing_time_offsets` (relative-offset, datetime-series branch), the 
existing TEMPORAL_RANGE filter was matched against 
`query_object_clone.granularity or x_axis_label`. For an adhoc Custom SQL 
X-axis the label is the user's column label (e.g. `wedding_date_cast`), not the 
dataset column the filter is on (`wedding_date`), so the match fails and the 
filter's `val` stays at the original range.
   
   The fix uses `_get_temporal_column_for_filter`, which is already used by the 
date-range-offset branch. It prefers the column from an existing TEMPORAL_RANGE 
filter over the X-axis label.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Same chart, same X-axis Custom SQL, "1 year ago" comparison. Offset query 
SQL:
   
   Before (offset has impossible intersection of original + shifted ranges):
   
   ```sql
   WHERE wedding_date >= '2024-01-01' AND wedding_date < '2025-06-01'
     AND wedding_date >= '2025-01-01' AND wedding_date < '2026-06-01'
   ```
   
   After (offset uses the shifted range only):
   
   ```sql
   WHERE wedding_date >= '2024-01-01' AND wedding_date < '2025-06-01'
     AND wedding_date >= '2024-01-01' AND wedding_date < '2025-06-01'
   ```
   
   Comparison series values change from `null` everywhere to real values.
   
   ### TESTING INSTRUCTIONS
   
   1. Create a virtual dataset with a temporal column (e.g. `wedding_date`).
   2. Create a Mixed/Line/Bar chart on that dataset.
   3. Set X-axis to Custom SQL with a Jinja expression like:
      ```
      {% set tc = time_column if time_column else 'wedding_date' %} CAST({{ tc 
}} AS TIMESTAMP)
      ```
   4. Add a SUM metric, a TEMPORAL_RANGE filter on `wedding_date`, time grain 
Month.
   5. Enable a relative time comparison such as "1 year ago".
   6. Confirm the comparison line plots values rather than `null`.
   
   Unit test: 
`test_processing_time_offsets_updates_temporal_filter_with_adhoc_x_axis`.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
   - [ ] 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