Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7044 from lichuang/share_sql
feat: add alter share tenants sql
- Loading branch information
Showing
14 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2022 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::sync::Arc; | ||
|
||
use common_datavalues::chrono::Utc; | ||
use common_exception::Result; | ||
use common_meta_api::ShareApi; | ||
use common_meta_app::share::AddShareAccountsReq; | ||
use common_meta_app::share::RemoveShareAccountsReq; | ||
use common_meta_app::share::ShareNameIdent; | ||
use common_streams::DataBlockStream; | ||
use common_streams::SendableDataBlockStream; | ||
|
||
use crate::interpreters::Interpreter; | ||
use crate::sessions::QueryContext; | ||
use crate::sessions::TableContext; | ||
use crate::sql::plans::share::AlterShareTenantsPlan; | ||
|
||
pub struct AlterShareTenantsInterpreter { | ||
ctx: Arc<QueryContext>, | ||
plan: AlterShareTenantsPlan, | ||
} | ||
|
||
impl AlterShareTenantsInterpreter { | ||
pub fn try_create(ctx: Arc<QueryContext>, plan: AlterShareTenantsPlan) -> Result<Self> { | ||
Ok(AlterShareTenantsInterpreter { ctx, plan }) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Interpreter for AlterShareTenantsInterpreter { | ||
fn name(&self) -> &str { | ||
"AlterShareTenantsInterpreter" | ||
} | ||
|
||
async fn execute(&self) -> Result<SendableDataBlockStream> { | ||
let tenant = self.ctx.get_tenant(); | ||
let user_mgr = self.ctx.get_user_manager(); | ||
let meta_api = user_mgr.get_meta_store_client(); | ||
if self.plan.is_add { | ||
let req = AddShareAccountsReq { | ||
share_name: ShareNameIdent { | ||
tenant, | ||
share_name: self.plan.share.clone(), | ||
}, | ||
if_exists: self.plan.if_exists, | ||
accounts: self.plan.accounts.clone(), | ||
share_on: Utc::now(), | ||
}; | ||
meta_api.add_share_accounts(req).await?; | ||
} else { | ||
let req = RemoveShareAccountsReq { | ||
share_name: ShareNameIdent { | ||
tenant, | ||
share_name: self.plan.share.clone(), | ||
}, | ||
if_exists: self.plan.if_exists, | ||
accounts: self.plan.accounts.clone(), | ||
}; | ||
meta_api.remove_share_accounts(req).await?; | ||
} | ||
|
||
Ok(Box::pin(DataBlockStream::create( | ||
self.plan.schema(), | ||
None, | ||
vec![], | ||
))) | ||
} | ||
} |
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
Oops, something went wrong.
bd12b79
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.
Successfully deployed to the following URLs:
databend – ./
databend.vercel.app
databend-git-main-databend.vercel.app
databend.rs
databend-databend.vercel.app