Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chart): Supporting custom SQL as temporal x-axis column with filter #25126

Merged
merged 14 commits into from
Sep 18, 2023
16 changes: 12 additions & 4 deletions superset/common/query_context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def _apply_granularity(

if granularity := query_object.granularity:
filter_to_remove = None
if x_axis and x_axis in temporal_columns:
x_axis_column_name = (
x_axis["sqlExpression"] if isinstance(x_axis, dict) else x_axis
)
zephyring marked this conversation as resolved.
Show resolved Hide resolved
if x_axis_column_name in temporal_columns:
filter_to_remove = x_axis
x_axis_column = next(
(
Expand All @@ -137,7 +140,7 @@ def _apply_granularity(
if column == x_axis
or (
isinstance(column, dict)
and column["sqlExpression"] == x_axis
and column["sqlExpression"] == x_axis_column_name
)
),
None,
Expand Down Expand Up @@ -175,11 +178,16 @@ def _apply_granularity(
# another temporal filter. A new filter based on the value of
# the granularity will be added later in the code.
# In practice, this is replacing the previous default temporal filter.
if filter_to_remove:
filter_to_remove_str = (
filter_to_remove["sqlExpression"]
if isinstance(filter_to_remove, dict)
else filter_to_remove
)
if filter_to_remove_str:
query_object.filter = [
filter
for filter in query_object.filter
if filter["col"] != filter_to_remove
if filter["col"] != filter_to_remove_str
]

def _apply_filters(self, query_object: QueryObject) -> None:
Expand Down
Loading