|
| 1 | +// Copyright 2022 Datafuse Labs. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use std::sync::Arc; |
| 16 | + |
| 17 | +use common_exception::Result; |
| 18 | +use common_meta_api::ShareApi; |
| 19 | +use common_streams::DataBlockStream; |
| 20 | +use common_streams::SendableDataBlockStream; |
| 21 | + |
| 22 | +use crate::interpreters::Interpreter; |
| 23 | +use crate::sessions::QueryContext; |
| 24 | +use crate::sessions::TableContext; |
| 25 | +use crate::sql::plans::share::DropSharePlan; |
| 26 | + |
| 27 | +pub struct DropShareInterpreter { |
| 28 | + ctx: Arc<QueryContext>, |
| 29 | + plan: DropSharePlan, |
| 30 | +} |
| 31 | + |
| 32 | +impl DropShareInterpreter { |
| 33 | + pub fn try_create(ctx: Arc<QueryContext>, plan: DropSharePlan) -> Result<Self> { |
| 34 | + Ok(DropShareInterpreter { ctx, plan }) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +#[async_trait::async_trait] |
| 39 | +impl Interpreter for DropShareInterpreter { |
| 40 | + fn name(&self) -> &str { |
| 41 | + "DropShareInterpreter" |
| 42 | + } |
| 43 | + |
| 44 | + async fn execute(&self) -> Result<SendableDataBlockStream> { |
| 45 | + let user_mgr = self.ctx.get_user_manager(); |
| 46 | + let meta_api = user_mgr.get_meta_store_client(); |
| 47 | + meta_api.drop_share(self.plan.clone().into()).await?; |
| 48 | + |
| 49 | + Ok(Box::pin(DataBlockStream::create( |
| 50 | + self.plan.schema(), |
| 51 | + None, |
| 52 | + vec![], |
| 53 | + ))) |
| 54 | + } |
| 55 | +} |
0 commit comments