Skip to content

Commit 1c35f13

Browse files
committed
Fix cargo clippy
1 parent b70864f commit 1c35f13

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

src/ast/ddl.rs

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

3131
use crate::ast::value::escape_single_quote_string;
3232
use crate::ast::{
33-
display_comma_separated, display_separated, CatalogSyncNamespaceMode, CommentDef,
33+
display_comma_separated, display_separated, CatalogSyncNamespaceMode, CommentDef, ContactEntry,
3434
CreateFunctionBody, CreateFunctionUsing, DataType, Expr, FunctionBehavior,
3535
FunctionCalledOnNull, FunctionDeterminismSpecifier, FunctionParallel, Ident,
3636
MySQLColumnPosition, ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect,
@@ -2294,7 +2294,7 @@ pub struct CreateSnowflakeDatabase {
22942294
pub catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
22952295
pub catalog_sync_namespace_flatten_delimiter: Option<String>,
22962296
pub with_tags: Option<Vec<Tag>>,
2297-
pub with_contacts: Option<Vec<(String, String)>>,
2297+
pub with_contacts: Option<Vec<ContactEntry>>,
22982298
}
22992299

23002300
impl fmt::Display for CreateSnowflakeDatabase {
@@ -2367,16 +2367,7 @@ impl fmt::Display for CreateSnowflakeDatabase {
23672367
}
23682368

23692369
if let Some(contacts) = &self.with_contacts {
2370-
write!(
2371-
f,
2372-
" WITH CONTACT ({})",
2373-
display_comma_separated(
2374-
&contacts
2375-
.iter()
2376-
.map(|(purpose, contact)| format!("{purpose} = {contact}"))
2377-
.collect::<Vec<_>>()
2378-
)
2379-
)?;
2370+
write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
23802371
}
23812372

23822373
Ok(())

src/ast/helpers/stmt_create_database.rs

Lines changed: 3 additions & 3 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

@@ -73,7 +73,7 @@ pub struct CreateDatabaseBuilder {
7373
pub catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
7474
pub catalog_sync_namespace_flatten_delimiter: Option<String>,
7575
pub with_tags: Option<Vec<Tag>>,
76-
pub with_contacts: Option<Vec<(String, String)>>,
76+
pub with_contacts: Option<Vec<ContactEntry>>,
7777
}
7878

7979
impl CreateDatabaseBuilder {
@@ -192,7 +192,7 @@ impl CreateDatabaseBuilder {
192192
self
193193
}
194194

195-
pub fn with_contacts(mut self, with_contacts: Option<Vec<(String, String)>>) -> Self {
195+
pub fn with_contacts(mut self, with_contacts: Option<Vec<ContactEntry>>) -> Self {
196196
self.with_contacts = with_contacts;
197197
self
198198
}

src/ast/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8290,6 +8290,29 @@ impl Display for Tag {
82908290
}
82918291
}
82928292

8293+
/// Snowflake `WITH CONTACT ( purpose = contact [ , purpose = contact ...] )`
8294+
///
8295+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-database>
8296+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8297+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8298+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8299+
pub struct ContactEntry {
8300+
pub purpose: String,
8301+
pub contact: String,
8302+
}
8303+
8304+
impl ContactEntry {
8305+
pub fn new(purpose: String, contact: String) -> Self {
8306+
Self { purpose, contact }
8307+
}
8308+
}
8309+
8310+
impl Display for ContactEntry {
8311+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8312+
write!(f, "{} = {}", self.purpose, self.contact)
8313+
}
8314+
}
8315+
82938316
/// Helper to indicate if a comment includes the `=` in the display form
82948317
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
82958318
#[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, 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, RowAccessPolicy, ShowObjects,
3030
Statement, StorageSerializationPolicy, TagsColumnOption, WrappedCollection,
@@ -685,7 +685,7 @@ pub fn parse_create_database(
685685
let purpose = p.parse_identifier()?.value;
686686
p.expect_token(&Token::Eq)?;
687687
let contact = p.parse_identifier()?.value;
688-
Ok((purpose, contact))
688+
Ok(ContactEntry::new(purpose, contact))
689689
})?;
690690
parser.expect_token(&Token::RParen)?;
691691
builder = builder.with_contacts(Some(contacts));

0 commit comments

Comments
 (0)