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

Fixes join test cases #125

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Fixes join test cases #125

merged 1 commit into from
Aug 27, 2024

Conversation

johnedquinn
Copy link
Member

Description

Picked out the relevant ones from #122. See the description there.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -363,7 +364,8 @@ select_join::[
result:EvaluationSuccess,
Copy link
Contributor

Choose a reason for hiding this comment

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

This test logically corresponds to something like:

CREATE TABLE Stores (
    id int
);

CREATE TABLE Books (
    id int,
    title varchar(255),
  	price real
);

INSERT INTO Stores (id) VALUES (5), (6), (7);
INSERT INTO Books (id, title, price) VALUES 
    (5, 'A', 5.0), (5, 'B', 2.0), (5, 'C', 7.0), (5, 'D', 9.0),
    (6, 'A', 5.0), (6, 'E', 9.50), (6, 'F', 10.0);

SELECT s.id AS id, b.title AS title 
FROM Stores AS s LEFT OUTER JOIN Books AS b ON s.id = b.id AND b.price > 9

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's a corresponding DB Fiddle.

Comment on lines 350 to 357
result:EvaluationSuccess,
output:$bag::[
{
id:"7"
id:"7",
title: null
}
]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This test logically corresponds to something like:

CREATE TABLE Stores (
    id int
);

CREATE TABLE Books (
    id int,
    title varchar(255),
  	price real
);

INSERT INTO Stores (id) VALUES (5), (6), (7);
INSERT INTO Books (id, title, price) VALUES 
    (5, 'A', 5.0), (5, 'B', 2.0), (5, 'C', 7.0), (5, 'D', 9.0),
    (6, 'A', 5.0), (6, 'E', 9.50), (6, 'F', 10.0);

SELECT s.id AS id, b.title AS title 
FROM Stores AS s LEFT OUTER JOIN Books AS b ON 1=1 AND s.id = b.id  
WHERE b.* IS NULL

Based on the logic that:

  • <x> LEFT CROSS JOIN <y> can be modeled as <x> LEFT OUTER JOIN <y> ON 1=1
  • Since the <y> is a corellated value from <x>, we add the <x>.id = <y>.id to the ON

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's a corresponding DB Fiddle.

@@ -657,7 +657,9 @@ join::[
name:"ee",
s2_n:42,
s2_2:2,
_4:null
Copy link
Contributor

Choose a reason for hiding this comment

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

This test logically corresponds to something like (I didn't rewrite the query, just added SQL tables):

CREATE TABLE t2 (
    name varchar(255),
    n int
);

CREATE TABLE t3 (
    name varchar(255),
    n int
);

INSERT INTO t2 (name, n) VALUES 
	('bb', 12), ('cc', 22), ('ee', 42);
INSERT INTO t3 (name, n) VALUES 
	('bb', 13), ('cc', 23), ('dd', 33);

SELECT * 
FROM 
		(SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2 
    LEFT JOIN 
	    (SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3 ON s2.name = s3.name

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly. Here's a corresponding DB Fiddle.

@@ -593,7 +593,7 @@ join::[
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This test logically corresponds to something like (I didn't rewrite the query, just added SQL tables):

CREATE TABLE t2 (
    name varchar(255),
    n int
);

CREATE TABLE t3 (
    name varchar(255),
    n int
);

INSERT INTO t2 (name, n) VALUES 
	('bb', 12), ('cc', 22), ('ee', 42);
INSERT INTO t3 (name, n) VALUES 
	('bb', 13), ('cc', 23), ('dd', 33);

SELECT * 
FROM 
		(SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2 
    LEFT JOIN 
	    (SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3 ON s2.name = s3.name

And here we assert the result is

<< 
    {'name': 'bb', 'n': 12, 'name':'bb', 'b':13},
    {'name': 'cc', 'n': 22, 'name':'cc', 'b':23},
    {'name': 'ee', 'n': 42, _2:null},
>>

The SQL-equivalent result might be encoded as

<< 
    {'name': 'bb', 'n': 12, 'name':'bb', 'b':13},
    {'name': 'cc', 'n': 22, 'name':'cc', 'b':23},
    {'name': 'ee', 'n': 42, 'name':null, 'n':null},
>>

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly. Here's a corresponding DB Fiddle.

@johnedquinn johnedquinn merged commit 058bdde into main Aug 27, 2024
4 checks passed
@johnedquinn johnedquinn deleted the main-fix-joins branch August 27, 2024 22:35
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