mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-13 07:22:02 +00:00
Support EXPLAIN
/ DESCR
/ DESCRIBE
[FORMATTED | EXTENDED]
(#1156)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
991dbab755
commit
ef4668075b
5 changed files with 103 additions and 30 deletions
|
@ -2436,22 +2436,24 @@ pub enum Statement {
|
|||
id: u64,
|
||||
},
|
||||
/// ```sql
|
||||
/// EXPLAIN TABLE
|
||||
/// [EXPLAIN | DESC | DESCRIBE] TABLE
|
||||
/// ```
|
||||
/// Note: this is a MySQL-specific statement. See <https://dev.mysql.com/doc/refman/8.0/en/explain.html>
|
||||
ExplainTable {
|
||||
/// If true, query used the MySQL `DESCRIBE` alias for explain
|
||||
describe_alias: bool,
|
||||
/// `EXPLAIN | DESC | DESCRIBE`
|
||||
describe_alias: DescribeAlias,
|
||||
/// Hive style `FORMATTED | EXTENDED`
|
||||
hive_format: Option<HiveDescribeFormat>,
|
||||
/// Table name
|
||||
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
|
||||
table_name: ObjectName,
|
||||
},
|
||||
/// ```sql
|
||||
/// [EXPLAIN | DESCRIBE <select statement>
|
||||
/// [EXPLAIN | DESC | DESCRIBE] <statement>
|
||||
/// ```
|
||||
Explain {
|
||||
// If true, query used the MySQL `DESCRIBE` alias for explain
|
||||
describe_alias: bool,
|
||||
/// `EXPLAIN | DESC | DESCRIBE`
|
||||
describe_alias: DescribeAlias,
|
||||
/// Carry out the command and show actual run times and other statistics.
|
||||
analyze: bool,
|
||||
// Display additional information regarding the plan.
|
||||
|
@ -2611,12 +2613,13 @@ impl fmt::Display for Statement {
|
|||
}
|
||||
Statement::ExplainTable {
|
||||
describe_alias,
|
||||
hive_format,
|
||||
table_name,
|
||||
} => {
|
||||
if *describe_alias {
|
||||
write!(f, "DESCRIBE ")?;
|
||||
} else {
|
||||
write!(f, "EXPLAIN ")?;
|
||||
write!(f, "{describe_alias} ")?;
|
||||
|
||||
if let Some(format) = hive_format {
|
||||
write!(f, "{} ", format)?;
|
||||
}
|
||||
|
||||
write!(f, "{table_name}")
|
||||
|
@ -2628,11 +2631,7 @@ impl fmt::Display for Statement {
|
|||
statement,
|
||||
format,
|
||||
} => {
|
||||
if *describe_alias {
|
||||
write!(f, "DESCRIBE ")?;
|
||||
} else {
|
||||
write!(f, "EXPLAIN ")?;
|
||||
}
|
||||
write!(f, "{describe_alias} ")?;
|
||||
|
||||
if *analyze {
|
||||
write!(f, "ANALYZE ")?;
|
||||
|
@ -4925,6 +4924,44 @@ impl fmt::Display for HiveDelimiter {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum HiveDescribeFormat {
|
||||
Extended,
|
||||
Formatted,
|
||||
}
|
||||
|
||||
impl fmt::Display for HiveDescribeFormat {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use HiveDescribeFormat::*;
|
||||
f.write_str(match self {
|
||||
Extended => "EXTENDED",
|
||||
Formatted => "FORMATTED",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum DescribeAlias {
|
||||
Describe,
|
||||
Explain,
|
||||
Desc,
|
||||
}
|
||||
|
||||
impl fmt::Display for DescribeAlias {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use DescribeAlias::*;
|
||||
f.write_str(match self {
|
||||
Describe => "DESCRIBE",
|
||||
Explain => "EXPLAIN",
|
||||
Desc => "DESC",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue