Skip to content

Commit

Permalink
add noalternativeverify to a few CTE tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Sep 2, 2024
1 parent 084241a commit bbede57
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
5 changes: 3 additions & 2 deletions test/sql/cte/materialized/test_cte_in_cte_materialized.test
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ with cte1 as MATERIALIZED (Select i as j from a) select * from cte1 where j = (w
----
42

require noalternativeverify

# same name, both get materialized with ALTERNATIVE_VERIFY, so we need 'noalternativeverify'
query I
with cte as materialized (Select i as j from a) select * from cte where j = (with cte as (select max(j) as j from cte) select j from cte);
----
42

require no_alternative_verify

# refer to same-named CTE in a subquery expression
statement error
with cte as MATERIALIZED (Select i as j from a) select * from cte where j = (with cte as MATERIALIZED (select max(j) as j from cte) select j from cte);
Expand Down
35 changes: 20 additions & 15 deletions test/sql/cte/test_cte.test
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ statement error
with cte1 as (select 42), cte1 as (select 42) select * FROM cte1;
----

# reference to CTE before its actually defined
query I
with cte3 as (select ref2.j as i from cte1 as ref2), cte1 as (Select i as j from a), cte2 as (select ref.j+1 as k from cte1 as ref) select * from cte2 union all select * FROM cte3;
----
43
42

# multiple uses of same CTE
query II
Expand Down Expand Up @@ -177,29 +171,40 @@ WITH RECURSIVE
t(b) AS MATERIALIZED (
(WITH helper(c) AS (
SELECT 5
)
SELECT * FROM helper h
), h1 AS
(SELECT * FROM helper h
UNION
SELECT 7
)
SELECT 7 FROM helper h)
SELECT * FROM h1)
)
SELECT * FROM t ORDER BY b;
----
5
7

require noalternativeverify

# FIXME: this one should work with ALTERNATIVE_VERIFY, but doesn't yet
# something wrong with binding a CTE inside a recursive CTE
query I
WITH RECURSIVE
t(b) AS MATERIALIZED (
(WITH helper(c) AS (
SELECT 5
), h1 AS
(SELECT * FROM helper h
)
SELECT * FROM helper h
UNION
SELECT 7 FROM helper h)
SELECT * FROM h1)
SELECT 7
)
)
SELECT * FROM t ORDER BY b;
----
5
7
7

# reference to CTE before its actually defined, can't with ALTERNATIVE_VERIFY because everything gets materialized
query I
with cte3 as (select ref2.j as i from cte1 as ref2), cte1 as (Select i as j from a), cte2 as (select ref.j+1 as k from cte1 as ref) select * from cte2 union all select * FROM cte3;
----
43
42
19 changes: 11 additions & 8 deletions test/sql/cte/test_issue_5673.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@ insert into orders values (1);
statement ok
insert into stg_orders values (1);

statement error
query I
with
orders as (
select * from stg_orders
where ordered_at >= (select max(ordered_at) from orders)
select * from main.stg_orders
where ordered_at >= (select max(ordered_at) from main.orders)
),
some_more_logic as (
select *
from orders
)
select * from some_more_logic;
----
Binder Error: Circular reference to CTE "orders", There are two possible solutions.
1

query I
require noalternativeverify

# this one needs 'noalternativeverify' otherwise the error message is different
statement error
with
orders as (
select * from main.stg_orders
where ordered_at >= (select max(ordered_at) from main.orders)
select * from stg_orders
where ordered_at >= (select max(ordered_at) from orders)
),
some_more_logic as (
select *
from orders
)
select * from some_more_logic;
----
1
Binder Error: Circular reference to CTE "orders", There are two possible solutions.

0 comments on commit bbede57

Please sign in to comment.