You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/05/08 13:31:37 UTC
[GitHub] [superset] cccs-jc commented on a change in pull request #14507: feat: Implementation issue 13943
cccs-jc commented on a change in pull request #14507:
URL: https://github.com/apache/superset/pull/14507#discussion_r628752010
##########
File path: superset/jinja_context.py
##########
@@ -213,6 +165,147 @@ def url_param(
self.cache_key_wrapper(result)
return result
+ def filter_values(
+ self, column: str, default: Optional[str] = None, remove_filter: bool = True
+ ) -> List[str]:
+ """Gets a values for a particular filter as a list
+
+ This is useful if:
+ - you want to use a filter box to filter a query where the name of filter
+ box column doesn't match the one in the select statement
+ - you want to have the ability for filter inside the main query for speed
+ purposes
+
+ Usage example::
+
+ SELECT action, count(*) as times
+ FROM logs
+ WHERE
+ action in ({{ "'" + "','".join(filter_values('action_type')) + "'" }})
+ GROUP BY action
+
+ :param column: column/filter name to lookup
+ :param default: default value to return if there's no matching columns
+ :param remove_filter:
+ flag indicating if superset should generate a condition for this filter
+ :return: returns a list of filter values
+ """
+ from superset.views.utils import get_form_data
+
+ form_data, _ = get_form_data()
+ convert_legacy_filters_into_adhoc(form_data)
+ merge_extra_filters(form_data)
+
+ return_val = [
+ comparator
+ for filter in form_data.get("adhoc_filters", [])
+ for comparator in (
+ filter["comparator"]
+ if isinstance(filter["comparator"], list)
+ else [filter["comparator"]]
+ )
+ if (
+ filter.get("expressionType") == "SIMPLE"
+ and filter.get("clause") == "WHERE"
+ and filter.get("subject") == column
+ and filter.get("comparator")
+ )
+ ]
+
+ if return_val:
+ if remove_filter:
+ self.cache_key_wrapper({"filter_removed_by_vt": column})
+ return return_val
+
+ if default:
+ return [default]
+
+ return []
+
+ def get_filters(self, column: str, remove_filter: bool = True) -> List[str]:
Review comment:
ha yes, I'll do that.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org