-
Notifications
You must be signed in to change notification settings - Fork 50
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
Impelement get_homogeneous_pages. #87
Conversation
Unit tests forthcoming once we're directionally aligned.
sqlakeyset/paging.py
Outdated
pages = [] | ||
for i in range(len(queries)): | ||
rows = page_to_rows[i] | ||
pages.append(paging_queries[i].page_from_rows(rows)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a return pages
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Sorry about the lack of polish on this PR. Unit tests will catch them all, I just didn't want to invest in writing a bunch of tests before we knew if we'd be merging this or not :)
sqlakeyset/paging.py
Outdated
|
||
# Grab result_type and keys before adding the _page_identifier so that | ||
# it isn't included in the results. | ||
result_type = orm_result_type(query.query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these query.query
s are a little confusing, I think we should avoid overloading the word "query". Let's rename _HomogeneousPagingQuery
-> _PagingRequest
and query
-> request
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also hate this (and it's even worse above, with a q.query.query). I riffed a little on your suggestion, let me know what you think!
sqlakeyset/paging.py
Outdated
result_type = orm_result_type(query.query) | ||
keys = orm_query_keys(query.query) | ||
query.query = query.query.add_columns( | ||
sa.sql.expression.literal_column(str(page_identifier)).label("_page_identifier") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does .add_columns(page_identifier)
not work? Given that we're just trying to select an integer value and not a database column, I'm confused about the need for literal_column
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try this, but I believe literal_column is the correct way to insert a literal into a select. It also allows us to give it a label, which is convenient when we do our collation later.
sqlakeyset/paging.py
Outdated
# it isn't included in the results. | ||
result_type = orm_result_type(query.query) | ||
keys = orm_query_keys(query.query) | ||
query.query = query.query.add_columns( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we reference query.query
multiple times and then modify it, let's split it out into a separate local variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger
sqlakeyset/paging.py
Outdated
@@ -438,3 +439,87 @@ def get_page( | |||
place, backwards = process_args(after, before, page) | |||
|
|||
return orm_get_page(query, per_page, place, backwards) | |||
|
|||
|
|||
# Do we need to support python 3.6? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, we've dropped support for 3.6 already and I'm happy to drop support for 3.7 if it gives us any friction at all. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! dataclass is such a nice improvement from NamedTuple.
@@ -3,6 +3,7 @@ | |||
from __future__ import annotations | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI fails at flake8 with a bunch of undefined names - looks like you've forgotten some imports?
sqlakeyset/paging.py
Outdated
page: Optional[Union[MarkerLike, str]] = None | ||
|
||
|
||
def get_homogeneous_page(queries: list[PageRequest[_TP]]) -> list[Page[Row[_TP]]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely think it should be get_homogeneous_pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, typo!
I definitely think some version of this is worth including, since it's not achievable using our current documented public API; so thanks! I've added a bunch of minor comments in my review above, should be easy fixes. I do have a couple more significant concerns:
And yeah, bring on the tests. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm almost there, just still struggling with select_homogeneous_pages. It keeps failing trying to grab the keys. Let me know if you see something obvious, otherwise I'll keep fighting with it.
Otherwise, good for you to take another look.
sqlakeyset/paging.py
Outdated
@@ -438,3 +439,87 @@ def get_page( | |||
place, backwards = process_args(after, before, page) | |||
|
|||
return orm_get_page(query, per_page, place, backwards) | |||
|
|||
|
|||
# Do we need to support python 3.6? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! dataclass is such a nice improvement from NamedTuple.
sqlakeyset/paging.py
Outdated
page: Optional[Union[MarkerLike, str]] = None | ||
|
||
|
||
def get_homogeneous_page(queries: list[PageRequest[_TP]]) -> list[Page[Row[_TP]]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, typo!
sqlakeyset/paging.py
Outdated
pages = [] | ||
for i in range(len(queries)): | ||
rows = page_to_rows[i] | ||
pages.append(paging_queries[i].page_from_rows(rows)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Sorry about the lack of polish on this PR. Unit tests will catch them all, I just didn't want to invest in writing a bunch of tests before we knew if we'd be merging this or not :)
sqlakeyset/paging.py
Outdated
|
||
# Grab result_type and keys before adding the _page_identifier so that | ||
# it isn't included in the results. | ||
result_type = orm_result_type(query.query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also hate this (and it's even worse above, with a q.query.query). I riffed a little on your suggestion, let me know what you think!
sqlakeyset/paging.py
Outdated
# it isn't included in the results. | ||
result_type = orm_result_type(query.query) | ||
keys = orm_query_keys(query.query) | ||
query.query = query.query.add_columns( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger
sqlakeyset/paging.py
Outdated
result_type = orm_result_type(query.query) | ||
keys = orm_query_keys(query.query) | ||
query.query = query.query.add_columns( | ||
sa.sql.expression.literal_column(str(page_identifier)).label("_page_identifier") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try this, but I believe literal_column is the correct way to insert a literal into a select. It also allows us to give it a label, which is convenient when we do our collation later.
Closing in favor of #90 which I finally got working for both ORM and select. |
Unit tests forthcoming once we're directionally aligned.