Skip to content

Commit

Permalink
#141: Make use of setAttributes() for distinct filter
Browse files Browse the repository at this point in the history
- Also moved the log.debug() to the start of the function. When it was at the end, it would not be logged out if there was an exception, the situation where you want that debug statement
  • Loading branch information
MRichards99 committed Apr 6, 2021
1 parent c0f5fde commit e3169e1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions datagateway_api/common/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def __init__(self, fields):
def apply_filter(self, query):
try:
log.info("Adding ICAT distinct filter to ICAT query")
log.debug("Fields for distinct filter: %s", self.fields)

if (
query.aggregate == "COUNT"
or query.aggregate == "AVG"
Expand All @@ -127,12 +129,9 @@ def apply_filter(self, query):
else:
query.setAggregate("DISTINCT")

# Using where filters to identify which fields to apply distinct too
for field in self.fields:
where_filter = PythonICATWhereFilter(field, "null", "ne")
where_filter.apply_filter(query)
# TODO - Remove 'distinct where' logic in query class
query.setAttributes(self.fields)

log.debug("Fields for distinct filter: %s", self.fields)
except ValueError as e:
raise FilterError(e)

Expand Down

0 comments on commit e3169e1

Please sign in to comment.