EnxDev commented on code in PR #45797:
URL: https://github.com/apache/superset/pull/45797#discussion_r4431282519
##########
superset/common/query_context_processor.py:
##########
@@ -151,6 +155,131 @@ def is_summable(series: pd.Series) -> bool:
return infer_dtype(series, skipna=True) == "decimal"
+def _resolve_override(overrides: dict[str, Any], key: str, inherited: Any) ->
Any:
+ """Return the value an annotation layer override resolves to.
+
+ An absent key means "no override". A key stored as ``None`` means
+ "inherit from the host chart", which is what the layer popover checkboxes
+ write, and resolves to ``inherited``. Any other value is used as given.
+ """
+ if key not in overrides:
+ return None
+ value = overrides[key]
+ return inherited if value is None else value
+
+
+def _host_time_range(host_query: QueryObject | None) -> str | None:
+ """Return the host chart's time range expression, or ``None`` without
one."""
+ if host_query is None:
+ return None
+ has_temporal_filter = any(
+ flt.get("op") == FilterOperator.TEMPORAL_RANGE for flt in
host_query.filter
+ )
+ if not host_query.time_range and not has_temporal_filter:
+ return None
+ return get_time_range_from_filters(
+ host_query.time_range, host_query.filter, host_query.columns
+ )
+
+
+def _host_time_grain(host_query: QueryObject | None) -> str | None:
+ """Return the host chart's time grain, or ``None`` when it has none.
+
+ Charts with a generic x-axis carry the grain on their BASE_AXIS column;
+ legacy charts carry it in ``extras["time_grain_sqla"]``.
+ """
+ if host_query is None:
+ return None
+ for column in host_query.columns:
+ if is_adhoc_column(column) and column.get("columnType") == "BASE_AXIS":
+ if grain := column.get("timeGrain"):
+ return grain
+ return host_query.extras.get("time_grain_sqla")
+
+
+def _apply_time_range(
+ query_context: QueryContext, time_range: str, time_column: Any
+) -> None:
+ """Run every query of an annotation source chart over ``time_range``.
+
+ Mirrors ``QueryContextFactory._apply_filters``: the range is written to
+ ``time_range`` and to every TEMPORAL_RANGE filter, which is where charts
+ with a generic x-axis read it, and ``from_dttm``/``to_dttm`` are
+ recomputed for charts on the legacy ``granularity`` path. A source query
+ without a TEMPORAL_RANGE filter gets one on the layer's time column when
+ that column belongs to the source dataset.
+ """
+ column_names = query_context.datasource.column_names
+ for query_object in query_context.queries:
+ query_object.time_range = time_range
+ temporal_filters = [
+ flt
+ for flt in query_object.filter
+ if flt.get("op") == FilterOperator.TEMPORAL_RANGE
+ ]
+ if temporal_filters:
+ for flt in temporal_filters:
+ flt["val"] = time_range
+ elif isinstance(time_column, str) and time_column in column_names:
Review Comment:
On an Interval layer `timeColumn` is the start column, so an interval that
began before the host range and runs into it gets filtered out. Override time
range is on by default once a source chart is picked, so existing interval
layers that used to draw those clipped at the axis edge would lose them.
Could INTERVAL layers filter on overlap instead (start before the range end,
`intervalEndColumn` after the range start), here and in the rewrite just above?
--
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]