|
| 1 | +// Copyright 2023 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::fmt::Display; |
| 16 | +use std::fmt::Formatter; |
| 17 | + |
| 18 | +use crate::ast::Identifier; |
| 19 | +use crate::ast::ShowLimit; |
| 20 | + |
| 21 | +#[derive(Debug, Clone, PartialEq)] // Columns |
| 22 | +pub struct ShowColumnsStmt { |
| 23 | + pub catalog: Option<Identifier>, |
| 24 | + pub database: Option<Identifier>, |
| 25 | + pub table: Identifier, |
| 26 | + pub full: bool, |
| 27 | + pub limit: Option<ShowLimit>, |
| 28 | +} |
| 29 | + |
| 30 | +impl Display for ShowColumnsStmt { |
| 31 | + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { |
| 32 | + write!(f, "SHOW")?; |
| 33 | + if self.full { |
| 34 | + write!(f, " FULL")?; |
| 35 | + } |
| 36 | + write!(f, " COLUMNS FROM {}", self.table)?; |
| 37 | + |
| 38 | + if let Some(database) = &self.database { |
| 39 | + write!(f, " FROM ")?; |
| 40 | + if let Some(catalog) = &self.catalog { |
| 41 | + write!(f, "{catalog}.",)?; |
| 42 | + } |
| 43 | + write!(f, "{database}")?; |
| 44 | + } |
| 45 | + |
| 46 | + if let Some(limit) = &self.limit { |
| 47 | + write!(f, " {limit}")?; |
| 48 | + } |
| 49 | + |
| 50 | + Ok(()) |
| 51 | + } |
| 52 | +} |
0 commit comments