Skip to content

Conversation

jverswijver
Copy link
Contributor

Added handling for when union gets a union object inside its make_sql(), this allows you to do multiple unions.
Took the test from @guzman-raphael comments on the issue linked.

fix #926

@jverswijver jverswijver marked this pull request as ready for review September 20, 2021 21:39
@jverswijver
Copy link
Contributor Author

Seems the test coverage api we use is experiencing a major outage, tests all pass locally. We can run the github actions when they are back up (outage information).

Copy link
Collaborator

@guzman-raphael guzman-raphael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jverswijver Nice work on this one man! 🚀
Only small suggestions included but overall fix looks great.

Comment on lines 515 to 517
x = set(zip(*q1.fetch('i', 'j')))
y = set(zip(*q2.fetch('i', 'j')))
assert_set_equal(x, y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the lessons I learned earlier from the recursive comparison within lists discussion, we can simplify this now to:

Suggested change
x = set(zip(*q1.fetch('i', 'j')))
y = set(zip(*q2.fetch('i', 'j')))
assert_set_equal(x, y)
assert q1.fetch() == q2.fetch()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break the test, I get this error when running it:
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION (SELECT DISTINCT `i`,`j` FROM `djtest_relational`.`#i_j` WHERE((`j`=2) AND' at line 1")
The other changes work fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jverswijver Just tagged up on this point and looks like this test should have passed. Must still be something missing with this fix. Let me know once you've pinpointed the problem/solution. Thanks 🤝

jverswijver and others added 2 commits September 27, 2021 08:29
Co-authored-by: Raphael Guzman <38401847+guzman-raphael@users.noreply.github.com>
Comment on lines 515 to 517
x = set(zip(*q1.fetch('i', 'j')))
y = set(zip(*q2.fetch('i', 'j')))
assert_set_equal(x, y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jverswijver Just tagged up on this point and looks like this test should have passed. Must still be something missing with this fix. Let me know once you've pinpointed the problem/solution. Thanks 🤝

@jverswijver jverswijver marked this pull request as draft October 1, 2021 18:32
@A-Baji
Copy link
Collaborator

A-Baji commented Feb 9, 2022

It seems mysql does not support nested unions in 5.7. In 8.0 the issue is semi fixed where it allows left side nested unions, but throws a specific error for unsupported right side nested unions. However, there is a workaround for both versions where wrapping the query and all sub queries in a SELECT * FROM () and then adding an alias allows the query to execute properly.

@jverswijver jverswijver marked this pull request as ready for review February 9, 2022 16:57

def where_clause(self):
return '' if not self.restriction else ' WHERE(%s)' % ')AND('.join(
return '' if not self.restriction else ' WHERE (%s)' % ')AND('.join(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really need the extra space but no big deal

Copy link
Collaborator

@guzman-raphael guzman-raphael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jverswijver @A-Baji 🚀 Excellent job guys and great collab! 🚀

It is too bad that MySQL has such nuances in working with unions but glad we were able to workaround them to achieve full union nesting support.

@guzman-raphael guzman-raphael merged commit 8115393 into datajoint:master Feb 9, 2022
@renniek
Copy link

renniek commented Nov 12, 2024

Hi there,

I am using datajoint version 0.13.7, and so I think this should be fixed based on what I've seen online for the different versions, but I am still getting this error when I try to do a union on more than 2 tables. Any advice? Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot form the union of more than two tables
5 participants