Skip to content

Commit 992a7e9

Browse files
committed
Fix clippy
1 parent 22ecf59 commit 992a7e9

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

src/ast/ddl.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use sqlparser_derive::{Visit, VisitMut};
3131
use crate::ast::value::escape_single_quote_string;
3232
use crate::ast::{
3333
display_comma_separated, display_separated, ArgMode, CatalogSyncNamespaceMode, CommentDef,
34-
CreateFunctionBody, CreateFunctionUsing, DataType, Expr, FunctionBehavior,
34+
ContactEntry, CreateFunctionBody, CreateFunctionUsing, DataType, Expr, FunctionBehavior,
3535
FunctionCalledOnNull, FunctionDeterminismSpecifier, FunctionParallel, Ident, IndexColumn,
3636
MySQLColumnPosition, ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect,
3737
SequenceOptions, SqlOption, StorageSerializationPolicy, Tag, Value, ValueWithSpan,
@@ -2546,7 +2546,7 @@ pub struct CreateSnowflakeDatabase {
25462546
pub catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
25472547
pub catalog_sync_namespace_flatten_delimiter: Option<String>,
25482548
pub with_tags: Option<Vec<Tag>>,
2549-
pub with_contacts: Option<Vec<(String, String)>>,
2549+
pub with_contacts: Option<Vec<ContactEntry>>,
25502550
}
25512551

25522552
impl fmt::Display for CreateSnowflakeDatabase {
@@ -2619,16 +2619,7 @@ impl fmt::Display for CreateSnowflakeDatabase {
26192619
}
26202620

26212621
if let Some(contacts) = &self.with_contacts {
2622-
write!(
2623-
f,
2624-
" WITH CONTACT ({})",
2625-
display_comma_separated(
2626-
&contacts
2627-
.iter()
2628-
.map(|(purpose, contact)| format!("{purpose} = {contact}"))
2629-
.collect::<Vec<_>>()
2630-
)
2631-
)?;
2622+
write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
26322623
}
26332624

26342625
Ok(())

src/ast/helpers/stmt_create_database.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use sqlparser_derive::{Visit, VisitMut};
2626

2727
use crate::ast::ddl::CreateSnowflakeDatabase;
2828
use crate::ast::{
29-
CatalogSyncNamespaceMode, ObjectName, Statement, StorageSerializationPolicy, Tag,
29+
CatalogSyncNamespaceMode, ContactEntry, ObjectName, Statement, StorageSerializationPolicy, Tag,
3030
};
3131
use crate::parser::ParserError;
3232

@@ -51,7 +51,6 @@ use crate::parser::ParserError;
5151
/// )
5252
/// ```
5353
///
54-
/// [1]: crate::ast::Statement::CreateSnowflakeDatabase
5554
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5655
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5756
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -73,7 +72,7 @@ pub struct CreateDatabaseBuilder {
7372
pub catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
7473
pub catalog_sync_namespace_flatten_delimiter: Option<String>,
7574
pub with_tags: Option<Vec<Tag>>,
76-
pub with_contacts: Option<Vec<(String, String)>>,
75+
pub with_contacts: Option<Vec<ContactEntry>>,
7776
}
7877

7978
impl CreateDatabaseBuilder {
@@ -192,7 +191,7 @@ impl CreateDatabaseBuilder {
192191
self
193192
}
194193

195-
pub fn with_contacts(mut self, with_contacts: Option<Vec<(String, String)>>) -> Self {
194+
pub fn with_contacts(mut self, with_contacts: Option<Vec<ContactEntry>>) -> Self {
196195
self.with_contacts = with_contacts;
197196
self
198197
}
@@ -275,7 +274,6 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
275274
#[cfg(test)]
276275
mod tests {
277276
use crate::ast::helpers::stmt_create_database::CreateDatabaseBuilder;
278-
use crate::ast::helpers::stmt_create_table::CreateTableBuilder;
279277
use crate::ast::{Ident, ObjectName, Statement};
280278
use crate::parser::ParserError;
281279

src/ast/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9550,6 +9550,29 @@ impl Display for Tag {
95509550
}
95519551
}
95529552

9553+
/// Snowflake `WITH CONTACT ( purpose = contact [ , purpose = contact ...] )`
9554+
///
9555+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-database>
9556+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9557+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9558+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9559+
pub struct ContactEntry {
9560+
pub purpose: String,
9561+
pub contact: String,
9562+
}
9563+
9564+
impl ContactEntry {
9565+
pub fn new(purpose: String, contact: String) -> Self {
9566+
Self { purpose, contact }
9567+
}
9568+
}
9569+
9570+
impl Display for ContactEntry {
9571+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9572+
write!(f, "{} = {}", self.purpose, self.contact)
9573+
}
9574+
}
9575+
95539576
/// Helper to indicate if a comment includes the `=` in the display form
95549577
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
95559578
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

src/dialect/snowflake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::ast::helpers::stmt_data_loading::{
2424
FileStagingCommand, StageLoadSelectItem, StageLoadSelectItemKind, StageParamsObject,
2525
};
2626
use crate::ast::{
27-
CatalogSyncNamespaceMode, ColumnOption, ColumnPolicy, ColumnPolicyProperty,
27+
CatalogSyncNamespaceMode, ColumnOption, ColumnPolicy, ColumnPolicyProperty, ContactEntry,
2828
CopyIntoSnowflakeKind, Ident, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
2929
IdentityPropertyKind, IdentityPropertyOrder, ObjectName, ObjectNamePart, RowAccessPolicy,
3030
ShowObjects, SqlOption, Statement, StorageSerializationPolicy, TagsColumnOption,
@@ -826,7 +826,7 @@ pub fn parse_create_database(
826826
let purpose = p.parse_identifier()?.value;
827827
p.expect_token(&Token::Eq)?;
828828
let contact = p.parse_identifier()?.value;
829-
Ok((purpose, contact))
829+
Ok(ContactEntry::new(purpose, contact))
830830
})?;
831831
parser.expect_token(&Token::RParen)?;
832832
builder = builder.with_contacts(Some(contacts));

tests/sqlparser_snowflake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,9 +4374,9 @@ fn test_snowflake_identifier_function() {
43744374

43754375
// Using IDENTIFIER to reference a database
43764376
match snowflake().verified_stmt("CREATE DATABASE IDENTIFIER('tbl')") {
4377-
Statement::CreateDatabase { db_name, .. } => {
4377+
Statement::CreateSnowflakeDatabase(CreateSnowflakeDatabase { name, .. }) => {
43784378
assert_eq!(
4379-
db_name,
4379+
name,
43804380
ObjectName(vec![ObjectNamePart::Function(ObjectNamePartFunction {
43814381
name: Ident::new("IDENTIFIER"),
43824382
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(

0 commit comments

Comments
 (0)