Skip to content

Commit

Permalink
fix: implement new blank/not blank filters (#2693)
Browse files Browse the repository at this point in the history
  • Loading branch information
niross authored Jul 5, 2023
1 parent 1188c50 commit 39d3983
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions dataworkspace/dataworkspace/apps/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,6 @@ def build_filtered_dataset_query(inner_query, download_limit, column_config, par
f"LOWER(STRING_TO_ARRAY(%({field})s, ',')::text) != LOWER({{}}::TEXT) or {{}} is NULL"
).format(Identifier(field), Identifier(field))
)
if filter_data["type"] == "blank":
where_clause.append(SQL("{{}} IS NULL").format(Identifier(field)))
if filter_data["type"] == "notBlank":
where_clause.append(SQL("{{}} IS NOT NULL").format(Identifier(field)))

elif data_type == "text" and filter_data["type"] == "contains":
query_params[field] = f"%{terms[0]}%"
Expand Down Expand Up @@ -563,11 +559,9 @@ def build_filtered_dataset_query(inner_query, download_limit, column_config, par
operator = "<" if filter_data["type"] == "lessThan" else "<="
where_clause.append(SQL(f"{{}} {operator} %({field})s").format(Identifier(field)))
elif filter_data["type"] == "blank":
where_clause.append(SQL("COALESCE({{}}::TEXT, '') = ''").format(Identifier(field)))
where_clause.append(SQL("COALESCE({}::TEXT, '') = ''").format(Identifier(field)))
elif filter_data["type"] == "notBlank":
where_clause.append(
SQL("COALESCE({{}}::TEXT, '') != ''").format(Identifier(field))
)
where_clause.append(SQL("COALESCE({}::TEXT, '') != ''").format(Identifier(field)))

if where_clause:
where_clause = SQL(" WHERE ") + SQL(" AND ").join(where_clause)
Expand Down

0 comments on commit 39d3983

Please sign in to comment.