cccs-jc commented on a change in pull request #14507:
URL: https://github.com/apache/superset/pull/14507#discussion_r636834724



##########
File path: superset/jinja_context.py
##########
@@ -213,6 +176,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
+        """

Review comment:
       Although `get_filters` is more generic is also a bit less friendly to 
use in a jinja template.
   
   For instance with filter_values you can do something like
   ```
   where
                 action in ({{ "'" + "','".join(filter_values('action_type')) + 
"'" }})
   ```
   
   However with get_filters the list of values is in each filter (if user 
specified filter twice). 
   So in the template you would have to iterate over the array of filters, pull 
out the `val` attribute of type array. And finally include all the items in a 
consolidated array. I know it's probably doable in a single line of python but 
it will be less obvious than the filter_values.
   
   what do you think?




-- 
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]

Reply via email to