operator/statement/
describe.rs

1// Copyright 2023 Greptime Team
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
15use common_error::ext::BoxedError;
16use common_query::Output;
17use common_telemetry::tracing;
18use session::context::QueryContextRef;
19use session::table_name::table_idents_to_full_name;
20use snafu::{OptionExt, ResultExt};
21use sql::statements::describe::DescribeTable;
22use sql::util::format_raw_object_name;
23
24use crate::error::{
25    CatalogSnafu, DescribeStatementSnafu, ExternalSnafu, Result, TableNotFoundSnafu,
26};
27use crate::statement::StatementExecutor;
28
29impl StatementExecutor {
30    #[tracing::instrument(skip_all)]
31    pub(super) async fn describe_table(
32        &self,
33        stmt: DescribeTable,
34        query_ctx: QueryContextRef,
35    ) -> Result<Output> {
36        let (catalog, schema, table) = table_idents_to_full_name(stmt.name(), &query_ctx)
37            .map_err(BoxedError::new)
38            .context(ExternalSnafu)?;
39
40        let table = self
41            .catalog_manager
42            .table(&catalog, &schema, &table, Some(&query_ctx))
43            .await
44            .context(CatalogSnafu)?
45            .with_context(|| TableNotFoundSnafu {
46                table_name: format_raw_object_name(stmt.name()),
47            })?;
48
49        query::sql::describe_table(table).context(DescribeStatementSnafu)
50    }
51}