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.
missing a return pages?
There was a problem hiding this comment.
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.
All these query.querys 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.
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.
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.
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.
Since we reference query.query multiple times and then modify it, let's split it out into a separate local variable.
sqlakeyset/paging.py
Outdated
| return orm_get_page(query, per_page, place, backwards) | ||
|
|
||
|
|
||
| # Do we need to support python 3.6? |
There was a problem hiding this comment.
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.
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.
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.
I definitely think it should be get_homogeneous_pages.
|
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. :) |
mattalbr
left a comment
There was a problem hiding this comment.
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
| return orm_get_page(query, per_page, place, backwards) | ||
|
|
||
|
|
||
| # Do we need to support python 3.6? |
There was a problem hiding this comment.
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]]]: |
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.
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.
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( |
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.
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.