Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion superset/views/datasource/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Any, Optional
from typing import Any, Iterable, Optional

from flask import current_app as app

Expand Down Expand Up @@ -44,6 +44,35 @@ def get_limit_clause(page: Optional[int], per_page: Optional[int]) -> dict[str,
return {"row_offset": offset, "row_limit": limit}


def replace_verbose_with_column(
filters: list[dict[str, Any]],
columns: Iterable[Any],
verbose_attr: str = "verbose_name",
column_attr: str = "column_name",
) -> None:
"""
Replace filter 'col' values that match column verbose_name with the column_name.
Operates in-place on the filters list.

Args:
filters: List of filter dicts, each must have 'col' key.
columns: Iterable of column objects with verbose_name and column_name.
verbose_attr: Attribute name for verbose/label.
column_attr: Attribute name for actual column name.
"""
for f in filters:
match = next(
(
getattr(col, column_attr)
for col in columns
if getattr(col, verbose_attr) == f["col"]
Comment thread
LisaHusband marked this conversation as resolved.
Outdated
),
None,
)
Comment thread
LisaHusband marked this conversation as resolved.
Outdated
if match:
f["col"] = match


Comment thread
LisaHusband marked this conversation as resolved.
def get_samples( # pylint: disable=too-many-arguments
datasource_type: str,
datasource_id: int,
Expand Down Expand Up @@ -72,6 +101,9 @@ def get_samples( # pylint: disable=too-many-arguments
force=force,
)
else:
# Use column names replacing verbose column names(Label)
replace_verbose_with_column(payload.get("filters", []), datasource.columns)

# constructing drill detail query
# When query_type == 'samples' the `time filter` will be removed,
# so it is not applicable drill detail query
Expand Down
Loading