Skip to content

Commit e3c8903

Browse files
authored
add test for join queries with in predicate (#3698)
1 parent f47d9a8 commit e3c8903

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

yaml-tests/src/test/resources/join-tests.yamsql

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,89 @@ test_block:
9595
- unorderedResult: [{"Engineering", "OLAP"},
9696
{"Sales", "Feedback"},
9797
{"Marketing", "SEO"}]
98+
-
99+
# Join with NOT IN - get employees in Engineering excluding specific employee ids
100+
- query: select emp.id, fname, lname from emp, dept where emp.dept_id = dept.id and dept.name = 'Engineering' and emp.id not in (1, 3)
101+
- unorderedResult: [{ID: 2, FNAME: "Thomas", LNAME: "Johnson"},
102+
{ID: 4, FNAME: "Amelia", LNAME: "Johnson"}]
103+
-
104+
# Join with NOT IN - get projects excluding certain project ids
105+
- query: select project.id, project.name from emp, project where project.emp_id = emp.id and project.id not in (1, 2)
106+
- unorderedResult: [{ID: 3, NAME: "Feedback"}]
107+
-
108+
# Three-way join with NOT IN - departments with projects, excluding specific departments
109+
- query: select dept.id, dept.name, project.name from emp, dept, project where emp.dept_id = dept.id and project.emp_id = emp.id and dept.id not in (1)
110+
- unorderedResult: [{ID: 2, "Sales", "Feedback"},
111+
{ID: 3, "Marketing", "SEO"}]
112+
-
113+
# Join with NOT IN - employees in Sales department excluding specific ids
114+
- query: select emp.id from emp, dept where emp.dept_id = dept.id and dept.id = 2 and emp.id not in (5, 6)
115+
- unorderedResult: [{7}]
116+
-
117+
# Join with NOT IN - all employees except those in excluded departments
118+
- query: select emp.id, fname from emp, dept where emp.dept_id = dept.id and dept.id not in (1, 3)
119+
- unorderedResult: [{ID: 5, FNAME: "Daniel"},
120+
{ID: 6, FNAME: "Chloe"},
121+
{ID: 7, FNAME: "Charlotte"}]
122+
-
123+
# Join with NOT IN on non-existent values (should return all matching rows)
124+
- query: select emp.id from emp, dept where emp.dept_id = dept.id and dept.id = 1 and emp.id not in (10, 20, 30)
125+
- unorderedResult: [{1}, {2}, {3}, {4}]
126+
-
127+
# Subquery join with NOT IN
128+
- query: select fname, lname from (select fname, lname, emp.id from emp, dept where emp.dept_id = dept.id and dept.name = 'Engineering') as sq where sq.id not in (1, 4)
129+
- unorderedResult: [{"Thomas", "Johnson"},
130+
{"Emily", "Martinez"}]
131+
-
132+
# Join with multiple NOT IN conditions
133+
- query: select project.id, project.name from emp, dept, project where emp.dept_id = dept.id and project.emp_id = emp.id and dept.id not in (3) and project.id not in (3)
134+
- unorderedResult: [{ID: 1, NAME: "OLAP"}]
135+
-
136+
# Join with IN - get specific employees in Engineering
137+
- query: select emp.id, fname, lname from emp, dept where emp.dept_id = dept.id and dept.name = 'Engineering' and emp.id in (1, 3)
138+
- unorderedResult: [{ID: 1, FNAME: "Jack", LNAME: "Williams"},
139+
{ID: 3, FNAME: "Emily", LNAME: "Martinez"}]
140+
-
141+
# Join with IN - get specific projects
142+
- query: select project.id, project.name from emp, project where project.emp_id = emp.id and project.id in (1, 2)
143+
- unorderedResult: [{ID: 1, NAME: "OLAP"},
144+
{ID: 2, NAME: "SEO"}]
145+
-
146+
# Three-way join with IN - departments with projects, including only specific departments
147+
- query: select dept.id, dept.name, project.name from emp, dept, project where emp.dept_id = dept.id and project.emp_id = emp.id and dept.id in (1, 2)
148+
- unorderedResult: [{ID: 1, "Engineering", "OLAP"},
149+
{ID: 2, "Sales", "Feedback"}]
150+
-
151+
# Join with IN - employees in specific departments
152+
- query: select emp.id, fname from emp, dept where emp.dept_id = dept.id and dept.id in (2, 3)
153+
- unorderedResult: [{ID: 5, FNAME: "Daniel"},
154+
{ID: 6, FNAME: "Chloe"},
155+
{ID: 7, FNAME: "Charlotte"},
156+
{ID: 8, FNAME: "Megan"},
157+
{ID: 9, FNAME: "Harry"}]
158+
-
159+
# Join with IN - single value in list
160+
- query: select emp.id, fname, lname from emp, dept where emp.dept_id = dept.id and dept.id = 1 and emp.id in (2)
161+
- unorderedResult: [{ID: 2, FNAME: "Thomas", LNAME: "Johnson"}]
162+
-
163+
# Join with IN - employees in Sales department with specific ids
164+
- query: select emp.id from emp, dept where emp.dept_id = dept.id and dept.id = 2 and emp.id in (5, 6, 7)
165+
- unorderedResult: [{5}, {6}, {7}]
166+
-
167+
# Subquery join with IN
168+
- query: select fname, lname from (select fname, lname, emp.id from emp, dept where emp.dept_id = dept.id and dept.name = 'Engineering') as sq where sq.id in (1, 4)
169+
- unorderedResult: [{"Jack", "Williams"},
170+
{"Amelia", "Johnson"}]
171+
-
172+
# Join with both IN and NOT IN conditions
173+
- query: select emp.id, fname from emp, dept where emp.dept_id = dept.id and dept.id in (1, 2) and emp.id not in (1, 5)
174+
- unorderedResult: [{ID: 2, FNAME: "Thomas"},
175+
{ID: 3, FNAME: "Emily"},
176+
{ID: 4, FNAME: "Amelia"},
177+
{ID: 6, FNAME: "Chloe"},
178+
{ID: 7, FNAME: "Charlotte"}]
179+
-
180+
# Join with IN on non-existent values (should return empty)
181+
- query: select emp.id from emp, dept where emp.dept_id = dept.id and dept.id = 1 and emp.id in (10, 20, 30)
182+
- result: []
98183
...

0 commit comments

Comments
 (0)