Skip to content

Commit

Permalink
Add tests for DELETE OUTPUT with JOIN
Browse files Browse the repository at this point in the history
Signed-off-by: Walt Boettge <[email protected]>
  • Loading branch information
wboettge committed Oct 9, 2023
1 parent ffe9e63 commit e8be0a0
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 1 deletion.
184 changes: 184 additions & 0 deletions test/JDBC/expected/babel_delete.out
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ go
~~ROW COUNT: 1~~


exec babel_2020_delete_ct;
delete babel_2020_delete_t1 output deleted.a
from babel_2020_delete_t1 x where x.a = 2;
go
~~ROW COUNT: 3~~

~~ROW COUNT: 3~~

~~START~~
int
2
~~END~~


-- multiple tables in FROM clause
exec babel_2020_delete_ct;
delete babel_2020_delete_t1 from babel_2020_delete_t1 x, babel_2020_delete_t2 y;
Expand Down Expand Up @@ -77,6 +91,20 @@ go
~~ROW COUNT: 1~~


exec babel_2020_delete_ct;
delete babel_2020_delete_t1 output y.*
from babel_2020_delete_t1 x, babel_2020_delete_t2 y where x.a = y.a;
go
~~ROW COUNT: 3~~

~~ROW COUNT: 3~~

~~START~~
int
2
~~END~~


-- JOIN clause
exec babel_2020_delete_ct;
delete babel_2020_delete_t1 from babel_2020_delete_t1 x join babel_2020_delete_t2 y on 1 = 1;
Expand Down Expand Up @@ -118,6 +146,21 @@ go
~~ROW COUNT: 1~~


exec babel_2020_delete_ct;
delete babel_2020_delete_t1 output deleted.a, y.a
from babel_2020_delete_t1 x join babel_2020_delete_t2 y on x.a = y.a;
go
~~ROW COUNT: 3~~

~~ROW COUNT: 3~~

~~START~~
int#!#int
2#!#2
~~END~~



-- subqueries
exec babel_2020_delete_ct;
delete babel_2020_delete_t1 from (select * from babel_2020_delete_t1) x;
Expand Down Expand Up @@ -201,6 +244,23 @@ go
~~ROW COUNT: 3~~


exec babel_2020_delete_ct;
delete babel_2020_delete_t1 output deleted.*, babel_2020_delete_t2.*
from babel_2020_delete_t1 x left outer join babel_2020_delete_t2
on babel_2020_delete_t2.a = x.a;
go
~~ROW COUNT: 3~~

~~ROW COUNT: 3~~

~~START~~
int#!#int
1#!#<NULL>
2#!#2
<NULL>#!#<NULL>
~~END~~


-- will be tracked in BABEL-3910
drop procedure if exists babel_3910_init_tables
go
Expand Down Expand Up @@ -341,6 +401,26 @@ int
~~END~~


exec babel_3910_init_tables
delete t1_3910 output deleted.*
from (t2_3910 left join t1_3910 on t1_3910.a = t2_3910.a)
join t3_3910 on t2_3910.a = t3_3910.a;
go
~~ROW COUNT: 5~~

~~ROW COUNT: 5~~

~~ROW COUNT: 5~~

~~ROW COUNT: 5~~

~~START~~
int
3
4
~~END~~


exec babel_3910_init_tables
delete t1_3910
from
Expand Down Expand Up @@ -458,6 +538,27 @@ go
~~ROW COUNT: 3~~


exec babel_3910_init_tables;
delete t1 output t2.*
from t2_3910 t2 left outer join t1_3910 t1 on t2.a = t1.a
where 0 < t1.a OR t1.a < 10;
go
~~ROW COUNT: 5~~

~~ROW COUNT: 5~~

~~ROW COUNT: 5~~

~~ROW COUNT: 5~~

~~START~~
int
2
3
4
~~END~~


select a from t1_3910;
go
~~START~~
Expand Down Expand Up @@ -546,6 +647,20 @@ go
~~ROW COUNT: 1~~


exec babel_2020_delete_ct;
delete babel_2020_delete_t1 output babel_2020_delete_t2.*
from babel_2020_delete_t2 left outer join babel_2020_delete_t1 x on x.a is null;
go
~~ROW COUNT: 3~~

~~ROW COUNT: 3~~

~~START~~
int
2
~~END~~


-- updatable views
drop view if exists babel_2020_delete_v1;
go
Expand Down Expand Up @@ -599,6 +714,21 @@ go
~~ROW COUNT: 1~~


exec babel_2020_delete_ct;
delete babel_2020_delete_t1 output deleted.*
from babel_2020_delete_t1 x where exists
(select a from babel_2020_delete_t1 y where y.a + 1 = x.a);
go
~~ROW COUNT: 3~~

~~ROW COUNT: 3~~

~~START~~
int
2
~~END~~


drop procedure if exists babel_2020_delete_ct;
drop table if exists babel_2020_delete_t1;
drop table if exists babel_2020_delete_t2;
Expand Down Expand Up @@ -675,6 +805,25 @@ int#!#varchar
~~END~~


BEGIN TRAN
DELETE t1 OUTPUT t2.b
FROM babel_delete_tbl1 t1
INNER JOIN (SELECT * FROM babel_delete_tbl1) t2
ON t1.b = t2.b
SELECT * FROM babel_delete_tbl1
ROLLBACK
GO
~~START~~
varchar
inner
left
~~END~~

~~START~~
int#!#varchar
~~END~~


-- alias + join
BEGIN TRAN
DELETE t1
Expand Down Expand Up @@ -741,6 +890,24 @@ int#!#int
~~END~~


BEGIN TRAN
DELETE t1 output deleted.*
FROM babel_delete_tbl1 t2, babel_delete_tbl3 t1
WHERE c > 1
SELECT * FROM babel_delete_tbl3
ROLLBACK
go
~~START~~
int#!#int
1#!#10
3#!#10
~~END~~

~~START~~
int#!#int
~~END~~


-- alias + outer join
BEGIN TRAN
DELETE t1
Expand Down Expand Up @@ -816,6 +983,23 @@ int
~~END~~


BEGIN TRAN
DELETE t1 output deleted.*
FROM babel_delete_schema.babel_delete_tbl1 t1
SELECT * fROM babel_delete_schema.babel_delete_tbl1
ROLLBACK
GO
~~START~~
int
1
2
~~END~~

~~START~~
int
~~END~~


-- target with schema
BEGIN TRAN
DELETE babel_delete_schema.babel_delete_tbl1
Expand Down
111 changes: 111 additions & 0 deletions test/JDBC/expected/babel_output_in_dml.out
Original file line number Diff line number Diff line change
Expand Up @@ -2028,3 +2028,114 @@ go

DROP TABLE #t2;
go

-- BABEL-4199 DELETE, join, and output
CREATE TABLE babel4199_t1(c1 varchar(30), c2 varchar(50));
CREATE TABLE babel4199_t2(c1 varchar(30), c2 varchar(50));
INSERT INTO babel4199_t1 VALUES ('1', '2'), ('2', '3');
INSERT INTO babel4199_t2 VALUES ('1', '10'), ('-1', '100');
GO
~~ROW COUNT: 2~~

~~ROW COUNT: 2~~


BEGIN TRANSACTION
DELETE TOP(1) a OUTPUT b.* FROM babel4199_t1 a
JOIN babel4199_t2 b on a.c1 = b.c1
WHERE a.c1 IN (
SELECT TOP(5) c1
FROM babel4199_t1 a
ORDER BY c2
)
ROLLBACK
GO
~~START~~
varchar#!#varchar
1#!#10
~~END~~


BEGIN TRANSACTION
DELETE a output b.*
from babel4199_t1 a
join babel4199_t2 b on a.c1 = b.c1
where a.c1 = 1
ROLLBACK
GO
~~START~~
varchar#!#varchar
1#!#10
~~END~~


BEGIN TRANSACTION
DELETE babel4199_t1 output b.*
from babel4199_t1 a
join babel4199_t2 b on a.c1 = b.c1
where a.c1 = 1
ROLLBACK
GO
~~START~~
varchar#!#varchar
1#!#10
~~END~~


-- Is an error in T-SQL
BEGIN TRANSACTION
DELETE a output a.*
from babel4199_t1 a
join babel4199_t2 b on a.c1 = b.c1
where a.c1 = 1
ROLLBACK
GO
~~START~~
varchar#!#varchar
1#!#2
~~END~~


-- Should error
BEGIN TRANSACTION
DELETE babel4199_t1 output babel4199_t1.*
from babel4199_t1 a
join babel4199_t2 b on a.c1 = b.c1
where a.c1 = 1
ROLLBACK
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: invalid reference to FROM-clause entry for table "babel4199_t1")~~


BEGIN TRANSACTION
DELETE a output deleted.*
from babel4199_t1 a
join babel4199_t2 b on a.c1 = b.c1
where a.c1 = 1
ROLLBACK
GO
~~START~~
varchar#!#varchar
1#!#2
~~END~~


BEGIN TRANSACTION
DELETE a output deleted.c1, deleted.c2
from babel4199_t1 a
join babel4199_t2 b on a.c1 = b.c1
where a.c1 = 1
ROLLBACK
GO
~~START~~
varchar#!#varchar
1#!#2
~~END~~



DROP TABLE babel4199_t1
DROP TABLE babel4199_t2
GO
Loading

0 comments on commit e8be0a0

Please sign in to comment.