-
Notifications
You must be signed in to change notification settings - Fork 298
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
feat: Support limiting row count and offsets in Oracle queries #754
feat: Support limiting row count and offsets in Oracle queries #754
Conversation
Add support for [Oracle's syntax](https://www.oracletutorial.com/oracle-basics/oracle-fetch/) for limiting the row count returned in a 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.
Looks good. Thanks for working on this
Absolutely! My pleasure. One observation is that @builder
def fetch_next(self, limit: int) -> "MSSQLQueryBuilder":
# Overridden to provide a more domain-specific API for T-SQL users
self._limit = limit
...
def _limit_sql(self) -> str:
return " FETCH NEXT {limit} ROWS ONLY".format(limit=self._limit) Would we want to use that with |
To be honest, I am not very well familiar with the code and have myself not used this library so far Having said that, I see a difference of "FETCH FIRST" and "FETCH NEXT" between these. How will that be handled? I believe it is not very clear theoretically if |
Good question - And yes, a mixin is also exactly what I was thinking (composability > inheritance for this IMO unless MSSQL and Oracle have more in common than we know). I considered adding it, but I wasn't sure if that was overkill or violated any design guidelines within the library. I am open to adding it though - something like: class FetchNextMixin:
@builder
def fetch_next(self, limit: int) -> "MSSQLQueryBuilder":
self._limit = limit
def _limit_sql(self) -> str:
return " FETCH NEXT {limit} ROWS ONLY".format(limit=self._limit) I think my follow-up question would be if we went that route, how to approach the |
Hey @AzisK , just wanted to follow-up on this. I think we have a few options for a path forward:
I think I'm in favor of the third design. |
I am in favor of 3rd design as well. My arguments that this is beneficial are following. First of all, in this way users can easily switch between data sources and the API will work correctly and accordingly to the source of data or dialect in this sense. Secondly, this library simplifies building SQL queries with the API, so let's keep it simple. Supporting another API keyword for the same functionality but for a different platform makes it more complicated. Thirdly, word "limit" expresses clearly what is being done. |
Hello @AzisK ! I hope all is going well. I made the changes and wound up making a few more around supporting the offset syntax, as detailed in the updated PR description. Please take a look when you get the chance. 😄 |
Hi @AzisK ! Just wanted to follow-up on this. |
Hi @danielenricocahall I will look into it shortly |
Hi @AzisK ! I hope all is going well! Any chance we could merge this soon? |
1 similar comment
Hi @AzisK ! I hope all is going well! Any chance we could merge this soon? |
Hi @danielenricocahall. Happy New Year! 😅 I will ask one more person to take a look into it and he is much more active than I am and then things will hopefully go smooth. Sorry for taking so long @wd60622 could you take a look? |
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 not super versed in the two SQL flavors but am coming from just code perspective. Just comment on deprecating fetch_next
method and making sure the CI/CD and test suite run
Other than that, look good! Thanks for the edits
@wd60622 addressed your comments! |
Seems like the tests that ran were good. Is there an issue with the coveralls version @AzisK ? |
I could see this error before as a hiccup of Github Actions. For some reason it does not succeed after a re-run |
Yeah, I believe we can bump the coveralls library and hopefully that will fix it |
Out of my wheelhouse, sorry. @AzisK will have to take care of it |
For some reason, I don't see an option to rerun... |
Hi @AzisK I just merged master into my branch and it's pending re-running CI. Could you approve? |
Add support for Oracle's syntax for limiting the row count returned in a query by overriding the
_limit_sql
method inOracleQueryBuilder
, as well the offset syntax (_offset_sql
).As these are identical to the
MSSQL
syntax, I created a new subclass ofQueryBuilder
calledFetchNextAndOffsetRowsQueryBuilder
(admittedly not the most clever name) which overrides the two methods, and now haveOracleQueryBuilder
andMSSQLQueryBuilder
subclass from them.I also overrode the
_apply_pagination
method in theOracleQueryBuilder
to ensure that offset and fetch next are arranged in the correct order for Oracle queries. That override is similar toMSSQLQueryBuilder
's implementation, but as Oracle doesn't have the same constraint of aFETCH NEXT
requiring anOFFSET _ ROWS
, it's not identical, I opted to keep them separated.