Skip to content

Commit 2ae7380

Browse files
everpcpcDousir9zhyass
authored
chore(binder): fix bind cte (#17187)
* chore(binder): fix bind cte (#17183) * fix(ci): flaky test (#17149) --------- Co-authored-by: Jk Xu <[email protected]> Co-authored-by: zhya <[email protected]>
1 parent 7092968 commit 2ae7380

File tree

26 files changed

+83
-63
lines changed

26 files changed

+83
-63
lines changed

.github/workflows/dev.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,21 @@ jobs:
5555
runner_provider: aws
5656
license_type: trial
5757

58-
linux_hive:
59-
needs: changes
60-
if: needs.changes.outputs.any_src_changed == 'true'
61-
uses: ./.github/workflows/reuse.linux.hive.yml
62-
secrets: inherit
63-
with:
64-
build_profile: ci
65-
runner_provider: aws
58+
# linux_hive:
59+
# needs: changes
60+
# if: needs.changes.outputs.any_src_changed == 'true'
61+
# uses: ./.github/workflows/reuse.linux.hive.yml
62+
# secrets: inherit
63+
# with:
64+
# build_profile: ci
65+
# runner_provider: aws
6666

6767
ready:
6868
if: always()
6969
runs-on: ubuntu-latest
7070
needs:
7171
- changes
7272
- linux
73-
- linux_hive
7473
steps:
7574
- name: Check Ready to Merge
7675
uses: actions/github-script@v7

scripts/build/build-website.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cd "$SCRIPT_PATH/../.." || exit
1010
echo "Building docs"
1111
cd website
1212

13-
# NOET: for aarch64 macos
13+
# NOTE: for aarch64 macos
1414
# arch -x86_64 zsh
1515

1616
mkdir -p ~/.nvm

src/query/ast/src/parser/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ where
518518
input.backtrace.clear();
519519

520520
let err_kind = match err {
521-
PrattError::EmptyInput => ErrorKind::Other("expecting an oprand"),
521+
PrattError::EmptyInput => ErrorKind::Other("expecting an operand"),
522522
PrattError::UnexpectedNilfix(_) => ErrorKind::Other("unable to parse the element"),
523523
PrattError::UnexpectedPrefix(_) => {
524524
ErrorKind::Other("unable to parse the prefix operator")

src/query/ast/tests/it/testdata/expr-error.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error:
55
--> SQL:1:3
66
|
77
1 | 5 * (a and ) 1
8-
| - ^ expecting an oprand
8+
| - ^ expecting an operand
99
| |
1010
| while parsing expression
1111

@@ -17,7 +17,7 @@ error:
1717
--> SQL:1:5
1818
|
1919
1 | a + +
20-
| - ^ expecting an oprand
20+
| - ^ expecting an operand
2121
| |
2222
| while parsing expression
2323

src/query/ast/tests/it/testdata/query-error.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error:
55
--> SQL:1:24
66
|
77
1 | select * from customer join where a = b
8-
| ------ ^^^^ expecting an oprand
8+
| ------ ^^^^ expecting an operand
99
| |
1010
| while parsing `SELECT ...`
1111

src/query/script/src/compiler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,14 @@ impl Compiler {
724724
fn compile_case(
725725
&mut self,
726726
span: Span,
727-
oprand: &Expr,
727+
operand: &Expr,
728728
conditions: &[Expr],
729729
results: &[Vec<ScriptStatement>],
730730
else_result: &Option<Vec<ScriptStatement>>,
731731
) -> Result<Vec<ScriptIR>> {
732732
let conditions = conditions
733733
.iter()
734-
.map(|condition| wrap_eq(condition.span(), oprand.clone(), condition.clone()))
734+
.map(|condition| wrap_eq(condition.span(), operand.clone(), condition.clone()))
735735
.collect::<Vec<_>>();
736736
self.compile_if(span, &conditions, results, else_result)
737737
}

src/query/sql/src/planner/binder/bind_query/bind.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Binder {
101101
};
102102
// If the CTE is materialized, we'll construct a temp table for it.
103103
if cte.materialized {
104-
self.m_cte_to_temp_table(cte)?;
104+
self.m_cte_to_temp_table(cte, idx, with.clone())?;
105105
}
106106
bind_context
107107
.cte_context
@@ -180,7 +180,7 @@ impl Binder {
180180
))
181181
}
182182

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

208208
let expr_replacer = ExprReplacer::new(database.clone(), self.m_cte_table_name.clone());
209209
let mut as_query = cte.query.clone();
210+
with.ctes.truncate(cte_index);
211+
with.ctes.retain(|cte| !cte.materialized);
212+
as_query.with = if !with.ctes.is_empty() {
213+
Some(with)
214+
} else {
215+
None
216+
};
210217
expr_replacer.replace_query(&mut as_query);
211218

212219
let create_table_stmt = CreateTableStmt {

src/query/sql/src/planner/binder/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl TableIdentifier {
186186
QuotedIdent(&database.name, self.dialect.default_ident_quote())
187187
)
188188
}
189-
Some(NameResolutionSuggest::Unqoted) => {
189+
Some(NameResolutionSuggest::Unquoted) => {
190190
format!(
191191
"Unknown database {catalog}.{database} (quoted). Did you mean {} (unquoted)?",
192192
&database.name
@@ -204,7 +204,7 @@ impl TableIdentifier {
204204
QuotedIdent(&table.name, self.dialect.default_ident_quote())
205205
)
206206
}
207-
Some(NameResolutionSuggest::Unqoted) => {
207+
Some(NameResolutionSuggest::Unquoted) => {
208208
format!(
209209
"Unknown table {catalog}.{database}.{table} (quoted). Did you mean {} (unquoted)?",
210210
&table.name

src/query/sql/src/planner/semantic/name_resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct NameResolutionContext {
3333

3434
pub enum NameResolutionSuggest {
3535
Quoted,
36-
Unqoted,
36+
Unquoted,
3737
}
3838

3939
impl NameResolutionContext {
@@ -48,7 +48,7 @@ impl NameResolutionContext {
4848
) {
4949
(false, true, false) => Some(NameResolutionSuggest::Quoted),
5050
(true, false, true) if !ident_needs_quote(&ident.name) => {
51-
Some(NameResolutionSuggest::Unqoted)
51+
Some(NameResolutionSuggest::Unquoted)
5252
}
5353
_ => None,
5454
}

tests/sqllogictests/suites/query/cte/cte.test

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,4 +557,18 @@ statement ok
557557
drop table if exists t1;
558558

559559
statement ok
560-
drop table if exists t2;
560+
drop table if exists t2;
561+
562+
query T
563+
with t(tt) as (select number as tt from numbers(10)), t2(tt) AS MATERIALIZED (SELECT tt FROM t) select * from t2;
564+
----
565+
0
566+
1
567+
2
568+
3
569+
4
570+
5
571+
6
572+
7
573+
8
574+
9

0 commit comments

Comments
 (0)