Skip to content

Commit

Permalink
test: order by and limit
Browse files Browse the repository at this point in the history
  • Loading branch information
holicc committed Oct 17, 2024
1 parent a47c1a5 commit eed0fae
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 37 deletions.
6 changes: 3 additions & 3 deletions qurious/src/execution/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,19 @@ mod tests {
#[test]
fn test_create_table() -> Result<()> {
let session = ExecuteSession::new()?;
session.sql("create table t (v1 int, v2 int)")?;
session.sql("create table t (v1 int, v2 int);")?;
// session.sql("create table b(v1 int, v2 float);")?;
// session.sql("create table t(v1 int not null, v2 int not null, v3 double not null)")?;

// session.sql("create table x(a int, b int);")?;
// session.sql("create table y(c int, d int);")?;

session.sql("insert into t values (1,1), (2,1), (3,2), (4,2), (5,3)")?;
session.sql("insert into t values (1, 0), ( 2, 2), (3, 15), (2, 12), (3, 9), (1, 5);")?;
// session.sql("insert into b select v1, v2 from a;")?;
// session.sql("INSERT INTO test VALUES (1, 1), (2, 2), (3, 3), (3, 5), (NULL, NULL);")?;
// session.sql("select a, b, c, d from x join y on a = c")?;
println!("++++++++++++++");
let batch = session.sql("select v1 + 1 + count(*) from t group by v1 + 1")?;
let batch = session.sql("select v1, v2 from t order by v1 asc, v2 desc")?;

print_batches(&batch)?;

Expand Down
5 changes: 5 additions & 0 deletions qurious/src/planner/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,11 @@ mod tests {

#[test]
fn test_order_by() {
quick_test(
"SELECT name FROM person ORDER BY name asc, age desc",
"Sort: person.name ASC\n Projection: (person.name)\n TableScan: person\n",
);

quick_test(
"SELECT name FROM person ORDER BY name",
"Sort: person.name ASC\n Projection: (person.name)\n TableScan: person\n",
Expand Down
45 changes: 45 additions & 0 deletions qurious/tests/having.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# scalar having
query I
select 42 having 42 > 18
----
42

# scalar having
query I
select 42 having 42 > 801
----

statement ok
CREATE TABLE test (x INT, y INT);

statement ok
INSERT INTO test VALUES (1, 2), (2, 2), (11, 22)

query II
select y as b, sum(x) as sum from test group by b having b = 2
----
2 3

query II
select count(x) as a, y as b from test group by b having a > 1
----
2 2

query II
select count(x) as a, y + 1 as b from test group by b having b + 1 = 24;
----
1 23

query II
select x from test group by x having max(y) = 22
----
11

query II
select y + 1 as i from test group by y + 1 having count(x) > 1 and y + 1 = 3 or y + 1 = 23 order by i;
----
3
23

statement error
select count(x) from test group by count(x)
117 changes: 117 additions & 0 deletions qurious/tests/join_left_inner.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
statement ok
create table x(a int, b int);

statement ok
create table y(c int, d int);

statement ok
insert into x values (1, 2), (1, 3);

query IIII
select a, b, c, d from x join y on a = c;
----

statement ok
insert into y values (1, 5), (1, 6), (2, 7);

query IIII
select a, b, c, d from x join y on a = c;
----
1 2 1 5
1 3 1 5
1 2 1 6
1 3 1 6

query IIII
select a, b, c, d from x, y;
----
1 2 1 5
1 3 1 5
1 2 1 6
1 3 1 6
1 2 2 7
1 3 2 7

query IIII
select a, b, c, d from x cross join y;
----
1 2 1 5
1 3 1 5
1 2 1 6
1 3 1 6
1 2 2 7
1 3 2 7

statement ok
drop table x;

statement ok
drop table y;

statement ok
create table a(v1 int, v2 int);

statement ok
create table b(v3 int, v4 int);

statement ok
insert into a values (1, 1), (2, 2), (3, 3);

query IIII rowsort
select v1, v2, v3, v4 from a left join b on v1 = v3;
----
1 1 NULL NULL
2 2 NULL NULL
3 3 NULL NULL

query I
select v1, v2, v3, v4 from a, b;
----

statement ok
insert into b values (1, 100), (3, 300), (4, 400);

query IIII
select v1, v2, v3, v4 from a left join b on v1 = v3;
----
1 1 1 100
3 3 3 300
2 2 NULL NULL

statement ok
drop table a;

statement ok
drop table b;

statement ok
create table a(v1 int, v2 int);

statement ok
create table b(v3 int, v4 int, v5 int);

statement ok
insert into a values (1, 1), (2, 2), (3, 3);

statement ok
insert into b values (1, 1, 1), (2, 2, 2), (3, 3, 4), (1, 1, 5);

query IIIII
select v1, v2, v3, v4, v5 from a join b on v1 = v3 and v2 = v4;
----
1 1 1 1 1
2 2 2 2 2
3 3 3 3 4
1 1 1 1 5

query IIIII
select v1, v2, v3, v4, v5 from a join b on v1 = v3 and v2 = v4 and v1 < v5;
----
3 3 3 3 4
1 1 1 1 5

statement ok
drop table a;

statement ok
drop table b;
49 changes: 49 additions & 0 deletions qurious/tests/join_semi_anti.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
statement ok
create table x(a int, b int);

statement ok
create table y(c int, d int);

statement ok
insert into x values (1, 2), (2, 3);

query II
select a, b from x left semi join y on a = c;
----

query II
select a, b from x left anti join y on a = c;
----
1 2
2 3

statement ok
insert into y values (2, 5), (3, 7);

# hash join
query II
select a, b from x left semi join y on a = c;
----
2 3

query II
select a, b from x left anti join y on a = c;
----
1 2

# nested loop join
query II
select a, b from x left semi join y on a >= c;
----
2 3

query II
select a, b from x left anti join y on a >= c;
----
1 2

statement ok
drop table x;

statement ok
drop table y;
50 changes: 50 additions & 0 deletions qurious/tests/sql/limit.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
statement ok
create table t(v1 int not null, v2 int not null)

statement ok
insert into t values (1, 1), (4, 2), (3, 3), (10, 12), (2, 5)

query I
select v1 from t limit 3
----
1
4
3

query I
select v1 from t offset 2
----
3
10
2

query I
select v1 from t limit 2 offset 2
----
3
10

query I
select v1 from t limit 6
----
1
4
3
10
2

query I
select v1 from t limit 0
----

query I
select v1 from t offset 5
----

# test case for https://github.com/risinglightdb/risinglight/issues/264
statement ok
insert into t values (1, 1)

query I
select v1 from t limit 0
----
84 changes: 84 additions & 0 deletions qurious/tests/sql/order_by.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
statement ok
create table t(v1 int not null, v2 int not null)

statement ok
insert into t values(1, 1), (4, 2), (3, 3), (10, 12), (2, 5)

query I
select v1 from t order by v1 asc
----
1
2
3
4
10

query I
select v1 from t order by v1 desc
----
10
4
3
2
1

statement ok
drop table t


statement ok
create table t(v1 int not null, v2 int not null)

statement ok
insert into t values (1, 0), ( 2, 2), (3, 15), (2, 12), (3, 9), (1, 5)

query II
select v1, v2 from t order by v1 asc, v2 desc
----
1 5
1 0
2 12
2 2
3 15
3 9

statement ok
drop table t


# sort with NULL
statement ok
create table t(v1 int, v2 int)

statement ok
insert into t values (1, 0), (2, 2), (NULL, 5), (2, NULL)

query II
select v1, v2 from t order by v1 asc, v2 asc
----
NULL 5
1 0
2 NULL
2 2

statement ok
drop table t

# sort on alias
statement ok
create table t(v1 int, v2 int)

statement ok
insert into t values(1, 1), (4, 2), (3, 3), (10, 12), (2, 5)

query I
select v1 as a from t order by a
----
1
2
3
4
10

statement ok
drop table t
Loading

0 comments on commit eed0fae

Please sign in to comment.