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

Support nullable columns on Right Join and Full Join #626

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

griffio
Copy link
Contributor

@griffio griffio commented May 5, 2024

To enable a fix in sqldelight/sqldelight#5136

Tested locally and in SqlDelight using snapshot build

For unit testing in sql-psi, the sql.bnf grammar would have to include right and full joins - however, not all databases dialects support full joins, sqlite recently added right joins. Actual tests would have to be added to SqlDelight with a supporting grammar such as Postgresql.

Implementation

💇‍♂️ The existing code present in queryExposed is worked around rather than a complete re-write

🤐 Uses zipWithNext to create a pair of table queries, if there are joins present in the query. These joins could be inner joins or outer joins. Only outer joins are copied with the nullable field set to true.

👥 From each pair, when there is a right or full join the first query columns are copied with nullability, any left or full join nullability columns are produced on the second query columns

This produces duplicate QueryResult columns and
queryAvailable.associateBy { it.table }.values is used to remove the duplicate columns

SELECT A.*, B.*
FROM A LEFT JOIN B USING (id);

LEFT JOINS nulls on right expected and does so in table data interface

id val1 val2
1 a null
2 b null
SELECT A.*, B.*
FROM A RIGHT JOIN B USING (id);

RIGHT JOINS nulls on left side expected and does have nullable types for A fields

id val1 val2
11 null a
21 null b
SELECT A.*, B.*
FROM A FULL JOIN B USING (id);

FULL JOINS nulls on both sides expected and does have nullable types for A, B fields

id val1 val2
1 a null
2 b null
11 null a
21 null b

Uses zipWithNext to create a pair of table queries, if there are joins

From each pair, when there is a right or full join the first query columns are copied with nullability, any left or full join nullability columns are produced

This produces duplicate QueryResult columns and
queryAvailable.associateBy { it.table }.values is used to remove the duplicate columns
@griffio griffio marked this pull request as ready for review May 6, 2024 08:36
@AlecKazakova AlecKazakova merged commit 502a1dc into sqldelight:master Aug 6, 2024
1 check passed
@AlecKazakova
Copy link
Collaborator

thank you!

@griffio griffio deleted the fix-outer-join-nullability branch August 6, 2024 15:24
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.

2 participants