-
Notifications
You must be signed in to change notification settings - Fork 760
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 vacuum temporary table #16364
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d15baed
feat: support vacuum temporary table
SkyFan2002 b1920bf
Merge branch 'main' into vacuum_tmp
SkyFan2002 e56a5e2
fix slt
SkyFan2002 c578069
add system.temporary_tables
SkyFan2002 312c71a
Merge branch 'main' into vacuum_tmp
SkyFan2002 4d1470d
fix ut
SkyFan2002 ef169f3
Merge branch 'main' into vacuum_tmp
SkyFan2002 bf00bb8
adjust log
SkyFan2002 f9b5d0d
remove debug level log
SkyFan2002 6c0dd5d
Merge branch 'main' into vacuum_tmp
SkyFan2002 d367ab7
make lint
SkyFan2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/query/storages/fuse/src/table_functions/fuse_vacuum_temporary_table.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::collections::HashSet; | ||
use std::sync::Arc; | ||
|
||
use databend_common_catalog::plan::DataSourcePlan; | ||
use databend_common_exception::ErrorCode; | ||
use databend_common_exception::Result; | ||
use databend_common_expression::types::StringType; | ||
use databend_common_expression::DataBlock; | ||
use databend_common_expression::FromData; | ||
use databend_common_expression::TableDataType; | ||
use databend_common_expression::TableField; | ||
use databend_common_expression::TableSchemaRef; | ||
use databend_common_expression::TableSchemaRefExt; | ||
use databend_common_storage::DataOperator; | ||
use databend_common_users::UserApiProvider; | ||
use databend_storages_common_table_meta::meta::TEMP_TABLE_STORAGE_PREFIX; | ||
use futures_util::TryStreamExt; | ||
use log::debug; | ||
use log::info; | ||
use uuid::Uuid; | ||
|
||
use crate::sessions::TableContext; | ||
use crate::table_functions::SimpleTableFunc; | ||
use crate::table_functions::TableArgs; | ||
pub struct FuseVacuumTemporaryTable; | ||
|
||
#[async_trait::async_trait] | ||
impl SimpleTableFunc for FuseVacuumTemporaryTable { | ||
fn get_engine_name(&self) -> String { | ||
"fuse_vacuum_temporary_table".to_owned() | ||
} | ||
|
||
fn table_args(&self) -> Option<TableArgs> { | ||
None | ||
} | ||
|
||
fn schema(&self) -> TableSchemaRef { | ||
TableSchemaRefExt::create(vec![TableField::new("result", TableDataType::String)]) | ||
} | ||
|
||
async fn apply( | ||
&self, | ||
ctx: &Arc<dyn TableContext>, | ||
_plan: &DataSourcePlan, | ||
) -> Result<Option<DataBlock>> { | ||
let op = DataOperator::instance().operator(); | ||
let mut lister = op | ||
.lister_with(TEMP_TABLE_STORAGE_PREFIX) | ||
.recursive(true) | ||
.await?; | ||
let client_session_mgr = UserApiProvider::instance().client_session_api(&ctx.get_tenant()); | ||
let mut session_ids = HashSet::new(); | ||
while let Some(entry) = lister.try_next().await? { | ||
let path = entry.path(); | ||
debug!("path: {}", path); | ||
if let Some(session_id) = path.split('/').nth(1) { | ||
if session_id.is_empty() { | ||
continue; | ||
} | ||
// check if session_id is a valid uuid | ||
let _ = Uuid::parse_str(session_id) | ||
.map_err(|e| ErrorCode::Internal(format!("Invalid session_id: {}", e)))?; | ||
debug!("session_id: {}", session_id); | ||
SkyFan2002 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
session_ids.insert(session_id.to_string()); | ||
} | ||
} | ||
for session_id in session_ids { | ||
if client_session_mgr | ||
.get_client_session(&session_id) | ||
.await? | ||
.is_none() | ||
{ | ||
let path = format!("{}/{}", TEMP_TABLE_STORAGE_PREFIX, session_id); | ||
info!("Removing temporary table: {}", path); | ||
op.remove_all(&path).await?; | ||
} | ||
} | ||
let col: Vec<String> = vec!["Ok".to_owned()]; | ||
|
||
Ok(Some(DataBlock::new_from_columns(vec![ | ||
StringType::from_data(col), | ||
]))) | ||
} | ||
|
||
fn create(_func_name: &str, _table_args: TableArgs) -> Result<Self> | ||
where Self: Sized { | ||
Ok(Self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why disable http SessionType?