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

Add support for new features on query results #111

Merged
merged 4 commits into from
Mar 4, 2024
Merged

Conversation

RichardKeo
Copy link
Collaborator

@RichardKeo RichardKeo commented Mar 1, 2024

Add support for a few features that will soon become available when retrieving query results:

  • specify the output columns
  • get a sample of the results
  • filter out some rows before retrieve the results
  • sort the results

Add support for a few features that will soon become available when
retrieving query results:
  - specify the output columns
  - get a sample of the results
  - filter out some rows before retrieve the results
  - sort the results
@RichardKeo RichardKeo changed the title Sync client: Add support for new features on query results Add support for new features on query results Mar 1, 2024
Copy link
Member

@TheEdgeOfRage TheEdgeOfRage left a comment

Choose a reason for hiding this comment

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

There's a few more places with asserts that I think are duplicate. Please check

if filters is not None:
params["filters"] = filters
if sort_by is not None and len(sort_by) > 0:
params["sort_by"] = ",".join(sort_by)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't you want to do the escaping here too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this will be the user's responsibility since we can't reliably do it. The way they'll specify the order is something like this:

sort_by=['column_1', '"column 2" DESC', '"column\\" 3" ASC']

This should then get converted to the following:

column_1,"column 2" DESC,"column\\" 3" ASC

Copy link
Member

Choose a reason for hiding this comment

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

Ah makes sense. We'll have to check for SQL injection then tho, right?

Comment on lines +62 to +67
assert (
# We are not sampling
sample_count is None
# We are sampling and don't use filters or pagination
or (batch_size is None and filters is None)
), "sampling cannot be combined with filters or pagination"
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this already covered by the assert on the build params function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would, but it would only run after the refresh

Comment on lines +104 to +109
assert (
# We are not sampling
sample_count is None
# We are sampling and don't use filters or pagination
or (batch_size is None and filters is None)
), "sampling cannot be combined with filters or pagination"
Copy link
Member

Choose a reason for hiding this comment

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

Same

@RichardKeo RichardKeo marked this pull request as ready for review March 4, 2024 11:23
Copy link
Collaborator

@msf msf left a comment

Choose a reason for hiding this comment

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

minor improvements suggested.

  1. fix link to API docs (updated)
  2. add link to API docs on public function docstrings
  3. default values for sample+limit+offset on _build_parameters()

dune_client/api/execution.py Outdated Show resolved Hide resolved
dune_client/api/extensions.py Outdated Show resolved Hide resolved
@@ -114,6 +179,14 @@ def get_latest_result(
:param max_age_hours: re-executes the query if result is older than max_age_hours
https://dune.com/docs/api/api-reference/get-results/latest-results
Copy link
Collaborator

Choose a reason for hiding this comment

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

update link to docs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will follow up in a separate PR to update all links to the docs (we do have a redirect tho)

dune_client/client_async.py Show resolved Hide resolved
dune_client/api/base.py Show resolved Hide resolved
@RichardKeo RichardKeo merged commit 1f33260 into main Mar 4, 2024
3 checks passed
@RichardKeo RichardKeo deleted the filters-and-more branch March 4, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants