forked from brynary/arel
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
Support Oracle 12c top-N query #319
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
support using `FETCH FIRST n ROWS` and `OFFSET` for Oracle 12c database
This commit simply removes duplicated code by reusing the existing `maybe_visit` method.
😓 I don't know why the tests did not fail, but to keep the same syntax as before, `collector =` is required. Maybe `visit` changes `collector` in-place, so the result is the same, but since I'm not sure about the side effects, I think this PR is needed to. Sorry! 😓
These methods are going to go through some heavy refactoring, and moving logic around. This adds missing tests for each of the branches on the predicate.
Currently, doing ```ruby relation[:id].not_eq(4).and(relation[:id].not_in(1..3)) ``` will generate ```sql "id" != 4 AND "id" < 1 OR "id" > 3 ``` Which would incorrectly include records with an id of 4, as the OR statement has higher precidence than the AND statement. The `or` method on `Node` properly groups the statement in parenthesis.
These methods duplicate a lot of logic from the other predications. We can just use those methods directly, and only build nodes with the same name in our method directly. We've already had one bug that came from building nodes directly, rather than using the proper predicate.
The goal of these methods should be to generate in nodes, not handle every possible permutation of more than one value. The `#between` and `#not_between` methods have been extracted, which better represent the semantics of handling ranges in SQL.
Given that we are going to remove casting from Arel in the near future, having a single place nodes in predications will help.
This reverts commit 9b92af7. beta2 is out, and we've fixed the issue that this caused in Rails
It's not quite duck typed, but it will allow us to pass in our own objects with additional logic (like type casting).
Failed to merge master branch. will close this pull request. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request has two separate commits to support Oracle 12c better Top N query support using
FETCH FIRST n ROWS ONLY
andOFFSET n ROWS
.8f5e57f Extract visit_Arel_Nodes_SelectOptions
It extracts
visit_Arel_Nodes_SelectOptions
fromvisit_Arel_Nodes_SelectStatement
method to prepare Oracle 12c support since it will be able to reuse most of super'svisit_Arel_Nodes_SelectStatement
method because Oracle requires to add collector in the following order.Unlike other database require in this order.
This method is not called using visitor pattern, I'd like to hear
visit_Arel_Nodes_SelectOptions
is an appropreate method name.371b642 Create Arel::Visitors::Oracle12 to provide better top-N query
Oracle Database 12c introduces better top-N query support using
FETCH FIRST n ROWS ONLY
andOFFSET n ROWS
. Also to support older version of Oracle 11gR2 or lower version, this commit createsanother visitor named
Arel::Visitors::Oracle12
, 12 comes from the database version.By changing oracle enhanced adapter as follows to execute each Arel visitor based on
if this top-n query feature supported. yahonda/oracle-enhanced@fcb22db
It looks
Arel::Visitors
just allows 1 database adapter to have 1 visitor, but my implementation works to switch two visitors just changingArel::Visitors::Oracle12
orArel::Visitors::Oracle
based on its database version. It looks 1 database adapter can have 2 or more visitor(s). Are these lines can be removed?https://github.com/yahonda/arel/blob/a19190ab06db4d68765fb08ec1a4dc6c8ebb2eb5/lib/arel/visitors.rb#L15-L41