Skip to content

Commit 4c52327

Browse files
committed
feat: pr feedback
1 parent 0fc29b2 commit 4c52327

7 files changed

Lines changed: 32 additions & 23 deletions

File tree

src/ast/ddl.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,10 +1453,13 @@ impl fmt::Display for ViewColumnDef {
14531453
write!(f, " {}", data_type)?;
14541454
}
14551455
if let Some(options) = self.options.as_ref() {
1456-
if matches!(options, ColumnOptions::CommaSeparated(_)) {
1457-
write!(f, " {}", display_comma_separated(options.as_slice()))?;
1458-
} else {
1459-
write!(f, " {}", display_separated(options.as_slice(), " "))?
1456+
match options {
1457+
ColumnOptions::CommaSeparated(column_options) => {
1458+
write!(f, " {}", display_comma_separated(column_options.as_slice()))?;
1459+
}
1460+
ColumnOptions::SpaceSeparated(column_options) => {
1461+
write!(f, " {}", display_separated(column_options.as_slice(), " "))?
1462+
}
14601463
}
14611464
}
14621465
Ok(())

src/ast/spans.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::ast::query::SelectItemQualifiedWildcardKind;
18+
use crate::ast::{query::SelectItemQualifiedWildcardKind, ColumnOptions};
1919
use core::iter;
2020

2121
use crate::tokenizer::Span;
@@ -991,13 +991,13 @@ impl Spanned for ViewColumnDef {
991991
options,
992992
} = self;
993993

994-
union_spans(
995-
core::iter::once(name.span).chain(
996-
options
997-
.iter()
998-
.flat_map(|i| i.as_slice().iter().map(|k| k.span())),
999-
),
1000-
)
994+
name.span.union_opt(&options.as_ref().map(|o| o.span()))
995+
}
996+
}
997+
998+
impl Spanned for ColumnOptions {
999+
fn span(&self) -> Span {
1000+
union_spans(self.as_slice().iter().map(|i| i.span()))
10011001
}
10021002
}
10031003

src/dialect/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,10 @@ pub trait Dialect: Debug + Any {
10281028
fn supports_set_names(&self) -> bool {
10291029
false
10301030
}
1031+
1032+
fn supports_space_separated_column_options(&self) -> bool {
1033+
false
1034+
}
10311035
}
10321036

10331037
/// This represents the operators for which precedence must be defined

src/dialect/snowflake.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ impl Dialect for SnowflakeDialect {
356356
fn get_reserved_keywords_for_select_item_operator(&self) -> &[Keyword] {
357357
&RESERVED_KEYWORDS_FOR_SELECT_ITEM_OPERATOR
358358
}
359+
360+
fn supports_space_separated_column_options(&self) -> bool {
361+
true
362+
}
359363
}
360364

361365
fn parse_file_staging_command(kw: Keyword, parser: &mut Parser) -> Result<Statement, ParserError> {

src/parser/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use alloc::{
2222
};
2323
use core::{
2424
fmt::{self, Display},
25-
ops::Not,
2625
str::FromStr,
2726
};
2827
use helpers::attached_token::AttachedToken;
@@ -10603,14 +10602,13 @@ impl<'a> Parser<'a> {
1060310602
break;
1060410603
}
1060510604
}
10606-
Ok(options
10607-
.is_empty()
10608-
.not()
10609-
.then_some(if dialect_of!(self is SnowflakeDialect) {
10610-
ColumnOptions::SpaceSeparated(options)
10611-
} else {
10612-
ColumnOptions::CommaSeparated(options)
10613-
}))
10605+
if options.is_empty() {
10606+
Ok(None)
10607+
} else if self.dialect.supports_space_separated_column_options() {
10608+
Ok(Some(ColumnOptions::SpaceSeparated(options)))
10609+
} else {
10610+
Ok(Some(ColumnOptions::CommaSeparated(options)))
10611+
}
1061410612
}
1061510613

1061610614
/// Parses a parenthesized comma-separated list of unqualified, possibly quoted identifiers.

tests/sqlparser_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7964,7 +7964,7 @@ fn parse_create_view_with_columns() {
79647964
let sql = "CREATE VIEW v (has, cols) AS SELECT 1, 2";
79657965
// TODO: why does this fail for ClickHouseDialect? (#1449)
79667966
// match all_dialects().verified_stmt(sql) {
7967-
match all_dialects_where(|d| !d.is::<ClickHouseDialect>()).verified_stmt(sql) {
7967+
match all_dialects_except(|d| d.is::<ClickHouseDialect>()).verified_stmt(sql) {
79687968
Statement::CreateView {
79697969
or_alter,
79707970
name,

tests/sqlparser_snowflake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4169,7 +4169,7 @@ fn test_snowflake_fetch_clause_syntax() {
41694169
}
41704170

41714171
#[test]
4172-
fn test_snowflake_create_view_with_tag() {
4172+
fn test_snowflake_create_view_with_multiple_column_options() {
41734173
let create_view_with_tag =
41744174
r#"CREATE VIEW X (COL WITH TAG (pii='email') COMMENT 'foobar') AS SELECT * FROM Y"#;
41754175
snowflake().verified_stmt(create_view_with_tag);

0 commit comments

Comments
 (0)