ktmud commented on a change in pull request #13496:
URL: https://github.com/apache/superset/pull/13496#discussion_r589192013
##########
File path: superset/connectors/sqla/models.py
##########
@@ -1061,23 +1061,34 @@ def get_sqla_query( # pylint:
disable=too-many-arguments,too-many-locals,too-ma
target_column_is_numeric=col_obj.is_numeric,
is_list_target=is_list_target,
)
- if op in (
- utils.FilterOperator.IN.value,
- utils.FilterOperator.NOT_IN.value,
- ):
- cond = col_obj.get_sqla_col().in_(eq)
- if isinstance(eq, str) and NULL_STRING in eq:
- cond = or_(
- cond,
- col_obj.get_sqla_col() # pylint:
disable=singleton-comparison
- == None,
+ if is_list_target:
+ if len(eq) == 0:
+ raise QueryObjectValidationError(
+ _("Filter value list cannot be empty")
)
+ if None in eq:
+ eq = [x for x in eq if x is not None]
+ is_null_cond = col_obj.get_sqla_col().is_(None)
+ if eq:
+ cond = or_(is_null_cond,
col_obj.get_sqla_col().in_(eq))
+ else:
+ cond = is_null_cond
Review comment:
Do additional check to make the generated where clause cleaner for when
there are `NULL` in the `IN` list.
Previously it may generate:
```sql
WHERE abc in (NULL, 123) OR abc IS NULL
```
Now it generates:
```sql
WHERE abc in (123, ) OR abc IS NOT NULL
```
##########
File path: superset/connectors/sqla/models.py
##########
@@ -1061,23 +1061,34 @@ def get_sqla_query( # pylint:
disable=too-many-arguments,too-many-locals,too-ma
target_column_is_numeric=col_obj.is_numeric,
is_list_target=is_list_target,
)
- if op in (
- utils.FilterOperator.IN.value,
- utils.FilterOperator.NOT_IN.value,
- ):
- cond = col_obj.get_sqla_col().in_(eq)
- if isinstance(eq, str) and NULL_STRING in eq:
Review comment:
`NULL_STRING` is already parsed to `None` in `filter_values_handler`, so
this is not needed.
----------------------------------------------------------------
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]