mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
feat: pr feedback
This commit is contained in:
parent
0fc29b2e16
commit
4c52327704
7 changed files with 32 additions and 23 deletions
|
@ -1453,10 +1453,13 @@ impl fmt::Display for ViewColumnDef {
|
|||
write!(f, " {}", data_type)?;
|
||||
}
|
||||
if let Some(options) = self.options.as_ref() {
|
||||
if matches!(options, ColumnOptions::CommaSeparated(_)) {
|
||||
write!(f, " {}", display_comma_separated(options.as_slice()))?;
|
||||
} else {
|
||||
write!(f, " {}", display_separated(options.as_slice(), " "))?
|
||||
match options {
|
||||
ColumnOptions::CommaSeparated(column_options) => {
|
||||
write!(f, " {}", display_comma_separated(column_options.as_slice()))?;
|
||||
}
|
||||
ColumnOptions::SpaceSeparated(column_options) => {
|
||||
write!(f, " {}", display_separated(column_options.as_slice(), " "))?
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
use crate::ast::query::SelectItemQualifiedWildcardKind;
|
||||
use crate::ast::{query::SelectItemQualifiedWildcardKind, ColumnOptions};
|
||||
use core::iter;
|
||||
|
||||
use crate::tokenizer::Span;
|
||||
|
@ -991,13 +991,13 @@ impl Spanned for ViewColumnDef {
|
|||
options,
|
||||
} = self;
|
||||
|
||||
union_spans(
|
||||
core::iter::once(name.span).chain(
|
||||
options
|
||||
.iter()
|
||||
.flat_map(|i| i.as_slice().iter().map(|k| k.span())),
|
||||
),
|
||||
)
|
||||
name.span.union_opt(&options.as_ref().map(|o| o.span()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Spanned for ColumnOptions {
|
||||
fn span(&self) -> Span {
|
||||
union_spans(self.as_slice().iter().map(|i| i.span()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1028,6 +1028,10 @@ pub trait Dialect: Debug + Any {
|
|||
fn supports_set_names(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn supports_space_separated_column_options(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// This represents the operators for which precedence must be defined
|
||||
|
|
|
@ -356,6 +356,10 @@ impl Dialect for SnowflakeDialect {
|
|||
fn get_reserved_keywords_for_select_item_operator(&self) -> &[Keyword] {
|
||||
&RESERVED_KEYWORDS_FOR_SELECT_ITEM_OPERATOR
|
||||
}
|
||||
|
||||
fn supports_space_separated_column_options(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_file_staging_command(kw: Keyword, parser: &mut Parser) -> Result<Statement, ParserError> {
|
||||
|
|
|
@ -22,7 +22,6 @@ use alloc::{
|
|||
};
|
||||
use core::{
|
||||
fmt::{self, Display},
|
||||
ops::Not,
|
||||
str::FromStr,
|
||||
};
|
||||
use helpers::attached_token::AttachedToken;
|
||||
|
@ -10603,14 +10602,13 @@ impl<'a> Parser<'a> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
Ok(options
|
||||
.is_empty()
|
||||
.not()
|
||||
.then_some(if dialect_of!(self is SnowflakeDialect) {
|
||||
ColumnOptions::SpaceSeparated(options)
|
||||
} else {
|
||||
ColumnOptions::CommaSeparated(options)
|
||||
}))
|
||||
if options.is_empty() {
|
||||
Ok(None)
|
||||
} else if self.dialect.supports_space_separated_column_options() {
|
||||
Ok(Some(ColumnOptions::SpaceSeparated(options)))
|
||||
} else {
|
||||
Ok(Some(ColumnOptions::CommaSeparated(options)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a parenthesized comma-separated list of unqualified, possibly quoted identifiers.
|
||||
|
|
|
@ -7964,7 +7964,7 @@ fn parse_create_view_with_columns() {
|
|||
let sql = "CREATE VIEW v (has, cols) AS SELECT 1, 2";
|
||||
// TODO: why does this fail for ClickHouseDialect? (#1449)
|
||||
// match all_dialects().verified_stmt(sql) {
|
||||
match all_dialects_where(|d| !d.is::<ClickHouseDialect>()).verified_stmt(sql) {
|
||||
match all_dialects_except(|d| d.is::<ClickHouseDialect>()).verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
|
|
|
@ -4169,7 +4169,7 @@ fn test_snowflake_fetch_clause_syntax() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_snowflake_create_view_with_tag() {
|
||||
fn test_snowflake_create_view_with_multiple_column_options() {
|
||||
let create_view_with_tag =
|
||||
r#"CREATE VIEW X (COL WITH TAG (pii='email') COMMENT 'foobar') AS SELECT * FROM Y"#;
|
||||
snowflake().verified_stmt(create_view_with_tag);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue