Skip to content

Commit

Permalink
wip sql: use goldenscript for DML tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jul 1, 2024
1 parent 2235180 commit 0388abc
Show file tree
Hide file tree
Showing 140 changed files with 1,706 additions and 2,168 deletions.
13 changes: 11 additions & 2 deletions src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod tests {

// Run goldenscript tests in src/sql/testscripts.
test_each_path! { in "src/sql/testscripts/schema" as schema => test_goldenscript }
test_each_path! { in "src/sql/testscripts/writes" as writes => test_goldenscript }
test_each_path! { in "src/sql/testscripts/expressions" as expressions => test_goldenscript_expr }

fn test_goldenscript(path: &std::path::Path) {
Expand Down Expand Up @@ -124,8 +125,16 @@ mod tests {
writeln!(output, "{plan}")?;
}

// Output the result if requested.
if tags.remove("result") {
// Output the result if requested. SELECT results are always output,
// but the columns only if result is given.
if let StatementResult::Select { columns, rows } = result {
if tags.remove("columns") {
writeln!(output, "{}", columns.into_iter().map(|c| c.to_string()).join(","))?;
}
for row in rows {
writeln!(output, "{}", row.into_iter().map(|v| v.to_string()).join(","))?;
}
} else if tags.remove("result") {
writeln!(output, "{result:?}")?;
}

Expand Down
87 changes: 87 additions & 0 deletions src/sql/testscripts/writes/delete
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Tests basic DELETE.

# Insert some data into a table. We'll use transactions to avoid
#
> CREATE TABLE name (id INT PRIMARY KEY, value STRING)
> INSERT INTO name VALUES (1, 'a'), (2, 'b'), (3, 'c')
---
ok

# Deleting from a table works. Use a transaction to keep the fixture.
> BEGIN
[plan,ops]> DELETE FROM name
---
Delete: name
└─ Scan: name
storage set mvcc:TxnWrite(3, sql:Row("name", Integer(1))) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x03\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x01\x00\x00" → ""]
storage set mvcc:Version(sql:Row("name", Integer(1)), 3) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03" → "\x00"]
storage set mvcc:TxnWrite(3, sql:Row("name", Integer(2))) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x03\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x02\x00\x00" → ""]
storage set mvcc:Version(sql:Row("name", Integer(2)), 3) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03" → "\x00"]
storage set mvcc:TxnWrite(3, sql:Row("name", Integer(3))) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x03\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x03\x00\x00" → ""]
storage set mvcc:Version(sql:Row("name", Integer(3)), 3) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03" → "\x00"]

> SELECT * FROM name
> ROLLBACK
---
ok

# Deleting without a table, or with a missing or multiple tables errors.
!> DELETE
!> DELETE FROM
!> DELETE FROM missing
!> DELETE FROM name, foo
---
Error: invalid input: unexpected end of input
Error: invalid input: unexpected end of input
Error: invalid input: table missing does not exist
Error: invalid input: unexpected token ,

# Deleting in an implicit transaction works, and deletes.
[ops]> DELETE FROM name
---
storage set mvcc:NextVersion → 6 ["\x00" → "\x06"]
storage set mvcc:TxnActive(5) → "" ["\x01\x00\x00\x00\x00\x00\x00\x00\x05" → ""]
storage set mvcc:TxnWrite(5, sql:Row("name", Integer(1))) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x05\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x01\x00\x00" → ""]
storage set mvcc:Version(sql:Row("name", Integer(1)), 5) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05" → "\x00"]
storage set mvcc:TxnWrite(5, sql:Row("name", Integer(2))) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x05\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x02\x00\x00" → ""]
storage set mvcc:Version(sql:Row("name", Integer(2)), 5) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05" → "\x00"]
storage set mvcc:TxnWrite(5, sql:Row("name", Integer(3))) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x05\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x03\x00\x00" → ""]
storage set mvcc:Version(sql:Row("name", Integer(3)), 5) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05" → "\x00"]
storage delete mvcc:TxnWrite(5, sql:Row("name", Integer(1))) ["\x03\x00\x00\x00\x00\x00\x00\x00\x05\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x01\x00\x00"]
storage delete mvcc:TxnWrite(5, sql:Row("name", Integer(2))) ["\x03\x00\x00\x00\x00\x00\x00\x00\x05\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x02\x00\x00"]
storage delete mvcc:TxnWrite(5, sql:Row("name", Integer(3))) ["\x03\x00\x00\x00\x00\x00\x00\x00\x05\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x03\x00\x00"]
storage delete mvcc:TxnActive(5) ["\x01\x00\x00\x00\x00\x00\x00\x00\x05"]

> SELECT * FROM name
---
ok

dump
---
mvcc:NextVersion → 6 ["\x00" → "\x06"]
mvcc:Version(sql:Table("name"), 1) → CREATE TABLE name ( id INTEGER PRIMARY KEY, value STRING DEFAULT NULL ) ["\x04\x00\xffname\x00\xff\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" → "\x01\x1d\x04name\x00\x02\x02id\x01\x00\x00\x01\x00\x00\x05value\x03\x01\x01\x00\x00\x00\x00"]
mvcc:Version(sql:Row("name", Integer(1)), 2) → Integer(1),String("a") ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02" → "\x01\x06\x02\x02\x02\x04\x01a"]
mvcc:Version(sql:Row("name", Integer(1)), 5) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05" → "\x00"]
mvcc:Version(sql:Row("name", Integer(2)), 2) → Integer(2),String("b") ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02" → "\x01\x06\x02\x02\x04\x04\x01b"]
mvcc:Version(sql:Row("name", Integer(2)), 5) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05" → "\x00"]
mvcc:Version(sql:Row("name", Integer(3)), 2) → Integer(3),String("c") ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02" → "\x01\x06\x02\x02\x06\x04\x01c"]
mvcc:Version(sql:Row("name", Integer(3)), 5) → None ["\x04\x02name\x00\xff\x00\xff\x02\x80\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05" → "\x00"]

# Bare DELETE errors.
!> DELETE
!> DELETE FROM
---
Error: invalid input: unexpected end of input
Error: invalid input: unexpected end of input

# Unknown table errors.
!> DELETE FROM foo
---
Error: invalid input: table foo does not exist

# LIMIT and ORDER BY clauses error.
!> DELETE FROM name LIMIT 2
!> DELETE FROM name ORDER BY id
---
Error: invalid input: unexpected token LIMIT
Error: invalid input: unexpected token ORDER
Loading

0 comments on commit 0388abc

Please sign in to comment.