Skip to content

Commit 17d7e7e

Browse files
authored
fix: Remove BASE_AXIS from pre-query (apache#29084)
1 parent df0b1cb commit 17d7e7e

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

null_byte.csv

6 Bytes
Binary file not shown.

superset/common/query_context_processor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
get_column_names_from_columns,
6161
get_column_names_from_metrics,
6262
get_metric_names,
63-
get_xaxis_label,
63+
get_x_axis_label,
6464
normalize_dttm_col,
6565
TIME_COMPARISON,
6666
)
@@ -399,7 +399,7 @@ def processing_time_offsets( # pylint: disable=too-many-locals,too-many-stateme
399399
for offset in query_object.time_offsets:
400400
try:
401401
# pylint: disable=line-too-long
402-
# Since the xaxis is also a column name for the time filter, xaxis_label will be set as granularity
402+
# Since the x-axis is also a column name for the time filter, x_axis_label will be set as granularity
403403
# these query object are equivalent:
404404
# 1) { granularity: 'dttm_col', time_range: '2020 : 2021', time_offsets: ['1 year ago']}
405405
# 2) { columns: [
@@ -414,9 +414,9 @@ def processing_time_offsets( # pylint: disable=too-many-locals,too-many-stateme
414414
)
415415
query_object_clone.to_dttm = get_past_or_future(offset, outer_to_dttm)
416416

417-
xaxis_label = get_xaxis_label(query_object.columns)
417+
x_axis_label = get_x_axis_label(query_object.columns)
418418
query_object_clone.granularity = (
419-
query_object_clone.granularity or xaxis_label
419+
query_object_clone.granularity or x_axis_label
420420
)
421421
except ValueError as ex:
422422
raise QueryObjectValidationError(str(ex)) from ex
@@ -450,7 +450,7 @@ def processing_time_offsets( # pylint: disable=too-many-locals,too-many-stateme
450450
query_object_clone.filter = [
451451
flt
452452
for flt in query_object_clone.filter
453-
if flt.get("col") != xaxis_label
453+
if flt.get("col") != x_axis_label
454454
]
455455

456456
# `offset` is added to the hash function

superset/common/query_object_factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
DatasourceDict,
2929
DatasourceType,
3030
FilterOperator,
31-
get_xaxis_label,
31+
get_x_axis_label,
3232
QueryObjectFilterClause,
3333
)
3434

@@ -122,9 +122,9 @@ def _process_time_range(
122122
# Use the temporal filter as the time range.
123123
# if the temporal filters uses x-axis as the temporal filter
124124
# then use it or use the first temporal filter
125-
xaxis_label = get_xaxis_label(columns or [])
125+
x_axis_label = get_x_axis_label(columns)
126126
match_flt = [
127-
flt for flt in temporal_flt if flt.get("col") == xaxis_label
127+
flt for flt in temporal_flt if flt.get("col") == x_axis_label
128128
]
129129
if match_flt:
130130
time_range = cast(str, match_flt[0].get("val"))

superset/common/utils/time_range_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_since_until_from_query_object(
5252
"""
5353
this function will return since and until by tuple if
5454
1) the time_range is in the query object.
55-
2) the xaxis column is in the columns field
55+
2) the x-axis column is in the columns field
5656
and its corresponding `temporal_range` filter is in the adhoc filters.
5757
:param query_object: a valid query object
5858
:return: since and until by tuple

superset/models/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
from superset.utils.core import (
9191
GenericDataType,
9292
get_column_name,
93+
get_non_base_axis_columns,
9394
get_user_id,
9495
is_adhoc_column,
9596
MediumText,
@@ -2083,7 +2084,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
20832084
"filter": filter,
20842085
"orderby": orderby,
20852086
"extras": extras,
2086-
"columns": columns,
2087+
"columns": get_non_base_axis_columns(columns),
20872088
"order_desc": True,
20882089
}
20892090

superset/utils/core.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,16 +1056,23 @@ def is_adhoc_column(column: Column) -> TypeGuard[AdhocColumn]:
10561056
)
10571057

10581058

1059+
def is_base_axis(column: Column) -> bool:
1060+
return is_adhoc_column(column) and column.get("columnType") == "BASE_AXIS"
1061+
1062+
1063+
def get_base_axis_columns(columns: list[Column] | None) -> list[Column]:
1064+
return [column for column in columns or [] if is_base_axis(column)]
1065+
1066+
1067+
def get_non_base_axis_columns(columns: list[Column] | None) -> list[Column]:
1068+
return [column for column in columns or [] if not is_base_axis(column)]
1069+
1070+
10591071
def get_base_axis_labels(columns: list[Column] | None) -> tuple[str, ...]:
1060-
axis_cols = [
1061-
col
1062-
for col in columns or []
1063-
if is_adhoc_column(col) and col.get("columnType") == "BASE_AXIS"
1064-
]
1065-
return tuple(get_column_name(col) for col in axis_cols)
1072+
return tuple(get_column_name(column) for column in get_base_axis_columns(columns))
10661073

10671074

1068-
def get_xaxis_label(columns: list[Column] | None) -> str | None:
1075+
def get_x_axis_label(columns: list[Column] | None) -> str | None:
10691076
labels = get_base_axis_labels(columns)
10701077
return labels[0] if labels else None
10711078

0 commit comments

Comments
 (0)