aminghadersohi commented on code in PR #45671:
URL: https://github.com/apache/superset/pull/45671#discussion_r4434586592
##########
superset/models/helpers.py:
##########
@@ -3409,12 +3466,18 @@ def get_offset_custom_or_inherit(
# the range against itself, and a 36-hour range would shift by a
# single day and overlap it. Whole-day ranges resolve to the same
# instant either way.
- duration = outer_to_dttm - outer_from_dttm
+ from_comparison, to_comparison = get_comparable_bounds(
+ *self._inherit_time_bounds(outer_from_dttm, outer_to_dttm)
+ )
+ duration = to_comparison - from_comparison
Review Comment:
With a +08:00 quarter start and a naive end (no dataset tz), `inherit` now
shifts by the SQL span, 91d 8h, and `join_offset_dfs` shifts each main row by
that amount: at Day grain no bucket matches and the comparison series is all
null (0/92; the previous commit filled 92/92).
##########
superset/models/helpers.py:
##########
@@ -3387,6 +3422,28 @@ def is_valid_date_range(self, date_range: str) -> bool:
# YYYY-MM-DD:YYYY-MM-DD
return False
+ def _inherit_time_bounds(
+ self,
+ start: datetime,
+ end: datetime,
+ time_col: Optional["TableColumn"] = None,
+ ) -> tuple[datetime, datetime]:
+ """Resolve explicit inherited periods in the SQL filter's coordinate
frame."""
+ if start.utcoffset() is None and end.utcoffset() is None:
+ return start, end
+ if time_col is None:
+ time_col = next(
+ (col for col in self.columns if col.column_name ==
self.main_dttm_col),
Review Comment:
`get_offset_custom_or_inherit` re-enters here without `time_col`, so this
fallback runs for every explicit-offset `inherit`; on a SQL Lab `Query`
datasource `main_dttm_col` calls `.get` on a `TableColumn` and raises
`AttributeError`, failing the chart request (the previous commit returned a
shift).
##########
superset/utils/date_parser.py:
##########
@@ -739,32 +753,34 @@ def get_since_until( # pylint:
disable=too-many-arguments,too-many-locals,too-m
elif instant_time_comparison_range == InstantTimeComparison.WEEK:
time_unit = "WEEK"
elif instant_time_comparison_range ==
InstantTimeComparison.INHERITED:
- delta_in_days = (_until - _since).days if _since and _until
else None
+ if _since and _until:
+ since_comparison, until_comparison = get_comparable_bounds(
+ _since, _until
+ )
+ delta_in_days = (until_comparison - since_comparison).days
Review Comment:
For `DATETRUNC(DATETIME('2024-05-31T12:00:00+08:00'), QUARTER) :
2024-07-01`, the INHERITED instant comparison shifts by 91 wall-clock days, so
its window ends at 04-01 00:00 UTC while the main window starts 03-31 16:00
UTC: 8h of rows land in both periods.
--
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]