Skip to content
Prev Previous commit
Next Next commit
get_filter_metadata also returns encoding size
  • Loading branch information
wilko committed Feb 17, 2020
commit fa8d267595a1665e3ee84b75253ee634ae647ae2
18 changes: 11 additions & 7 deletions backend/entityservice/database/selections.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,32 +260,36 @@ def get_dataprovider_id(db, update_token):
return query_db(db, sql_query, [update_token], one=True)['id']


def get_bloomingdata_column(db, dp_id, column):
assert column in {'ts', 'token', 'file', 'state', 'count'}
def get_bloomingdata_columns(db, dp_id, columns):
for column in columns:
assert column in {'ts', 'token', 'file', 'state', 'count', 'encoding_size'}
sql_query = """
SELECT {}
FROM bloomingdata
WHERE dp = %s
""".format(column)
""".format(', '.join(columns))
result = query_db(db, sql_query, [dp_id], one=True)
if result is None:
raise DataProviderDeleted(dp_id)
else:
return result[column]
if len(columns) > 1:
return [result[column] for column in columns]
else:
return result[columns[0]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% enjoying returning a different type for convenience when there is only one column. I get it & I've done it I just don't like it.



def get_filter_metadata(db, dp_id):
"""
:return: The filename of the raw clks.
:return: The filename and the encoding size of the raw clks.
"""
return get_bloomingdata_column(db, dp_id, 'file').strip()
return [s.strip() for s in get_bloomingdata_columns(db, dp_id, ['file', 'encoding_size'])]


def get_number_of_hashes(db, dp_id):
"""
:return: The count of the uploaded encodings.
"""
return get_bloomingdata_column(db, dp_id, 'count')
return get_bloomingdata_columns(db, dp_id, ['count'])


def get_project_schema_encoding_size(db, project_id):
Expand Down