Skip to content

Commit

Permalink
test: add e2e tests for natural join and cross join (risingwavelabs#8948
Browse files Browse the repository at this point in the history
)
  • Loading branch information
neverchanje authored Apr 4, 2023
1 parent 35f7c0c commit 5d8c0b4
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
55 changes: 55 additions & 0 deletions e2e_test/batch/join/natural_and_cross_join.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Test setup
statement ok
CREATE TABLE employees (
id INTEGER,
employee_name VARCHAR,
department_id INTEGER
);

statement ok
CREATE TABLE departments (
department_name VARCHAR,
department_id INTEGER
);

statement ok
INSERT INTO employees (id, employee_name, department_id) VALUES
(1, 'Alice', 1),
(2, 'Bob', 2),
(3, 'Charlie', 1);

statement ok
INSERT INTO departments (department_name, department_id) VALUES
('Engineering', 1),
('HR', 2);

statement ok
flush

query TT rowsort
SELECT e.employee_name, d.department_name
FROM employees e NATURAL JOIN departments d
ORDER BY employee_name;
----
Alice Engineering
Bob HR
Charlie Engineering

# Test cross join
query TT rowsort
SELECT e.employee_name, d.department_name
FROM employees e CROSS JOIN departments d
ORDER BY e.employee_name, d.department_name;
----
Alice Engineering
Alice HR
Bob Engineering
Bob HR
Charlie Engineering
Charlie HR

statement ok
DROP TABLE employees;

statement ok
DROP TABLE departments;
59 changes: 59 additions & 0 deletions e2e_test/streaming/natural_and_cross_join.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Test setup
statement ok
CREATE TABLE employees (
id INTEGER,
employee_name VARCHAR,
department_id INTEGER
);

statement ok
CREATE TABLE departments (
department_name VARCHAR,
department_id INTEGER
);

statement ok
INSERT INTO employees (id, employee_name, department_id) VALUES
(1, 'Alice', 1),
(2, 'Bob', 2),
(3, 'Charlie', 1);

statement ok
INSERT INTO departments (department_name, department_id) VALUES
('Engineering', 1),
('HR', 2);

# Create materialized view with NATURAL JOIN
statement ok
CREATE MATERIALIZED VIEW employee_department_natural_join AS
SELECT e.employee_name, d.department_name
FROM employees e NATURAL JOIN departments d
ORDER BY employee_name;

# Nested-loop joins are not supported in the streaming mode.
statement error
CREATE MATERIALIZED VIEW employee_department_cross_join AS
SELECT e.employee_name, d.department_name
FROM employees e CROSS JOIN departments d
ORDER BY e.employee_name, d.department_name;

statement ok
flush

# Test NATURAL JOIN
query TT rowsort
SELECT employee_name, department_name FROM employee_department_natural_join;
----
Alice Engineering
Bob HR
Charlie Engineering

# Cleanup
statement ok
DROP MATERIALIZED VIEW employee_department_natural_join;

statement ok
DROP TABLE employees;

statement ok
DROP TABLE departments;

0 comments on commit 5d8c0b4

Please sign in to comment.