GabeLoins commented on a change in pull request #4909: [Explore] Adding Adhoc
Filters
URL:
https://github.com/apache/incubator-superset/pull/4909#discussion_r186799129
##########
File path: superset/viz.py
##########
@@ -252,14 +252,56 @@ def query_obj(self):
# extras are used to query elements specific to a datasource type
# for instance the extra where clause that applies only to Tables
- extras = {
- 'where': form_data.get('where', ''),
- 'having': form_data.get('having', ''),
- 'having_druid': form_data.get('having_filters', []),
- 'time_grain_sqla': form_data.get('time_grain_sqla', ''),
- 'druid_time_origin': form_data.get('druid_time_origin', ''),
- }
- filters = form_data.get('filters', [])
+
+ extras = {}
+ filters = []
+ adhoc_filters = form_data.get('adhoc_filters', None)
+ if adhoc_filters is None:
+ extras = {
+ 'where': form_data.get('where', ''),
+ 'having': form_data.get('having', ''),
+ 'having_druid': form_data.get('having_filters', []),
+ 'time_grain_sqla': form_data.get('time_grain_sqla', ''),
+ 'druid_time_origin': form_data.get('druid_time_origin', ''),
+ }
+ filters = form_data.get('filters', [])
+ elif isinstance(adhoc_filters, list):
+ simple_where_filters = []
+ simple_having_filters = []
+ sql_where_filters = []
+ sql_having_filters = []
+ for adhoc_filter in adhoc_filters:
+ expression_type = adhoc_filter.get('expressionType')
+ clause = adhoc_filter.get('clause')
+ if expression_type == 'SIMPLE':
+ if clause == 'WHERE':
+ simple_where_filters.append({
+ 'col': adhoc_filter.get('subject'),
+ 'op': adhoc_filter.get('operator'),
+ 'val': adhoc_filter.get('comparator'),
+ })
+ elif clause == 'HAVING':
+ simple_having_filters.append({
+ 'col': adhoc_filter.get('subject'),
+ 'op': adhoc_filter.get('operator'),
+ 'val': adhoc_filter.get('comparator'),
+ })
+ elif expression_type == 'SQL':
+ if clause == 'WHERE':
+
sql_where_filters.append(adhoc_filter.get('sqlExpression'))
+ elif clause == 'HAVING':
+
sql_having_filters.append(adhoc_filter.get('sqlExpression'))
+ extras = {
+ 'where': ' AND '.join(['({})'.format(sql) for sql in
sql_where_filters]),
+ 'having': ' AND '.join(
+ ['({})'.format(sql) for sql in sql_having_filters],
Review comment:
by one character 😢
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]