Skip to content

Commit 4f6492e

Browse files
committed
stmt support branch
branch support recluster falshback constraint row access branch support compact and analyze index support branch fix branch support dml write truncate refresh virtual column and insert multi table create index fix support undrop branch add system.branches and show branches fix
1 parent 50836e0 commit 4f6492e

119 files changed

Lines changed: 2948 additions & 1112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/common/exception/src/exception_code.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ build_exceptions! {
335335
UnsupportedEngineParams(2703),
336336
}
337337

338-
// Table reference Errors [2745-2748]
338+
// Table reference Errors [2745-2749]
339339
build_exceptions! {
340340
/// Unknown reference
341341
UnknownReference(2745),
@@ -345,6 +345,8 @@ build_exceptions! {
345345
IllegalReference(2747),
346346
/// Reference expired
347347
ReferenceExpired(2748),
348+
/// Unsupported branch syntax
349+
UnsupportedBranchSyntax(2749),
348350
}
349351

350352
// License Errors [1401-1404]

src/meta/api/src/api_impl/ref_api.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,13 +716,13 @@ where
716716

717717
// 3. Collect all unique branch_ids
718718
let mut branch_id_set: HashSet<u64> = active_map.keys().copied().collect();
719-
let mut dropped_map: HashMap<u64, (String, DateTime<Utc>)> = HashMap::new();
719+
let mut dropped_map: HashMap<u64, (String, DroppedBranchMeta)> = HashMap::new();
720720

721721
for (key, seq_dropped) in &dropped_branches {
722722
branch_id_set.insert(key.branch_id);
723723
dropped_map.insert(
724724
key.branch_id,
725-
(key.branch_name.clone(), seq_dropped.data.drop_on),
725+
(key.branch_name.clone(), seq_dropped.data.clone()),
726726
);
727727
}
728728

@@ -746,8 +746,8 @@ where
746746

747747
// Filter branches whose effective delete time is already beyond the retention window.
748748
if let Some(retention_boundary) = req.retention_boundary {
749-
if let Some((_, drop_on)) = dropped_map.get(&branch_id.table_id) {
750-
if *drop_on < retention_boundary {
749+
if let Some((_, drop_meta)) = dropped_map.get(&branch_id.table_id) {
750+
if drop_meta.drop_on < retention_boundary {
751751
continue;
752752
}
753753
} else if let Some((_, expire_at)) = active_map.get(&branch_id.table_id) {
@@ -760,8 +760,8 @@ where
760760
let (branch_name, expire_at) =
761761
if let Some((name, expire_at)) = active_map.get(&branch_id.table_id) {
762762
(name.clone(), *expire_at)
763-
} else if let Some((name, _)) = dropped_map.get(&branch_id.table_id) {
764-
(name.clone(), None)
763+
} else if let Some((name, drop_meta)) = dropped_map.get(&branch_id.table_id) {
764+
(name.clone(), drop_meta.expire_at)
765765
} else {
766766
// unreachable.
767767
warn!(

src/query/ast/src/ast/statements/columns.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ use databend_common_ast_visit_derive::WalkMut;
2020
use derive_visitor::Drive;
2121
use derive_visitor::DriveMut;
2222

23-
use crate::ast::Identifier;
2423
use crate::ast::ShowLimit;
24+
use crate::ast::TableRef;
2525

2626
#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
2727
pub struct ShowColumnsStmt {
28-
pub catalog: Option<Identifier>,
29-
pub database: Option<Identifier>,
30-
pub table: Identifier,
28+
pub table: TableRef,
3129
pub full: bool,
3230
pub limit: Option<ShowLimit>,
3331
}
@@ -38,12 +36,15 @@ impl Display for ShowColumnsStmt {
3836
if self.full {
3937
write!(f, " FULL")?;
4038
}
41-
write!(f, " COLUMNS FROM {}", self.table)?;
39+
write!(f, " COLUMNS FROM {}", self.table.table)?;
40+
if let Some(branch) = &self.table.branch {
41+
write!(f, "/{branch}")?;
42+
}
4243

43-
if let Some(database) = &self.database {
44+
if let Some(database) = &self.table.database {
4445
write!(f, " FROM ")?;
45-
if let Some(catalog) = &self.catalog {
46-
write!(f, "{catalog}.",)?;
46+
if let Some(catalog) = &self.table.catalog {
47+
write!(f, "{catalog}.")?;
4748
}
4849
write!(f, "{database}")?;
4950
}

src/query/ast/src/ast/statements/copy.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::ast::Hint;
3232
use crate::ast::Identifier;
3333
use crate::ast::Query;
3434
use crate::ast::SelectTarget;
35+
use crate::ast::TableRef;
3536
use crate::ast::With;
3637
use crate::ast::WithOptions;
3738
use crate::ast::quote::QuotedString;
@@ -52,9 +53,7 @@ use crate::ast::write_dot_separated_list;
5253
pub struct CopyIntoTableStmt {
5354
pub with: Option<With>,
5455
pub src: CopyIntoTableSource,
55-
pub catalog: Option<Identifier>,
56-
pub database: Option<Identifier>,
57-
pub table: Identifier,
56+
pub table: TableRef,
5857
pub dst_columns: Option<Vec<Identifier>>,
5958

6059
pub hints: Option<Hint>,
@@ -104,13 +103,7 @@ impl Display for CopyIntoTableStmt {
104103
}
105104

106105
write!(f, " INTO ")?;
107-
write_dot_separated_list(
108-
f,
109-
self.catalog
110-
.iter()
111-
.chain(self.database.iter())
112-
.chain(Some(&self.table)),
113-
)?;
106+
write!(f, "{}", self.table)?;
114107

115108
if let Some(columns) = &self.dst_columns {
116109
write!(f, "({})", columns.iter().map(|c| c.to_string()).join(","))?;

src/query/ast/src/ast/statements/delete.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ use derive_visitor::DriveMut;
2222

2323
use crate::ast::Expr;
2424
use crate::ast::Hint;
25-
use crate::ast::Identifier;
2625
use crate::ast::TableAlias;
26+
use crate::ast::TableRef;
2727
use crate::ast::With;
28-
use crate::ast::write_dot_separated_list;
2928

3029
#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
3130
pub struct DeleteStmt {
3231
pub hints: Option<Hint>,
33-
pub catalog: Option<Identifier>,
34-
pub database: Option<Identifier>,
35-
pub table: Identifier,
32+
pub table: TableRef,
3633
pub table_alias: Option<TableAlias>,
3734
pub selection: Option<Expr>,
3835
// With clause, common table expression
@@ -49,13 +46,7 @@ impl Display for DeleteStmt {
4946
write!(f, "{} ", hints)?;
5047
}
5148
write!(f, "FROM ")?;
52-
write_dot_separated_list(
53-
f,
54-
self.catalog
55-
.iter()
56-
.chain(&self.database)
57-
.chain(Some(&self.table)),
58-
)?;
49+
write!(f, "{}", self.table)?;
5950
if let Some(alias) = &self.table_alias {
6051
write!(f, " AS {}", alias)?;
6152
}

src/query/ast/src/ast/statements/index.rs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use derive_visitor::DriveMut;
2424
use crate::ast::CreateOption;
2525
use crate::ast::Identifier;
2626
use crate::ast::Query;
27+
use crate::ast::TableRef;
2728
use crate::ast::write_comma_separated_list;
28-
use crate::ast::write_dot_separated_list;
2929
use crate::ast::write_space_separated_string_map;
3030

3131
#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
@@ -131,9 +131,7 @@ pub struct CreateTableIndexStmt {
131131
pub index_name: Identifier,
132132
pub index_type: TableIndexType,
133133

134-
pub catalog: Option<Identifier>,
135-
pub database: Option<Identifier>,
136-
pub table: Identifier,
134+
pub table: TableRef,
137135

138136
pub columns: Vec<Identifier>,
139137
pub sync_creation: bool,
@@ -155,14 +153,7 @@ impl Display for CreateTableIndexStmt {
155153
}
156154

157155
write!(f, " {}", self.index_name)?;
158-
write!(f, " ON ")?;
159-
write_dot_separated_list(
160-
f,
161-
self.catalog
162-
.iter()
163-
.chain(&self.database)
164-
.chain(Some(&self.table)),
165-
)?;
156+
write!(f, " ON {}", self.table)?;
166157
write!(f, " (")?;
167158
write_comma_separated_list(f, &self.columns)?;
168159
write!(f, ")")?;
@@ -181,9 +172,7 @@ pub struct DropTableIndexStmt {
181172
pub if_exists: bool,
182173
pub index_name: Identifier,
183174
pub index_type: TableIndexType,
184-
pub catalog: Option<Identifier>,
185-
pub database: Option<Identifier>,
186-
pub table: Identifier,
175+
pub table: TableRef,
187176
}
188177

189178
impl Display for DropTableIndexStmt {
@@ -194,14 +183,7 @@ impl Display for DropTableIndexStmt {
194183
}
195184

196185
write!(f, " {}", self.index_name)?;
197-
write!(f, " ON ")?;
198-
write_dot_separated_list(
199-
f,
200-
self.catalog
201-
.iter()
202-
.chain(&self.database)
203-
.chain(Some(&self.table)),
204-
)?;
186+
write!(f, " ON {}", self.table)?;
205187
Ok(())
206188
}
207189
}
@@ -210,24 +192,15 @@ impl Display for DropTableIndexStmt {
210192
pub struct RefreshTableIndexStmt {
211193
pub index_name: Identifier,
212194
pub index_type: TableIndexType,
213-
pub catalog: Option<Identifier>,
214-
pub database: Option<Identifier>,
215-
pub table: Identifier,
195+
pub table: TableRef,
216196
pub limit: Option<u64>,
217197
}
218198

219199
impl Display for RefreshTableIndexStmt {
220200
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
221201
write!(f, "REFRESH {} INDEX", self.index_type)?;
222202
write!(f, " {}", self.index_name)?;
223-
write!(f, " ON ")?;
224-
write_dot_separated_list(
225-
f,
226-
self.catalog
227-
.iter()
228-
.chain(&self.database)
229-
.chain(Some(&self.table)),
230-
)?;
203+
write!(f, " ON {}", self.table)?;
231204
if let Some(limit) = self.limit {
232205
write!(f, " LIMIT {limit}")?;
233206
}

src/query/ast/src/ast/statements/insert_multi_table.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct IntoClause {
2828
pub catalog: Option<Identifier>,
2929
pub database: Option<Identifier>,
3030
pub table: Identifier,
31+
pub branch: Option<Identifier>,
3132
pub target_columns: Vec<Identifier>,
3233
pub source_columns: Vec<SourceExpr>,
3334
}
@@ -58,6 +59,9 @@ impl Display for IntoClause {
5859
write!(f, "{}.", database)?;
5960
}
6061
write!(f, "{}", self.table)?;
62+
if let Some(branch) = &self.branch {
63+
write!(f, "/{branch}")?;
64+
}
6165
if !self.target_columns.is_empty() {
6266
write!(f, " (")?;
6367
write_comma_separated_list(f, &self.target_columns)?;

src/query/ast/src/ast/statements/merge_into.rs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use crate::ast::TableRef;
2929
use crate::ast::TableReference;
3030
use crate::ast::WithOptions;
3131
use crate::ast::write_comma_separated_list;
32-
use crate::ast::write_dot_separated_list;
3332

3433
#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
3534
pub struct MutationUpdateExpr {
@@ -85,9 +84,7 @@ pub enum MergeOption {
8584
#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
8685
pub struct MergeIntoStmt {
8786
pub hints: Option<Hint>,
88-
pub catalog: Option<Identifier>,
89-
pub database: Option<Identifier>,
90-
pub table_ident: Identifier,
87+
pub table: TableRef,
9188
pub source: MutationSource,
9289
// target_alias is belong to target
9390
pub target_alias: Option<TableAlias>,
@@ -98,13 +95,7 @@ pub struct MergeIntoStmt {
9895
impl Display for MergeIntoStmt {
9996
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
10097
write!(f, "MERGE INTO ")?;
101-
write_dot_separated_list(
102-
f,
103-
self.catalog
104-
.iter()
105-
.chain(&self.database)
106-
.chain(Some(&self.table_ident)),
107-
)?;
98+
write!(f, "{}", self.table)?;
10899
if let Some(alias) = &self.target_alias {
109100
write!(f, " AS {}", alias.name)?;
110101
}
@@ -175,9 +166,7 @@ pub enum MutationSource {
175166
source_alias: TableAlias,
176167
},
177168
Table {
178-
catalog: Option<Identifier>,
179-
database: Option<Identifier>,
180-
table: Identifier,
169+
table: Box<TableRef>,
181170
alias: Option<TableAlias>,
182171
with_options: Option<WithOptions>,
183172
},
@@ -198,19 +187,12 @@ impl MutationSource {
198187
unpivot: None,
199188
},
200189
Self::Table {
201-
catalog,
202-
database,
203190
table,
204191
with_options,
205192
alias,
206193
} => TableReference::Table {
207194
span: None,
208-
table: TableRef {
209-
catalog: catalog.clone(),
210-
database: database.clone(),
211-
table: table.clone(),
212-
branch: None,
213-
},
195+
table: table.as_ref().clone(),
214196
alias: alias.clone(),
215197
temporal: None,
216198
with_options: with_options.clone(),
@@ -231,16 +213,11 @@ impl Display for MutationSource {
231213
} => write!(f, "({query}) AS {source_alias}"),
232214

233215
MutationSource::Table {
234-
catalog,
235-
database,
236216
table,
237217
with_options,
238218
alias,
239219
} => {
240-
write_dot_separated_list(
241-
f,
242-
catalog.iter().chain(database.iter()).chain(Some(table)),
243-
)?;
220+
write!(f, "{}", table.as_ref())?;
244221
if let Some(with_options) = with_options {
245222
write!(f, " {with_options}")?;
246223
}

src/query/ast/src/ast/statements/replace.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ use crate::ast::Expr;
2424
use crate::ast::Hint;
2525
use crate::ast::Identifier;
2626
use crate::ast::InsertSource;
27+
use crate::ast::TableRef;
2728
use crate::ast::write_comma_separated_list;
28-
use crate::ast::write_dot_separated_list;
2929

3030
#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
3131
pub struct ReplaceStmt {
3232
pub hints: Option<Hint>,
33-
pub catalog: Option<Identifier>,
34-
pub database: Option<Identifier>,
35-
pub table: Identifier,
33+
pub table: TableRef,
3634
pub is_conflict: bool,
3735
pub on_conflict_columns: Vec<Identifier>,
3836
pub columns: Vec<Identifier>,
@@ -47,13 +45,7 @@ impl Display for ReplaceStmt {
4745
write!(f, " {}", hints)?;
4846
}
4947
write!(f, " INTO ")?;
50-
write_dot_separated_list(
51-
f,
52-
self.catalog
53-
.iter()
54-
.chain(&self.database)
55-
.chain(Some(&self.table)),
56-
)?;
48+
write!(f, "{}", self.table)?;
5749

5850
if !self.columns.is_empty() {
5951
write!(f, " (")?;

0 commit comments

Comments
 (0)