rails / arel

A Relational Algebra
2.06k stars 390 forks source link

Make union/except/intersect chainable #519

Closed fatkodima closed 6 years ago

fatkodima commented 6 years ago

Fixes https://github.com/rails/arel/pull/118.

This is an updated and changed/simplified version of https://github.com/rails/arel/pull/320. The idea remains the same (SelectManager returns a new SelectManager on calls to union/intersect/except with, basically speaking, N-ary Union/Intersect/Excepts taking place of SelectCores inside SelectStatement).

TOP related code for SelectStatement was removed because it is basically a noop operation and will require implement also noop method for Union/.../... classes to work here https://github.com/rails/arel/blob/df2b74b53664cc3ce3a49156c555b84c134bb75a/lib/arel/select_manager.rb#L224

Also, squashing braces in unions for MySQL was removed to allow applying limits and orders for individual queries. As stated in documentation:

To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses that enclose the SELECT.

Note: Previous versions of MySQL may permit such statements without parentheses. In MySQL 5.7, the requirement for parentheses is enforced.

But was introduced for SQLite, as it has troubles with parenthesized union subqueries and ordering + limits in them.

I'm also wondering, should all changed behavior be extensively deprecated or this PR can be merged in the next major version without any?

rails-bot commented 6 years ago

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @tenderlove (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

matthewd commented 6 years ago

Per #523, Arel development is moving to rails/rails.

If this PR is still relevant, please consider reopening it over there.