villebro commented on a change in pull request #14507:
URL: https://github.com/apache/superset/pull/14507#discussion_r636854532
##########
File path: superset/jinja_context.py
##########
@@ -213,6 +183,142 @@ def url_param(
self.cache_key_wrapper(result)
return result
+ def filter_values(
+ self, column: str, default: Optional[str] = None, remove_filter: bool
= False
+ ) -> List[str]:
Review comment:
I think the return value is `List[Any]`
##########
File path: superset/jinja_context.py
##########
@@ -213,6 +183,142 @@ def url_param(
self.cache_key_wrapper(result)
return result
+ def filter_values(
+ self, column: str, default: Optional[str] = None, remove_filter: bool
= False
+ ) -> List[str]:
+ """Gets a values for a particular filter as a list
+
+ This is useful if:
+ - you want to use a filter component to filter a query where the
name of
+ filter component 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: When set to true, mark the filter as processed,
+ removing it from the outer query. Useful when a filter should
+ only apply to the inner query
+ :return: returns a list of filter values
+ """
+ return_val: List[str] = []
Review comment:
Same here: `List[Any]`
##########
File path: superset/jinja_context.py
##########
@@ -60,56 +71,10 @@ def context_addons() -> Dict[str, Any]:
return current_app.config.get("JINJA_CONTEXT_ADDONS", {})
-def filter_values(column: str, default: Optional[str] = None) -> 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
- :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:
- return return_val
-
- if default:
- return [default]
-
- return []
+class Filter(TypedDict):
+ op: str
+ col: str
+ val: Union[str, List[str]]
Review comment:
I think here we need to assume `val` can be `Optional[Union[Any,
List[Any]]]`
--
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]