Skip to content

Commit

Permalink
test: add test for View
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Nov 3, 2024
1 parent bda05b9 commit 55f8250
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 92 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ let fnck_sql = DataBaseBuilder::path("./data")
- Create
- [x] Table
- [x] Index: Unique\Normal\Composite
- [x] View
- Drop
- [x] Table
- [ ] Index
- [ ] View
- Alert
- [x] Add Column
- [x] Drop Column
Expand Down
2 changes: 1 addition & 1 deletion src/binder/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl<'a: 'b, 'b, T: Transaction> Binder<'a, 'b, T> {
SelectItem::UnnamedExpr(expr) => select_items.push(self.bind_expr(expr)?),
SelectItem::ExprWithAlias { expr, alias } => {
let expr = self.bind_expr(expr)?;
let alias_name = alias.to_string();
let alias_name = alias.value.to_lowercase();

self.context
.add_alias(None, alias_name.clone(), expr.clone());
Expand Down
40 changes: 20 additions & 20 deletions tests/slt/crdb/delete.slt
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ SELECT * FROM kv
5 6
7 8

# TODO: View
# TODO: Drop View
# statement ok
# drop view if exists kview

# statement ok
# CREATE VIEW kview AS SELECT k,v FROM kv
statement ok
CREATE VIEW kview AS SELECT k,v FROM kv

# query II
# SELECT * FROM kview
# ----
# 1 2
# 3 4
# 5 6
# 7 8
query II
SELECT * FROM kview
----
1 2
3 4
5 6
7 8

# statement error 1002
# DELETE FROM kview
statement error
DELETE FROM kview

# query II
# SELECT * FROM kview
# ----
# 1 2
# 3 4
# 5 6
# 7 8
query II
SELECT * FROM kview
----
1 2
3 4
5 6
7 8

statement ok
DELETE FROM kv WHERE k=3 OR v=6
Expand Down Expand Up @@ -167,7 +167,7 @@ statement ok
drop table if exists family

statement ok
CREATE TABLE family ( x INT PRIMARY KEY, y INT)
CREATE TABLE family ( x INT PRIMARY KEY, y INT)

statement ok
INSERT INTO family VALUES (1, 1), (2, 2), (3, 3)
Expand Down
5 changes: 2 additions & 3 deletions tests/slt/sql_2016/F031_02.slt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# F031-02: CREATE VIEW statement

# TODO: Support `VIEW`

statement ok
CREATE TABLE TABLE_F031_02_01_01 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F031_02_01_01 AS SELECT A FROM TABLE_F031_02_01_01
statement ok
CREATE VIEW VIEW_F031_02_01_01 AS SELECT A FROM TABLE_F031_02_01_01
5 changes: 3 additions & 2 deletions tests/slt/sql_2016/F031_16.slt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# F031-16: DROP VIEW statement: RESTRICT clause

# TODO: Support `VIEW` & `CREATE VIEW` & `DROP VIEW`
# TODO: Support `DROP VIEW`

statement ok
CREATE TABLE TABLE_F031_16_01_01 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F031_16_01_01 AS SELECT A FROM TABLE_F031_16_01_01;
statement ok
CREATE VIEW VIEW_F031_16_01_01 AS SELECT A FROM TABLE_F031_16_01_01;

# DROP VIEW VIEW_F031_16_01_01
10 changes: 6 additions & 4 deletions tests/slt/sql_2016/F081.slt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# F081: UNION and EXCEPT in views

# TODO: VIEW & (UNION & EXCEPT with VIEW)

statement ok
CREATE TABLE TABLE_F081_01_011 ( ID INT PRIMARY KEY, A INTEGER );

statement ok
CREATE TABLE TABLE_F081_01_012 ( ID INT PRIMARY KEY, A INTEGER );

# TODO: Except
# statement ok
# CREATE VIEW VIEW_F081_01_01 AS SELECT A FROM TABLE_F081_01_011 EXCEPT SELECT A FROM TABLE_F081_01_012

statement ok
Expand All @@ -16,12 +16,14 @@ CREATE TABLE TABLE_F081_01_021 ( ID INT PRIMARY KEY, A INTEGER );
statement ok
CREATE TABLE TABLE_F081_01_022 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F081_01_02 AS SELECT A FROM TABLE_F081_01_021 UNION ALL SELECT A FROM TABLE_F081_01_022
statement ok
CREATE VIEW VIEW_F081_01_02 AS SELECT A FROM TABLE_F081_01_021 UNION ALL SELECT A FROM TABLE_F081_01_022

statement ok
CREATE TABLE TABLE_F081_01_031 ( ID INT PRIMARY KEY, A INTEGER );

statement ok
CREATE TABLE TABLE_F081_01_032 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F081_01_03 AS SELECT A FROM TABLE_F081_01_031 UNION SELECT A FROM TABLE_F081_01_032
statement ok
CREATE VIEW VIEW_F081_01_03 AS SELECT A FROM TABLE_F081_01_031 UNION SELECT A FROM TABLE_F081_01_032
38 changes: 24 additions & 14 deletions tests/slt/sql_2016/F131_01.slt
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
# F131-01: WHERE, GROUP BY, and HAVING clauses supported in queries with grouped views

# TODO: WHERE, GROUP BY, and HAVING clauses supported in queries with grouped views

statement ok
CREATE TABLE TABLE_F131_01_01_01 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F131_01_01_01 AS SELECT A FROM TABLE_F131_01_01_01 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_01_01_01 AS SELECT A FROM TABLE_F131_01_01_01 GROUP BY A;

# SELECT A FROM VIEW_F131_01_01_01
query I
SELECT A FROM VIEW_F131_01_01_01

statement ok
CREATE TABLE TABLE_F131_01_01_02 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F131_01_01_02 AS SELECT A FROM TABLE_F131_01_01_02 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_01_01_02 AS SELECT A FROM TABLE_F131_01_01_02 GROUP BY A;

# SELECT A FROM VIEW_F131_01_01_02 GROUP BY A
query I
SELECT A FROM VIEW_F131_01_01_02 GROUP BY A

statement ok
CREATE TABLE TABLE_F131_01_01_03 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F131_01_01_03 AS SELECT A FROM TABLE_F131_01_01_03 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_01_01_03 AS SELECT A FROM TABLE_F131_01_01_03 GROUP BY A;

# SELECT A FROM VIEW_F131_01_01_03 GROUP BY A HAVING A = 2
query I
SELECT A FROM VIEW_F131_01_01_03 GROUP BY A HAVING A = 2

statement ok
CREATE TABLE TABLE_F131_01_01_04 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F131_01_01_04 AS SELECT A FROM TABLE_F131_01_01_04 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_01_01_04 AS SELECT A FROM TABLE_F131_01_01_04 GROUP BY A;

# SELECT A FROM VIEW_F131_01_01_04 WHERE A = 1
query I
SELECT A FROM VIEW_F131_01_01_04 WHERE A = 1

statement ok
CREATE TABLE TABLE_F131_01_01_05 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F131_01_01_05 AS SELECT A FROM TABLE_F131_01_01_05 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_01_01_05 AS SELECT A FROM TABLE_F131_01_01_05 GROUP BY A;

# SELECT A FROM VIEW_F131_01_01_05 WHERE A = 1 GROUP BY A
query I
SELECT A FROM VIEW_F131_01_01_05 WHERE A = 1 GROUP BY A

statement ok
CREATE TABLE TABLE_F131_01_01_06 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F131_01_01_06 AS SELECT A FROM TABLE_F131_01_01_06 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_01_01_06 AS SELECT A FROM TABLE_F131_01_01_06 GROUP BY A;

# SELECT A FROM VIEW_F131_01_01_06 WHERE A = 1 GROUP BY A HAVING A = 2
query I
SELECT A FROM VIEW_F131_01_01_06 WHERE A = 1 GROUP BY A HAVING A = 2
8 changes: 4 additions & 4 deletions tests/slt/sql_2016/F131_02.slt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# F131-02: Multiple tables supported in queries with grouped views

# TODO Multiple tables supported in queries with grouped views

statement ok
CREATE TABLE TABLE_F131_02_01_011 ( ID INT PRIMARY KEY, A INTEGER );

statement ok
CREATE TABLE TABLE_F131_02_01_012 ( ID INT PRIMARY KEY, A INTEGER );

# CREATE VIEW VIEW_F131_02_01_01 AS SELECT A FROM TABLE_F131_02_01_011 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_02_01_01 AS SELECT A FROM TABLE_F131_02_01_011 GROUP BY A;

# SELECT A FROM VIEW_F131_02_01_01 JOIN TABLE_F131_02_01_012 USING ( A )
query I
SELECT A FROM VIEW_F131_02_01_01 JOIN TABLE_F131_02_01_012 USING ( A )
17 changes: 11 additions & 6 deletions tests/slt/sql_2016/F131_03.slt
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# F131-03: Set functions supported in queries with grouped views

# TODO: Set functions supported in queries with grouped views

statement ok
CREATE TABLE TABLE_F131_03_01_011 ( ID INT PRIMARY KEY, A INTEGER, B INTEGER );

# CREATE VIEW VIEW_F131_03_01_01 AS SELECT A, MIN ( B ) AS C FROM TABLE_F131_03_01_011 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_03_01_01 AS SELECT A, MIN ( B ) AS C FROM TABLE_F131_03_01_011 GROUP BY A;

# SELECT SUM ( C ) FROM VIEW_F131_03_01_01
query I
SELECT SUM ( C ) FROM VIEW_F131_03_01_01
----
null

statement ok
CREATE TABLE TABLE_F131_03_01_021 ( ID INT PRIMARY KEY, A INTEGER, B INTEGER );

# CREATE VIEW VIEW_F131_03_01_02 AS SELECT A, MIN ( B ) AS C FROM TABLE_F131_03_01_021 GROUP BY A;
statement ok
CREATE VIEW VIEW_F131_03_01_02 AS SELECT A, MIN ( B ) AS C FROM TABLE_F131_03_01_021 GROUP BY A;

# SELECT SUM ( C ) FROM VIEW_F131_03_01_02 GROUP BY A
query I
SELECT A, SUM ( C ) FROM VIEW_F131_03_01_02 GROUP BY A
----
Loading

0 comments on commit 55f8250

Please sign in to comment.