Skip to content

Commit

Permalink
chore(binder): fix bind cte (#17187)
Browse files Browse the repository at this point in the history
* chore(binder): fix bind cte (#17183)

* fix(ci): flaky test (#17149)

---------

Co-authored-by: Jk Xu <54522439+Dousir9@users.noreply.github.com>
Co-authored-by: zhya <mytesla@live.com>
  • Loading branch information
3 people authored Jan 7, 2025
1 parent 7092968 commit 2ae7380
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 63 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,21 @@ jobs:
runner_provider: aws
license_type: trial

linux_hive:
needs: changes
if: needs.changes.outputs.any_src_changed == 'true'
uses: ./.github/workflows/reuse.linux.hive.yml
secrets: inherit
with:
build_profile: ci
runner_provider: aws
# linux_hive:
# needs: changes
# if: needs.changes.outputs.any_src_changed == 'true'
# uses: ./.github/workflows/reuse.linux.hive.yml
# secrets: inherit
# with:
# build_profile: ci
# runner_provider: aws

ready:
if: always()
runs-on: ubuntu-latest
needs:
- changes
- linux
- linux_hive
steps:
- name: Check Ready to Merge
uses: actions/github-script@v7
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/build-website.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd "$SCRIPT_PATH/../.." || exit
echo "Building docs"
cd website

# NOET: for aarch64 macos
# NOTE: for aarch64 macos
# arch -x86_64 zsh

mkdir -p ~/.nvm
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ where
input.backtrace.clear();

let err_kind = match err {
PrattError::EmptyInput => ErrorKind::Other("expecting an oprand"),
PrattError::EmptyInput => ErrorKind::Other("expecting an operand"),
PrattError::UnexpectedNilfix(_) => ErrorKind::Other("unable to parse the element"),
PrattError::UnexpectedPrefix(_) => {
ErrorKind::Other("unable to parse the prefix operator")
Expand Down
4 changes: 2 additions & 2 deletions src/query/ast/tests/it/testdata/expr-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error:
--> SQL:1:3
|
1 | 5 * (a and ) 1
| - ^ expecting an oprand
| - ^ expecting an operand
| |
| while parsing expression

Expand All @@ -17,7 +17,7 @@ error:
--> SQL:1:5
|
1 | a + +
| - ^ expecting an oprand
| - ^ expecting an operand
| |
| while parsing expression

Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/tests/it/testdata/query-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error:
--> SQL:1:24
|
1 | select * from customer join where a = b
| ------ ^^^^ expecting an oprand
| ------ ^^^^ expecting an operand
| |
| while parsing `SELECT ...`

Expand Down
4 changes: 2 additions & 2 deletions src/query/script/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,14 @@ impl Compiler {
fn compile_case(
&mut self,
span: Span,
oprand: &Expr,
operand: &Expr,
conditions: &[Expr],
results: &[Vec<ScriptStatement>],
else_result: &Option<Vec<ScriptStatement>>,
) -> Result<Vec<ScriptIR>> {
let conditions = conditions
.iter()
.map(|condition| wrap_eq(condition.span(), oprand.clone(), condition.clone()))
.map(|condition| wrap_eq(condition.span(), operand.clone(), condition.clone()))
.collect::<Vec<_>>();
self.compile_if(span, &conditions, results, else_result)
}
Expand Down
11 changes: 9 additions & 2 deletions src/query/sql/src/planner/binder/bind_query/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Binder {
};
// If the CTE is materialized, we'll construct a temp table for it.
if cte.materialized {
self.m_cte_to_temp_table(cte)?;
self.m_cte_to_temp_table(cte, idx, with.clone())?;
}
bind_context
.cte_context
Expand Down Expand Up @@ -180,7 +180,7 @@ impl Binder {
))
}

fn m_cte_to_temp_table(&mut self, cte: &CTE) -> Result<()> {
fn m_cte_to_temp_table(&mut self, cte: &CTE, cte_index: usize, mut with: With) -> Result<()> {
let engine = if self.ctx.get_settings().get_persist_materialized_cte()? {
Engine::Fuse
} else {
Expand All @@ -207,6 +207,13 @@ impl Binder {

let expr_replacer = ExprReplacer::new(database.clone(), self.m_cte_table_name.clone());
let mut as_query = cte.query.clone();
with.ctes.truncate(cte_index);
with.ctes.retain(|cte| !cte.materialized);
as_query.with = if !with.ctes.is_empty() {
Some(with)
} else {
None
};
expr_replacer.replace_query(&mut as_query);

let create_table_stmt = CreateTableStmt {
Expand Down
4 changes: 2 additions & 2 deletions src/query/sql/src/planner/binder/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl TableIdentifier {
QuotedIdent(&database.name, self.dialect.default_ident_quote())
)
}
Some(NameResolutionSuggest::Unqoted) => {
Some(NameResolutionSuggest::Unquoted) => {
format!(
"Unknown database {catalog}.{database} (quoted). Did you mean {} (unquoted)?",
&database.name
Expand All @@ -204,7 +204,7 @@ impl TableIdentifier {
QuotedIdent(&table.name, self.dialect.default_ident_quote())
)
}
Some(NameResolutionSuggest::Unqoted) => {
Some(NameResolutionSuggest::Unquoted) => {
format!(
"Unknown table {catalog}.{database}.{table} (quoted). Did you mean {} (unquoted)?",
&table.name
Expand Down
4 changes: 2 additions & 2 deletions src/query/sql/src/planner/semantic/name_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct NameResolutionContext {

pub enum NameResolutionSuggest {
Quoted,
Unqoted,
Unquoted,
}

impl NameResolutionContext {
Expand All @@ -48,7 +48,7 @@ impl NameResolutionContext {
) {
(false, true, false) => Some(NameResolutionSuggest::Quoted),
(true, false, true) if !ident_needs_quote(&ident.name) => {
Some(NameResolutionSuggest::Unqoted)
Some(NameResolutionSuggest::Unquoted)
}
_ => None,
}
Expand Down
16 changes: 15 additions & 1 deletion tests/sqllogictests/suites/query/cte/cte.test
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,18 @@ statement ok
drop table if exists t1;

statement ok
drop table if exists t2;
drop table if exists t2;

query T
with t(tt) as (select number as tt from numbers(10)), t2(tt) AS MATERIALIZED (SELECT tt FROM t) select * from t2;
----
0
1
2
3
4
5
6
7
8
9
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ query T
SELECT substr(DATE_ADD(month, 1, now())::String, 6, 2) =
CASE
WHEN substr(now()::String, 6, 2) = '12' THEN '01'
ELSE (substr(now()::String, 6, 2)::int + 1)::String
ELSE LPAD((substr(now()::String, 6, 2)::int + 1)::String, 2, '0')
END;
----
1
Expand Down Expand Up @@ -950,7 +950,7 @@ query T
SELECT substr(DATE_ADD(month, 1, now())::String, 6, 2) =
CASE
WHEN substr(now()::String, 6, 2) = '12' THEN '01'
ELSE (substr(now()::String, 6, 2)::int + 1)::String
ELSE LPAD((substr(now()::String, 6, 2)::int + 1)::String, 2, '0')
END;
----
1
Expand All @@ -960,7 +960,7 @@ query T
SELECT substr(DATE_ADD(month, 1, now())::String, 1, 4) =
CASE
WHEN substr(now()::String, 6, 2) = '12' THEN (substr(now()::String, 1,4)::int+1)::String
ELSE (substr(now()::String, 6, 2)::int + 1)::String
ELSE (substr(now()::String, 1, 4)::int)::String
END;
----
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ query T
SELECT substr(DATE_ADD(month, 1, now())::String, 6, 2) =
CASE
WHEN substr(now()::String, 6, 2) = '12' THEN '01'
ELSE (substr(now()::String, 6, 2)::int + 1)::String
ELSE LPAD((substr(now()::String, 6, 2)::int + 1)::String, 2, '0')
END;
----
1
Expand All @@ -769,7 +769,7 @@ query T
SELECT substr(DATE_ADD(month, 1, now())::String, 1, 4) =
CASE
WHEN substr(now()::String, 6, 2) = '12' THEN (substr(now()::String, 1,4)::int+1)::String
ELSE (substr(now()::String, 6, 2)::int + 1)::String
ELSE (substr(now()::String, 1, 4)::int)::String
END;
----
1
Expand Down Expand Up @@ -813,7 +813,7 @@ query T
SELECT substr(DATE_ADD(month, 1, now())::String, 6, 2) =
CASE
WHEN substr(now()::String, 6, 2) = '12' THEN '01'
ELSE (substr(now()::String, 6, 2)::int + 1)::String
ELSE LPAD((substr(now()::String, 6, 2)::int + 1)::String, 2, '0')
END;
----
1
Expand All @@ -823,7 +823,7 @@ query T
SELECT substr(DATE_ADD(month, 1, now())::String, 1, 4) =
CASE
WHEN substr(now()::String, 6, 2) = '12' THEN (substr(now()::String, 1,4)::int+1)::String
ELSE (substr(now()::String, 6, 2)::int + 1)::String
ELSE (substr(now()::String, 1, 4)::int)::String
END;
----
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ remove @data/unload/parquet/null_if/
query
copy into @data/unload/parquet/null_if from string
----
3 56 387
3 56 379

statement ok
drop file format if exists parquet_null_if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ remove @data/parquet/unload/uuid
query
copy into @data/parquet/unload/uuid/ from (select 1 as a) file_format = (type = parquet)
----
1 1 374
1 1 366

query error column id doesn't exist
copy into t_uuid from @data/parquet/unload/uuid file_format = (type = parquet) RETURN_FAILED_ONLY=TRUE
Expand All @@ -22,7 +22,7 @@ select * from t_uuid
query
copy into @data/parquet/unload/uuid/ from (select 1 as a) file_format = (type = parquet)
----
1 1 374
1 1 366

statement ok
truncate table t_uuid
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/0_stateless/05_hints/05_0001_set_var.result
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ America/Toronto
1
2022-02-02 03:00:00
2022-02-02 03:00:00
1 13 427
1 13 419
Asia/Shanghai
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
1
200
=== test stage ===
1 8 400
1 8 392
0
=== test udf ===
2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Error: APIError: QueryFailed: [1063]Permission denied: privilege READ is require
Error: APIError: QueryFailed: [1063]Permission denied: No privilege on database root_db for user b.
Error: APIError: QueryFailed: [1063]Permission denied: No privilege on table root_table for user b.
Error: APIError: QueryFailed: [1063]Permission denied: No privilege on table root_table for user b.
1 1 374
1 1 366
Error: APIError: QueryFailed: [1063]Permission denied: privilege [Select] is required on 'default'.'default'.'t1' for user 'b'@'%' with roles [public]
Error: APIError: QueryFailed: [1063]Permission denied: privilege [Read] is required on STAGE s3 for user 'b'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Warehouse|Database|Table|UDF|Stage.
Error: APIError: QueryFailed: [1063]Permission denied: privilege [Select] is required on 'default'.'default'.'t' for user 'b'@'%' with roles [public]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1
1
2 10 399
2 10 391
expects .stats.write_progress.rows be 2
expects .error be null
2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
2
2
20 160 160
20 530 818
20 530 810
2
20 160 160
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
>>>> create or replace connection c_00_0005 storage_type='s3' access_key_id = 'minioadmin' endpoint_url = 'http://127.0.0.1:9900' secret_access_key = 'minioadmin'
>>>> copy into 's3://testbucket/c_00_0005/ab de/f' connection=(connection_name='c_00_0005') from (select 1) detailed_output=true use_raw_path=true single=true overwrite=true
c_00_0005/ab de/f 374 1
c_00_0005/ab de/f 366 1
<<<<
2 changes: 1 addition & 1 deletion tests/suites/1_stateful/00_stage/00_0012_stage_priv.result
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Error: APIError: QueryFailed: [1063]Permission denied: privilege [Write] is requ
Error: APIError: QueryFailed: [1063]Permission denied: privilege [Read] is required on STAGE presign_stage for user 'u1'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Warehouse|Database|Table|UDF|Stage.
000
Error: APIError: QueryFailed: [1063]Permission denied: privilege [Write] is required on STAGE s3 for user 'u1'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Warehouse|Database|Table|UDF|Stage.
1 1 374
1 1 366
Error: APIError: QueryFailed: [1063]Permission denied: privilege [Read] is required on STAGE s3 for user 'u1'@'%' with roles [public]. Note: Please ensure that your current role have the appropriate permissions to create a new Warehouse|Database|Table|UDF|Stage.
Error: APIError: QueryFailed: [1063]Permission denied: privilege READ is required on stage s3 for user 'u1'@'%'
Error: APIError: QueryFailed: [1063]Permission denied: privilege READ is required on stage s3 for user 'u1'@'%'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>>>> create stage my_stage url= 's3://testbucket/admin/tempdata/' connection = (connection_name='my_conn');
>>>> remove @my_stage;
>>>> copy into @my_stage/a.csv from my_table
3 13 401
3 13 393
>>>> select * from @my_stage order by a;
1
2
Expand Down
32 changes: 16 additions & 16 deletions tests/suites/1_stateful/00_stage/00_0015_unload_output.result
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,34 @@ copy2
<<<<
copy3
<<<<
a/bc/data_UUID_0000_00000000.parquet 393 1
a/bc/data_UUID_0000_00000001.parquet 393 1
a/bc/data_UUID_0000_00000002.parquet 393 1
a/bc/data_UUID_0000_00000003.parquet 393 1
a/bc/data_UUID_0000_00000004.parquet 393 1
a/bc/data_UUID_0000_00000005.parquet 393 1
a/bc/data_UUID_0000_00000006.parquet 393 1
a/bc/data_UUID_0000_00000007.parquet 393 1
a/bc/data_UUID_0000_00000008.parquet 393 1
a/bc/data_UUID_0000_00000009.parquet 393 1
a/bc/data_UUID_0000_00000000.parquet 385 1
a/bc/data_UUID_0000_00000001.parquet 385 1
a/bc/data_UUID_0000_00000002.parquet 385 1
a/bc/data_UUID_0000_00000003.parquet 385 1
a/bc/data_UUID_0000_00000004.parquet 385 1
a/bc/data_UUID_0000_00000005.parquet 385 1
a/bc/data_UUID_0000_00000006.parquet 385 1
a/bc/data_UUID_0000_00000007.parquet 385 1
a/bc/data_UUID_0000_00000008.parquet 385 1
a/bc/data_UUID_0000_00000009.parquet 385 1
>>>> unload path
>>>> copy /*+ set_var(max_threads=1) */ into @s1 from (select 1) detailed_output=true
data_UUID_0000_00000000.parquet 374 1
data_UUID_0000_00000000.parquet 366 1
<<<<
>>>> copy /*+ set_var(max_threads=1) */ into @s1/ from (select 1) detailed_output=true
data_UUID_0000_00000000.parquet 374 1
data_UUID_0000_00000000.parquet 366 1
<<<<
>>>> copy /*+ set_var(max_threads=1) */ into @s1/a from (select 1) detailed_output=true
a/data_UUID_0000_00000000.parquet 374 1
a/data_UUID_0000_00000000.parquet 366 1
<<<<
>>>> copy /*+ set_var(max_threads=1) */ into @s1/a/ from (select 1) detailed_output=true
a/data_UUID_0000_00000000.parquet 374 1
a/data_UUID_0000_00000000.parquet 366 1
<<<<
>>>> copy /*+ set_var(max_threads=1) */ into @s1/a/bc from (select 1) detailed_output=true
a/bc/data_UUID_0000_00000000.parquet 374 1
a/bc/data_UUID_0000_00000000.parquet 366 1
<<<<
>>>> copy /*+ set_var(max_threads=1) */ into @s1/a/data_ from (select 1) detailed_output=true
a/data_UUID_0000_00000000.parquet 374 1
a/data_UUID_0000_00000000.parquet 366 1
<<<<
>>>> drop stage if exists s1
>>>> drop table if exists t1
Loading

0 comments on commit 2ae7380

Please sign in to comment.