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

feat: support temporary table #16250

Merged
merged 58 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4cb711e
create temporary table
SkyFan2002 Aug 11, 2024
2ff9ad2
create as select
SkyFan2002 Aug 11, 2024
983fed1
fix create as select
SkyFan2002 Aug 11, 2024
7f38857
rename table
SkyFan2002 Aug 11, 2024
929a4d5
get_table_meta_by_id
SkyFan2002 Aug 12, 2024
4a8f940
get_table_name_by_id
SkyFan2002 Aug 12, 2024
9d899f4
not support stream on temp table
SkyFan2002 Aug 12, 2024
36960ce
fix get_table_name_by_id
SkyFan2002 Aug 12, 2024
74382a4
add comment
SkyFan2002 Aug 12, 2024
071c169
check access
SkyFan2002 Aug 13, 2024
a5b99fd
forbid grant and revoke
SkyFan2002 Aug 13, 2024
fa32f2b
get table
SkyFan2002 Aug 13, 2024
4849907
not support inverted index
SkyFan2002 Aug 13, 2024
0054373
not support virtual column
SkyFan2002 Aug 13, 2024
42b1f05
not support agg index
SkyFan2002 Aug 13, 2024
d93a5d9
not support data mask
SkyFan2002 Aug 13, 2024
fab9e46
,
SkyFan2002 Aug 13, 2024
5820f62
drop table by id
SkyFan2002 Aug 13, 2024
fde0bd0
refactor
SkyFan2002 Aug 14, 2024
1b80edf
update table meta
SkyFan2002 Aug 14, 2024
cf3e7aa
fix get table meta by id
SkyFan2002 Aug 14, 2024
62afd0d
get_table
SkyFan2002 Aug 15, 2024
f12345b
Merge remote-tracking branch 'upstream/main' into temp_table
SkyFan2002 Aug 15, 2024
0e99851
fix missing header
SkyFan2002 Aug 15, 2024
c0a8a0b
add create table test
SkyFan2002 Aug 15, 2024
b487795
rename folder
SkyFan2002 Aug 15, 2024
cfedf7d
commit before refactor
SkyFan2002 Aug 16, 2024
c8768c6
refactor
SkyFan2002 Aug 17, 2024
4555812
Merge remote-tracking branch 'upstream/main' into temp_table
SkyFan2002 Aug 17, 2024
c8bd015
make lint
SkyFan2002 Aug 17, 2024
3e4b73f
regenerate golden file
SkyFan2002 Aug 17, 2024
54925ed
fix catalog and add drop table test
SkyFan2002 Aug 17, 2024
a283982
fix catalog
SkyFan2002 Aug 18, 2024
3cbc84f
add alter temp table test
SkyFan2002 Aug 18, 2024
1f1f6af
fix show create table
SkyFan2002 Aug 18, 2024
83f56b8
add rename temp table test
SkyFan2002 Aug 18, 2024
b420373
add truncate test
SkyFan2002 Aug 18, 2024
09779f7
add copy into test
SkyFan2002 Aug 19, 2024
4d58866
fix copied file
SkyFan2002 Aug 19, 2024
57d8ae3
add log
SkyFan2002 Aug 19, 2024
35c0477
Merge branch 'main' into temp_table
SkyFan2002 Aug 19, 2024
f8d7cd8
add some check
SkyFan2002 Aug 19, 2024
dc85191
add drop_all_temp_tables()
SkyFan2002 Aug 19, 2024
ac64cf7
refine error message
SkyFan2002 Aug 19, 2024
15e7455
forbid alter temp prefix
SkyFan2002 Aug 19, 2024
1a80cee
remove useless println
SkyFan2002 Aug 19, 2024
0b9f5e0
adjust slt
SkyFan2002 Aug 19, 2024
0ce30cd
add privilege test
SkyFan2002 Aug 20, 2024
d3052d8
fix
SkyFan2002 Aug 20, 2024
850fcdc
Merge branch 'main' into temp_table
SkyFan2002 Aug 20, 2024
d901518
add assert
SkyFan2002 Aug 20, 2024
084118d
change print to log
SkyFan2002 Aug 21, 2024
bf121da
add temp table storage prefix
SkyFan2002 Aug 21, 2024
3d54fab
Merge remote-tracking branch 'upstream/main' into temp_table
SkyFan2002 Aug 21, 2024
8befcf6
Merge remote-tracking branch 'upstream/main' into temp_table
SkyFan2002 Aug 21, 2024
927924f
make lint
SkyFan2002 Aug 21, 2024
b12e0ab
fix prefix
SkyFan2002 Aug 22, 2024
9b28038
Merge remote-tracking branch 'upstream/main' into temp_table
SkyFan2002 Aug 22, 2024
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
40 changes: 22 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ members = [
"src/query/storages/common/io",
"src/query/storages/common/pruner",
"src/query/storages/common/stage",
"src/query/storages/common/txn",
"src/query/storages/common/session",
"src/query/storages/common/table_meta",
"src/query/storages/delta",
"src/query/storages/factory",
Expand Down Expand Up @@ -197,9 +197,9 @@ databend-storages-common-cache = { path = "src/query/storages/common/cache" }
databend-storages-common-index = { path = "src/query/storages/common/index" }
databend-storages-common-io = { path = "src/query/storages/common/io" }
databend-storages-common-pruner = { path = "src/query/storages/common/pruner" }
databend-storages-common-session = { path = "src/query/storages/common/session" }
databend-storages-common-stage = { path = "src/query/storages/common/stage" }
databend-storages-common-table-meta = { path = "src/query/storages/common/table_meta" }
databend-storages-common-txn = { path = "src/query/storages/common/txn" }

# Crates.io dependencies
anyerror = { version = "=0.1.10" }
Expand Down
3 changes: 2 additions & 1 deletion scripts/ci/ci-run-sqllogic-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ fi
echo "Run suites using argument: $RUN_DIR"

echo "Starting databend-sqllogic tests"
target/${BUILD_PROFILE}/databend-sqllogictests --handlers ${TEST_HANDLERS} ${RUN_DIR} --skip_dir management,explain_native,ee --enable_sandbox --parallel 8
target/${BUILD_PROFILE}/databend-sqllogictests --handlers "mysql" --run_dir temp_table --enable_sandbox --parallel 8
target/${BUILD_PROFILE}/databend-sqllogictests --handlers ${TEST_HANDLERS} ${RUN_DIR} --skip_dir management,explain_native,ee,temp_table --enable_sandbox --parallel 8
1 change: 1 addition & 0 deletions src/meta/api/src/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,7 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
copied_files,
update_stream_metas,
deduplicated_labels,
update_temp_tables: _,
} = req;

let mut tbl_seqs = HashMap::new();
Expand Down
1 change: 1 addition & 0 deletions src/meta/app/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub use table::UpdateMultiTableMetaResult;
pub use table::UpdateStreamMetaReq;
pub use table::UpdateTableMetaReply;
pub use table::UpdateTableMetaReq;
pub use table::UpdateTempTableReq;
pub use table::UpsertTableCopiedFileReply;
pub use table::UpsertTableCopiedFileReq;
pub use table::UpsertTableOptionReply;
Expand Down
26 changes: 24 additions & 2 deletions src/meta/app/src/schema/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Display for TableIdent {
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct TableNameIdent {
pub tenant: Tenant,
pub db_name: String,
Expand Down Expand Up @@ -188,6 +188,9 @@ impl Display for DatabaseType {

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq, Default)]
pub struct TableInfo {
/// For a temp table,
/// `ident.seq` is always 0.
/// `id.table_id` is set as value of `TempTblId`.
pub ident: TableIdent,

/// For a table it is `db_name.table_name`.
Expand Down Expand Up @@ -581,7 +584,7 @@ impl Display for DropTableByIdReq {
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct DropTableReply {
// db id, share spec vector
pub spec_vec: Option<(u64, Vec<ShareSpec>)>,
Expand Down Expand Up @@ -720,12 +723,31 @@ pub struct UpdateTableMetaReq {
pub new_table_meta: TableMeta,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UpdateTempTableReq {
pub table_id: u64,
pub desc: String,
pub new_table_meta: TableMeta,
pub copied_files: BTreeMap<String, TableCopiedFileInfo>,
}

#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct UpdateMultiTableMetaReq {
pub update_table_metas: Vec<(UpdateTableMetaReq, TableInfo)>,
pub copied_files: Vec<(u64, UpsertTableCopiedFileReq)>,
pub update_stream_metas: Vec<UpdateStreamMetaReq>,
pub deduplicated_labels: Vec<String>,
pub update_temp_tables: Vec<UpdateTempTableReq>,
}

impl UpdateMultiTableMetaReq {
pub fn is_empty(&self) -> bool {
self.update_table_metas.is_empty()
&& self.copied_files.is_empty()
&& self.update_stream_metas.is_empty()
&& self.deduplicated_labels.is_empty()
&& self.update_temp_tables.is_empty()
}
}

/// The result of updating multiple table meta
Expand Down
9 changes: 5 additions & 4 deletions src/query/ast/src/ast/format/syntax/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::ast::CreateStreamStmt;
use crate::ast::CreateTableSource;
use crate::ast::CreateTableStmt;
use crate::ast::CreateViewStmt;
use crate::ast::TableType;
use crate::ast::TimeTravelPoint;

pub(crate) fn pretty_create_table(stmt: CreateTableStmt) -> RcDoc<'static> {
Expand All @@ -40,10 +41,10 @@ pub(crate) fn pretty_create_table(stmt: CreateTableStmt) -> RcDoc<'static> {
} else {
RcDoc::nil()
})
.append(if stmt.transient {
RcDoc::space().append(RcDoc::text("TRANSIENT"))
} else {
RcDoc::nil()
.append(match stmt.table_type {
TableType::Transient => RcDoc::space().append(RcDoc::text("TRANSIENT")),
TableType::Temporary => RcDoc::space().append(RcDoc::text("TEMPORARY")),
TableType::Normal => RcDoc::nil(),
})
.append(RcDoc::space().append(RcDoc::text("TABLE")))
.append(match stmt.create_option {
Expand Down
17 changes: 13 additions & 4 deletions src/query/ast/src/ast/statements/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ pub struct CreateTableStmt {
pub cluster_by: Vec<Expr>,
pub table_options: BTreeMap<String, String>,
pub as_query: Option<Box<Query>>,
pub transient: bool,
pub table_type: TableType,
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub enum TableType {
Normal,
Transient,
Temporary,
}

impl Display for CreateTableStmt {
Expand All @@ -149,9 +156,11 @@ impl Display for CreateTableStmt {
if let CreateOption::CreateOrReplace = self.create_option {
write!(f, "OR REPLACE ")?;
}
if self.transient {
write!(f, "TRANSIENT ")?;
}
match self.table_type {
TableType::Normal => {}
TableType::Transient => write!(f, "TRANSIENT ")?,
TableType::Temporary => write!(f, "TEMPORARY ")?,
};
write!(f, "TABLE ")?;
if let CreateOption::CreateIfNotExists = self.create_option {
write!(f, "IF NOT EXISTS ")?;
Expand Down
12 changes: 9 additions & 3 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
);
let create_table = map_res(
rule! {
CREATE ~ ( OR ~ ^REPLACE )? ~ TRANSIENT? ~ TABLE ~ ( IF ~ ^NOT ~ ^EXISTS )?
CREATE ~ ( OR ~ ^REPLACE )? ~ (TEMP| TEMPORARY|TRANSIENT)? ~ TABLE ~ ( IF ~ ^NOT ~ ^EXISTS )?
~ #dot_separated_idents_1_to_3
~ #create_table_source?
~ ( #engine )?
Expand All @@ -709,7 +709,7 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
|(
_,
opt_or_replace,
opt_transient,
opt_type,
_,
opt_if_not_exists,
(catalog, database, table),
Expand All @@ -722,6 +722,12 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
)| {
let create_option =
parse_create_option(opt_or_replace.is_some(), opt_if_not_exists.is_some())?;
let table_type = match opt_type.map(|t| t.kind) {
None => TableType::Normal,
Some(TRANSIENT) => TableType::Transient,
Some(TEMP) | Some(TEMPORARY) => TableType::Temporary,
_ => unreachable!(),
};
Ok(Statement::CreateTable(CreateTableStmt {
create_option,
catalog,
Expand All @@ -735,7 +741,7 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
.unwrap_or_default(),
table_options: opt_table_options.unwrap_or_default(),
as_query: opt_as_query.map(|(_, query)| Box::new(query)),
transient: opt_transient.is_some(),
table_type,
}))
},
);
Expand Down
2 changes: 2 additions & 0 deletions src/query/ast/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,8 @@ pub enum TokenKind {
ROLLBACK,
#[token("TEMPORARY", ignore(ascii_case))]
TEMPORARY,
#[token("TEMP", ignore(ascii_case))]
TEMP,
#[token("SECONDS", ignore(ascii_case))]
SECONDS,
#[token("DAYS", ignore(ascii_case))]
Expand Down
Loading
Loading