This is an automated email from the ASF dual-hosted git repository.
iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new eae5629f Support optional table for `ANALYZE` statement (#1599)
eae5629f is described below
commit eae5629fb86f5e262063c0bc99ff628a5855168f
Author: yuyang <[email protected]>
AuthorDate: Thu Dec 19 17:18:45 2024 +0800
Support optional table for `ANALYZE` statement (#1599)
---
src/ast/mod.rs | 8 +++++++-
src/ast/spans.rs | 1 +
src/parser/mod.rs | 3 ++-
tests/sqlparser_common.rs | 6 ++++++
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 6e3f2047..39b97463 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -2354,6 +2354,7 @@ pub enum Statement {
cache_metadata: bool,
noscan: bool,
compute_statistics: bool,
+ has_table_keyword: bool,
},
/// ```sql
/// TRUNCATE
@@ -3651,8 +3652,13 @@ impl fmt::Display for Statement {
cache_metadata,
noscan,
compute_statistics,
+ has_table_keyword,
} => {
- write!(f, "ANALYZE TABLE {table_name}")?;
+ write!(
+ f,
+ "ANALYZE{}{table_name}",
+ if *has_table_keyword { " TABLE " } else { " " }
+ )?;
if let Some(ref parts) = partitions {
if !parts.is_empty() {
write!(f, " PARTITION ({})",
display_comma_separated(parts))?;
diff --git a/src/ast/spans.rs b/src/ast/spans.rs
index c2c7c14f..6168587c 100644
--- a/src/ast/spans.rs
+++ b/src/ast/spans.rs
@@ -284,6 +284,7 @@ impl Spanned for Statement {
cache_metadata: _,
noscan: _,
compute_statistics: _,
+ has_table_keyword: _,
} => union_spans(
core::iter::once(table_name.span())
.chain(partitions.iter().flat_map(|i| i.iter().map(|k|
k.span())))
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index ae44de1b..570b2397 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -851,7 +851,7 @@ impl<'a> Parser<'a> {
}
pub fn parse_analyze(&mut self) -> Result<Statement, ParserError> {
- self.expect_keyword(Keyword::TABLE)?;
+ let has_table_keyword = self.parse_keyword(Keyword::TABLE);
let table_name = self.parse_object_name(false)?;
let mut for_columns = false;
let mut cache_metadata = false;
@@ -896,6 +896,7 @@ impl<'a> Parser<'a> {
}
Ok(Statement::Analyze {
+ has_table_keyword,
table_name,
for_columns,
columns,
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index d04066c7..f18daa52 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -562,6 +562,12 @@ fn parse_select_with_table_alias() {
);
}
+#[test]
+fn parse_analyze() {
+ verified_stmt("ANALYZE TABLE test_table");
+ verified_stmt("ANALYZE test_table");
+}
+
#[test]
fn parse_invalid_table_name() {
let ast = all_dialects().run_parser_method("db.public..customer", |parser|
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]