From 4cddbdd4a514b79168ccb6e950d858e1ef72757b Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Tue, 28 May 2024 23:40:04 +0800 Subject: [PATCH 01/16] feature: add mv to parse --- src/ast/mod.rs | 2 ++ src/parser/mod.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index c9de747c7..1f8db84c3 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -1964,6 +1964,7 @@ pub enum Statement { if_not_exists: bool, /// if true, has SQLite `TEMP` or `TEMPORARY` clause temporary: bool, + to: Option, }, /// ```sql /// CREATE TABLE @@ -3229,6 +3230,7 @@ impl fmt::Display for Statement { with_no_schema_binding, if_not_exists, temporary, + .. } => { write!( f, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index f88aefd10..cd7680337 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3902,7 +3902,25 @@ impl<'a> Parser<'a> { } }; } - + println!("to qweqeqe"); + let mut to = Option::None; + if dialect_of!(self is ClickHouseDialect) { + println!("to {:}", self.peek_token().token); + if let Token::Word(word) = self.peek_token().token { + if word.keyword == Keyword::TO { + let _ = self.parse_keyword(Keyword::TO); + let indet = self.parse_object_name(false); + if indet.is_ok(){ + // println!("to {}",indet.unwrap()); + to = Some(indet.unwrap()); + } + // let opts = self.parse_options(Keyword::OPTIONS)?; + // if !opts.is_empty() { + // options = CreateTableOptions::Options(opts); + // } + } + }; + } self.expect_keyword(Keyword::AS)?; let query = self.parse_boxed_query()?; // Optional `WITH [ CASCADED | LOCAL ] CHECK OPTION` is widely supported here. @@ -3926,6 +3944,7 @@ impl<'a> Parser<'a> { with_no_schema_binding, if_not_exists, temporary, + to, }) } @@ -11284,4 +11303,24 @@ mod tests { assert!(Parser::parse_sql(&MySqlDialect {}, sql).is_err()); } + + #[test] + fn test_create_matireal_view_test() { + // NOTE: This is actually valid MySQL syntax, REPLACE and INSERT, + // but the parser does not yet support it. + // https://dev.mysql.com/doc/refman/8.3/en/insert.html + let sql = "CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv + TO analytics.monthly_aggregated_data + AS + SELECT + toDate(toStartOfMonth(event_time)) AS month, + domain_name, + sumState(count_views) AS sumCountViews + FROM analytics.hourly_data + GROUP BY + domain_name, + month "; + + assert!(Parser::parse_sql(&ClickHouseDialect {}, sql).is_ok()); + } } From 9e2395fe3d4c8000f558a631ce23ae9da8d92749 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Tue, 11 Jun 2024 23:47:15 +0800 Subject: [PATCH 02/16] add to --- src/ast/mod.rs | 7 ++++--- src/parser/mod.rs | 7 ------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 1f8db84c3..656f96fa4 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -3230,16 +3230,17 @@ impl fmt::Display for Statement { with_no_schema_binding, if_not_exists, temporary, - .. + to, } => { write!( f, - "CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name}", + "CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name} {to}", or_replace = if *or_replace { "OR REPLACE " } else { "" }, materialized = if *materialized { "MATERIALIZED " } else { "" }, name = name, temporary = if *temporary { "TEMPORARY " } else { "" }, - if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" } + if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }, + to = if to.is_some() { format!("TO {to:?} ") } else { "".to_string() } )?; if matches!(options, CreateTableOptions::With(_)) { write!(f, " {options}")?; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index cd7680337..93ecadc1b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3902,22 +3902,15 @@ impl<'a> Parser<'a> { } }; } - println!("to qweqeqe"); let mut to = Option::None; if dialect_of!(self is ClickHouseDialect) { - println!("to {:}", self.peek_token().token); if let Token::Word(word) = self.peek_token().token { if word.keyword == Keyword::TO { let _ = self.parse_keyword(Keyword::TO); let indet = self.parse_object_name(false); if indet.is_ok(){ - // println!("to {}",indet.unwrap()); to = Some(indet.unwrap()); } - // let opts = self.parse_options(Keyword::OPTIONS)?; - // if !opts.is_empty() { - // options = CreateTableOptions::Options(opts); - // } } }; } From 14c25fcf479459ad701fc2ffb6fbe47e333fb4a1 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Wed, 12 Jun 2024 23:34:50 +0800 Subject: [PATCH 03/16] add to --- tests/sqlparser_bigquery.rs | 1 + tests/sqlparser_common.rs | 7 +++++++ tests/sqlparser_sqlite.rs | 1 + 3 files changed, 9 insertions(+) diff --git a/tests/sqlparser_bigquery.rs b/tests/sqlparser_bigquery.rs index 179755e0c..5632ea7ef 100644 --- a/tests/sqlparser_bigquery.rs +++ b/tests/sqlparser_bigquery.rs @@ -312,6 +312,7 @@ fn parse_create_view_if_not_exists() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("mydataset.newview", name.to_string()); assert_eq!(Vec::::new(), columns); diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index f8b7d0265..5b7d1e454 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -6254,6 +6254,7 @@ fn parse_create_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6308,6 +6309,7 @@ fn parse_create_view_with_columns() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("v", name.to_string()); assert_eq!( @@ -6348,6 +6350,7 @@ fn parse_create_view_temporary() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6379,6 +6382,7 @@ fn parse_create_or_replace_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("v", name.to_string()); assert_eq!(columns, vec![]); @@ -6414,6 +6418,7 @@ fn parse_create_or_replace_materialized_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("v", name.to_string()); assert_eq!(columns, vec![]); @@ -6445,6 +6450,7 @@ fn parse_create_materialized_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6476,6 +6482,7 @@ fn parse_create_materialized_view_with_cluster_by() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); diff --git a/tests/sqlparser_sqlite.rs b/tests/sqlparser_sqlite.rs index 5742754c0..38bdd9a71 100644 --- a/tests/sqlparser_sqlite.rs +++ b/tests/sqlparser_sqlite.rs @@ -170,6 +170,7 @@ fn parse_create_view_temporary_if_not_exists() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); From 28691540bf1338fa9826a3d88935ca0717194de8 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Wed, 12 Jun 2024 23:44:54 +0800 Subject: [PATCH 04/16] add to --- src/ast/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 656f96fa4..7b82fbd9f 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -3234,13 +3234,13 @@ impl fmt::Display for Statement { } => { write!( f, - "CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name} {to}", + "CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name}{to}", or_replace = if *or_replace { "OR REPLACE " } else { "" }, materialized = if *materialized { "MATERIALIZED " } else { "" }, name = name, temporary = if *temporary { "TEMPORARY " } else { "" }, if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }, - to = if to.is_some() { format!("TO {to:?} ") } else { "".to_string() } + to = if to.is_some() { format!(" TO {to:?} ") } else { "".to_string() } )?; if matches!(options, CreateTableOptions::With(_)) { write!(f, " {options}")?; From b82e423abcf62d80063aaf240ecd973cc3318386 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Wed, 12 Jun 2024 23:46:40 +0800 Subject: [PATCH 05/16] add to --- src/ast/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 7b82fbd9f..3ad199dc7 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -3240,7 +3240,7 @@ impl fmt::Display for Statement { name = name, temporary = if *temporary { "TEMPORARY " } else { "" }, if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }, - to = if to.is_some() { format!(" TO {to:?} ") } else { "".to_string() } + to = if to.is_some() { format!("TO {to:?} ") } else { "".to_string() } )?; if matches!(options, CreateTableOptions::With(_)) { write!(f, " {options}")?; From 35f047f72e13f3bfa594e62c779a6d204827c985 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Sat, 15 Jun 2024 17:24:51 +0800 Subject: [PATCH 06/16] add example sql --- src/parser/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 93ecadc1b..6df5b0da9 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -11299,9 +11299,8 @@ mod tests { #[test] fn test_create_matireal_view_test() { - // NOTE: This is actually valid MySQL syntax, REPLACE and INSERT, - // but the parser does not yet support it. - // https://dev.mysql.com/doc/refman/8.3/en/insert.html + // example sql + // https://clickhouse.com/docs/en/guides/developer/cascading-materialized-views let sql = "CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv TO analytics.monthly_aggregated_data AS From eadec5c495caac8c2045207c089d802d48a654c3 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Sat, 15 Jun 2024 17:46:44 +0800 Subject: [PATCH 07/16] add example sql --- src/ast/mod.rs | 5 ++++- src/parser/mod.rs | 19 ------------------- tests/sqlparser_clickhouse.rs | 8 ++++++++ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 3ad199dc7..5855a7d28 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -3240,7 +3240,10 @@ impl fmt::Display for Statement { name = name, temporary = if *temporary { "TEMPORARY " } else { "" }, if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }, - to = if to.is_some() { format!("TO {to:?} ") } else { "".to_string() } + to = if to.is_some() { + let some = to.as_ref().unwrap(); + format!(" TO {some}") + } else { "".to_string() } )?; if matches!(options, CreateTableOptions::With(_)) { write!(f, " {options}")?; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 6df5b0da9..bbcaecd40 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -11296,23 +11296,4 @@ mod tests { assert!(Parser::parse_sql(&MySqlDialect {}, sql).is_err()); } - - #[test] - fn test_create_matireal_view_test() { - // example sql - // https://clickhouse.com/docs/en/guides/developer/cascading-materialized-views - let sql = "CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv - TO analytics.monthly_aggregated_data - AS - SELECT - toDate(toStartOfMonth(event_time)) AS month, - domain_name, - sumState(count_views) AS sumCountViews - FROM analytics.hourly_data - GROUP BY - domain_name, - month "; - - assert!(Parser::parse_sql(&ClickHouseDialect {}, sql).is_ok()); - } } diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs index 7150a9489..61e7c89b1 100644 --- a/tests/sqlparser_clickhouse.rs +++ b/tests/sqlparser_clickhouse.rs @@ -251,6 +251,14 @@ fn parse_select_star_except_no_parens() { ); } +#[test] +fn test_create_matireal_view_test() { + // example sql + // https://clickhouse.com/docs/en/guides/developer/cascading-materialized-views + let sql = r#"CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv TO analytics.monthly_aggregated_data AS SELECT toDate(toStartOfMonth(event_time)) AS month, domain_name, sumState(count_views) AS sumCountViews FROM analytics.hourly_data GROUP BY domain_name, month"#; + clickhouse().verified_stmt(sql); +} + fn clickhouse() -> TestedDialects { TestedDialects { dialects: vec![Box::new(ClickHouseDialect {})], From 34be082d3660f222057f5756c14a36c397799dde Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Sat, 15 Jun 2024 17:49:54 +0800 Subject: [PATCH 08/16] fix conflict --- tests/sqlparser_snowflake.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index f0a7c7735..d525c751c 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -552,6 +552,7 @@ fn parse_sf_create_or_replace_with_comment_for_snowflake() { with_no_schema_binding: late_binding, if_not_exists, temporary, + .. } => { assert_eq!("v", name.to_string()); assert_eq!(columns, vec![]); From 470982f47f396d9f45ec31032ba2e35b6ac9c416 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Sun, 16 Jun 2024 23:41:03 +0800 Subject: [PATCH 09/16] Update src/ast/mod.rs Co-authored-by: Ifeanyi Ubah --- src/ast/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index f15f77d69..588866c6c 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -3340,10 +3340,7 @@ impl fmt::Display for Statement { name = name, temporary = if *temporary { "TEMPORARY " } else { "" }, if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }, - to = if to.is_some() { - let some = to.as_ref().unwrap(); - format!(" TO {some}") - } else { "".to_string() } + to = if to.as_ref().map(|to| format!(" TO {to}")).unwrap_or_default() )?; if let Some(comment) = comment { write!( From 4bcbbe072b06497c18a9351f3f757842f6d54d86 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Sun, 16 Jun 2024 23:41:19 +0800 Subject: [PATCH 10/16] Update tests/sqlparser_clickhouse.rs Co-authored-by: Ifeanyi Ubah --- tests/sqlparser_clickhouse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs index 89c01e1f5..5845cdb63 100644 --- a/tests/sqlparser_clickhouse.rs +++ b/tests/sqlparser_clickhouse.rs @@ -562,7 +562,7 @@ fn parse_select_star_except_no_parens() { } #[test] -fn test_create_matireal_view_test() { +fn parse_create_materialized_view() { // example sql // https://clickhouse.com/docs/en/guides/developer/cascading-materialized-views let sql = r#"CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv TO analytics.monthly_aggregated_data AS SELECT toDate(toStartOfMonth(event_time)) AS month, domain_name, sumState(count_views) AS sumCountViews FROM analytics.hourly_data GROUP BY domain_name, month"#; From 3191129f9683f1b04c65a53b37ef54e6871b6066 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Sun, 16 Jun 2024 23:41:39 +0800 Subject: [PATCH 11/16] Update src/parser/mod.rs Co-authored-by: Ifeanyi Ubah --- src/parser/mod.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 544a95afc..d885266b9 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -4157,17 +4157,9 @@ impl<'a> Parser<'a> { }; } - let mut to = Option::None; - if dialect_of!(self is ClickHouseDialect) { - if let Token::Word(word) = self.peek_token().token { - if word.keyword == Keyword::TO { - let _ = self.parse_keyword(Keyword::TO); - let indet = self.parse_object_name(false); - if indet.is_ok(){ - to = Some(indet.unwrap()); - } - } - }; + let to = if dialect_of!(self is ClickHouseDialect | GenericDialect) && self.parse_keyword(Keyword::TO) { + Some(self.parse_object_name(false)?) + } else { None }; } let comment = if dialect_of!(self is SnowflakeDialect | GenericDialect) From f9f576569dee6e68e4de0a9a00094c82e2a99bcb Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Sun, 16 Jun 2024 23:41:47 +0800 Subject: [PATCH 12/16] Update tests/sqlparser_clickhouse.rs Co-authored-by: Ifeanyi Ubah --- tests/sqlparser_clickhouse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs index 5845cdb63..89587cae0 100644 --- a/tests/sqlparser_clickhouse.rs +++ b/tests/sqlparser_clickhouse.rs @@ -566,7 +566,7 @@ fn parse_create_materialized_view() { // example sql // https://clickhouse.com/docs/en/guides/developer/cascading-materialized-views let sql = r#"CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv TO analytics.monthly_aggregated_data AS SELECT toDate(toStartOfMonth(event_time)) AS month, domain_name, sumState(count_views) AS sumCountViews FROM analytics.hourly_data GROUP BY domain_name, month"#; - clickhouse().verified_stmt(sql); + clickhouse_and_generic().verified_stmt(sql); } fn clickhouse() -> TestedDialects { From 5825517c6ec731f5f698afea3382458e829492a6 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Mon, 17 Jun 2024 00:12:11 +0800 Subject: [PATCH 13/16] cargo fmt and split sql into multiline. --- src/ast/mod.rs | 5 ++++- src/parser/mod.rs | 13 ++++++++----- tests/sqlparser_clickhouse.rs | 9 ++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 588866c6c..9c68e1dfe 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -3340,7 +3340,10 @@ impl fmt::Display for Statement { name = name, temporary = if *temporary { "TEMPORARY " } else { "" }, if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }, - to = if to.as_ref().map(|to| format!(" TO {to}")).unwrap_or_default() + to = to + .as_ref() + .map(|to| format!(" TO {to}")) + .unwrap_or_default() )?; if let Some(comment) = comment { write!( diff --git a/src/parser/mod.rs b/src/parser/mod.rs index d885266b9..b765b26f6 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -4156,11 +4156,14 @@ impl<'a> Parser<'a> { } }; } - - let to = if dialect_of!(self is ClickHouseDialect | GenericDialect) && self.parse_keyword(Keyword::TO) { - Some(self.parse_object_name(false)?) - } else { None }; - } + + let to = if dialect_of!(self is ClickHouseDialect | GenericDialect) + && self.parse_keyword(Keyword::TO) + { + Some(self.parse_object_name(false)?) + } else { + None + }; let comment = if dialect_of!(self is SnowflakeDialect | GenericDialect) && self.parse_keyword(Keyword::COMMENT) diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs index 89587cae0..5cd483242 100644 --- a/tests/sqlparser_clickhouse.rs +++ b/tests/sqlparser_clickhouse.rs @@ -565,7 +565,14 @@ fn parse_select_star_except_no_parens() { fn parse_create_materialized_view() { // example sql // https://clickhouse.com/docs/en/guides/developer/cascading-materialized-views - let sql = r#"CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv TO analytics.monthly_aggregated_data AS SELECT toDate(toStartOfMonth(event_time)) AS month, domain_name, sumState(count_views) AS sumCountViews FROM analytics.hourly_data GROUP BY domain_name, month"#; + let sql = concat!( + "CREATE MATERIALIZED VIEW analytics.monthly_aggregated_data_mv ", + "TO analytics.monthly_aggregated_data ", + "AS SELECT toDate(toStartOfMonth(event_time)) ", + "AS month, domain_name, sumState(count_views) ", + "AS sumCountViews FROM analytics.hourly_data ", + "GROUP BY domain_name, month" + ); clickhouse_and_generic().verified_stmt(sql); } From 8071262ec244e9d3ac44b76896b42627011afeb4 Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Mon, 17 Jun 2024 21:23:03 +0800 Subject: [PATCH 14/16] change test to setup to --- tests/sqlparser_common.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index ca94b8ced..4966ddd7e 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -6270,7 +6270,7 @@ fn parse_create_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, - .. + to } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6283,6 +6283,7 @@ fn parse_create_view() { assert!(!late_binding); assert!(!if_not_exists); assert!(!temporary); + assert!(to.is_none()) } _ => unreachable!(), } @@ -6327,7 +6328,7 @@ fn parse_create_view_with_columns() { with_no_schema_binding: late_binding, if_not_exists, temporary, - .. + to, } => { assert_eq!("v", name.to_string()); assert_eq!( @@ -6350,6 +6351,7 @@ fn parse_create_view_with_columns() { assert!(!late_binding); assert!(!if_not_exists); assert!(!temporary); + assert!(to.is_none()) } _ => unreachable!(), } @@ -6371,7 +6373,7 @@ fn parse_create_view_temporary() { with_no_schema_binding: late_binding, if_not_exists, temporary, - .. + to } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6384,6 +6386,7 @@ fn parse_create_view_temporary() { assert!(!late_binding); assert!(!if_not_exists); assert!(temporary); + assert!(to.is_none()) } _ => unreachable!(), } @@ -6405,7 +6408,7 @@ fn parse_create_or_replace_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, - .. + to, } => { assert_eq!("v", name.to_string()); assert_eq!(columns, vec![]); @@ -6418,6 +6421,7 @@ fn parse_create_or_replace_view() { assert!(!late_binding); assert!(!if_not_exists); assert!(!temporary); + assert!(to.is_none()) } _ => unreachable!(), } @@ -6443,7 +6447,7 @@ fn parse_create_or_replace_materialized_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, - .. + to, } => { assert_eq!("v", name.to_string()); assert_eq!(columns, vec![]); @@ -6456,6 +6460,7 @@ fn parse_create_or_replace_materialized_view() { assert!(!late_binding); assert!(!if_not_exists); assert!(!temporary); + assert!(to.is_none()) } _ => unreachable!(), } @@ -6477,7 +6482,7 @@ fn parse_create_materialized_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, - .. + to, } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6490,6 +6495,7 @@ fn parse_create_materialized_view() { assert!(!late_binding); assert!(!if_not_exists); assert!(!temporary); + assert!(to.is_none()) } _ => unreachable!(), } @@ -6511,7 +6517,7 @@ fn parse_create_materialized_view_with_cluster_by() { with_no_schema_binding: late_binding, if_not_exists, temporary, - .. + to, } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6524,6 +6530,7 @@ fn parse_create_materialized_view_with_cluster_by() { assert!(!late_binding); assert!(!if_not_exists); assert!(!temporary); + assert!(to.is_none()) } _ => unreachable!(), } From ad1d3845ac6a34695a6dfb67826db8eb2140c0ca Mon Sep 17 00:00:00 2001 From: Bidaya0 Date: Thu, 20 Jun 2024 23:17:22 +0800 Subject: [PATCH 15/16] add some docs --- src/ast/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 9c68e1dfe..ab513da72 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -2029,6 +2029,8 @@ pub enum Statement { if_not_exists: bool, /// if true, has SQLite `TEMP` or `TEMPORARY` clause temporary: bool, + /// if not None, has Clickhouse `TO` clause, specify the table into which to insert results + /// to: Option, }, /// ```sql From c37dd326e920890cb460303e01ec4af71fb4e08e Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Sun, 23 Jun 2024 07:07:11 -0400 Subject: [PATCH 16/16] cargo fmt --- tests/sqlparser_common.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 4966ddd7e..3679adf4f 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -6270,7 +6270,7 @@ fn parse_create_view() { with_no_schema_binding: late_binding, if_not_exists, temporary, - to + to, } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns); @@ -6373,7 +6373,7 @@ fn parse_create_view_temporary() { with_no_schema_binding: late_binding, if_not_exists, temporary, - to + to, } => { assert_eq!("myschema.myview", name.to_string()); assert_eq!(Vec::::new(), columns);