Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/generate query for benchmarking #38

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/matchbox/server/postgresql/benchmark/generate_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from matchbox.client.helpers.selector import query, selector


# Generates a query that can be used for benchmarking purposes
def generate_query(crn, fields, backend, resolution, return_type):
select_crn = selector(
table=str(crn),
fields=fields,
engine=crn.database.engine,
)

query_string = query(
selector=select_crn,
backend=backend,
resolution=resolution,
return_type=return_type,
)

return query_string


if __name__ == "__main__":
query = ""
# vars: crn, fields, backend, resolution, return_type
# query = generate_query(crn, fields, backend, resolution, return_type)
print(query)
6 changes: 4 additions & 2 deletions src/matchbox/server/postgresql/utils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ def query(
# Get cluster assignments
mb_ids = sql_to_df(id_query, engine, return_type="arrow")

query_string = str(id_query)

# Get source data
raw_data = source.to_arrow(
fields=set([source.db_pk] + fields),
Expand All @@ -379,14 +381,14 @@ def query(

# Return in requested format
if return_type == "arrow":
return result
return result, query_string
elif return_type == "pandas":
return result.to_pandas(
use_threads=True,
split_blocks=True,
self_destruct=True,
types_mapper=ArrowDtype,
)
), query_string
else:
raise ValueError(f"return_type of {return_type} not valid")

Expand Down
Loading