Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add duckdb cte tests & fix some minor bugs #12527

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix cte table alias
  • Loading branch information
xxchan committed Sep 25, 2023
commit 79d3f524116517bdc28fdc07abfa3e05d868161a
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -33,3 +33,6 @@ f8266748dcb70541da944664552c1944ff8362e4

# feat(risedev): add check for trailing spaces in `risedev check` (#11294)
f2a3fd021059e680b35b24c63cff5f8dbe9f9d5f

# chore(rustfmt): format let-chains and let-else #9409
d70dba827c303373f3220c9733f7c7443e5c2d37
11 changes: 11 additions & 0 deletions e2e_test/batch/basic/cte.slt.part
Original file line number Diff line number Diff line change
@@ -65,3 +65,14 @@ drop table t1;

statement ok
drop table t2;

# more tests for alias https://github.com/risingwavelabs/risingwave/issues/12526
query I
with cte as (select 1) select x from cte t(x);
----
1

query I
with cte(a) as (select 1,2) select x,y from cte t(x,y);
----
1 2
5 changes: 3 additions & 2 deletions e2e_test/batch/duckdb/cte/test_cte.test.slt.part
Original file line number Diff line number Diff line change
@@ -16,9 +16,10 @@ with cte1 as (Select i as j from a) select * from cte1;
----
42

# FIXME: this should succeed
query error failed to bind expression: x
query I
with cte1 as (Select i as j from a) select x from cte1 t1(x);
----
42

query I
with cte1(xxx) as (Select i as j from a) select xxx from cte1;
5 changes: 3 additions & 2 deletions e2e_test/batch/duckdb/cte/test_cte_in_cte.test.slt.part
Original file line number Diff line number Diff line change
@@ -16,9 +16,10 @@ with cte1 as (Select i as j from a) select * from cte1;
----
42

# FIXME: this should succeed
query error failed to bind expression: x
query I
with cte1 as (with b as (Select i as j from a) Select j from b) select x from cte1 t1(x);
----
42

query I
with cte1(xxx) as (with ncte(yyy) as (Select i as j from a) Select yyy from ncte) select xxx from cte1;
7 changes: 5 additions & 2 deletions src/frontend/src/binder/relation/mod.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
use std::collections::hash_map::Entry;
use std::ops::Deref;

use itertools::{EitherOrBoth, Itertools};
use risingwave_common::catalog::{Field, TableId, DEFAULT_SCHEMA_NAME};
use risingwave_common::error::{internal_error, ErrorCode, Result, RwError};
use risingwave_sqlparser::ast::{
@@ -337,11 +338,13 @@ impl Binder {

if let Some(from_alias) = alias {
original_alias.name = from_alias.name;
let mut alias_iter = from_alias.columns.into_iter();
original_alias.columns = original_alias
.columns
.into_iter()
.map(|ident| alias_iter.next().unwrap_or(ident))
.zip_longest(
from_alias.columns.into_iter()
)
.map(EitherOrBoth::into_right)
.collect();
}