Skip to content
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

Fix #930 union join bug, Add test for union join. #967

Merged
merged 4 commits into from
Oct 1, 2021

Conversation

jverswijver
Copy link
Contributor

in 0.13.2 we are improperly forming the sql query when we perform a union and then a join, below are the make_sql()'s comparing 0.13.2 to 0.12.9:

(q1 + q2).make_sql() #0.13.2
(SELECT DISTINCT `table_a`,`table_b` FROM `test`.`table_b` WHERE(table_a < 3)) 
UNION 
(SELECT DISTINCT `table_a`,`table_b` FROM `test`.`table_b` WHERE(table_a > 3))
((q1 + q2) * TableA).make_sql() #0.13.2
SELECT DISTINCT `table_a`,`table_b` 
FROM (
    SELECT DISTINCT `table_a`,`table_b` 
        FROM `test`.`table_b` 
        WHERE(table_a < 3)) as `$8` 
NATURAL JOIN (
    SELECT DISTINCT `table_a`,`table_b` FROM `test`.`table_b` 
    WHERE(table_a > 3)
    ) as `$9`
(q1 + q2).make_sql() #0.12.9
SELECT `table_a`,`table_b` 
FROM (
    SELECT `table_a`,`table_b` 
    FROM `test`.`table_b` WHERE (table_a < 3) 
    UNION 
    SELECT `table_a`,`table_b` 
    FROM `test`.`table_b` 
    WHERE (table_a > 3)
    ) as `_u4`
((q1 + q2) * TableA).make_sql() #12.9
SELECT `table_a`,`table_b` 
FROM (
    SELECT `table_a`,`table_b` 
    FROM `test`.`table_b` 
    WHERE (table_a < 3) 
    UNION 
    SELECT `table_a`,`table_b` 
    FROM `test`.`table_b` 
    WHERE (table_a > 3)
    ) as `_u5` 
NATURAL JOIN `test`.`table_a`

Below is the make_sql after I added code to fix it

((q1 + q2) * TableA).make_sql() #0.13.2 DEV
SELECT DISTINCT `table_a`,`table_b` 
FROM (
    (SELECT DISTINCT `table_a`,`table_b` FROM `test`.`table_b` WHERE(table_a < 3)) 
    UNION 
    (SELECT DISTINCT `table_a`,`table_b` FROM `test`.`table_b` WHERE(table_a > 3))
    ) as `$8` 
NATURAL JOIN 
(SELECT DISTINCT `table_a` FROM `test`.`table_a`) as `$9`

I think this solution is good but I have included all the make_sql()'s to ensure that my solution did not introduce any unintended consequences.

fix #930

@jverswijver jverswijver marked this pull request as ready for review September 24, 2021 16:35
tests/test_aggr_regressions.py Outdated Show resolved Hide resolved
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 🎉 Woohoo! Nice work with this contribution! 🎉

@guzman-raphael guzman-raphael merged commit a1d27f3 into datajoint:master Oct 1, 2021
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.

AssertionError in using UNION and JOIN - DataJoint 0.13.* error
3 participants