mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-12 15:02:07 +00:00
CreateIndex: Move Display fmt to struct (#1307)
This commit is contained in:
parent
be77ce50ca
commit
deac269710
2 changed files with 44 additions and 42 deletions
|
@ -47,6 +47,49 @@ pub struct CreateIndex {
|
||||||
pub nulls_distinct: Option<bool>,
|
pub nulls_distinct: Option<bool>,
|
||||||
pub predicate: Option<Expr>,
|
pub predicate: Option<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for CreateIndex {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"CREATE {unique}INDEX {concurrently}{if_not_exists}",
|
||||||
|
unique = if self.unique { "UNIQUE " } else { "" },
|
||||||
|
concurrently = if self.concurrently {
|
||||||
|
"CONCURRENTLY "
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
if_not_exists = if self.if_not_exists {
|
||||||
|
"IF NOT EXISTS "
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
if let Some(value) = &self.name {
|
||||||
|
write!(f, "{value} ")?;
|
||||||
|
}
|
||||||
|
write!(f, "ON {}", self.table_name)?;
|
||||||
|
if let Some(value) = &self.using {
|
||||||
|
write!(f, " USING {value} ")?;
|
||||||
|
}
|
||||||
|
write!(f, "({})", display_separated(&self.columns, ","))?;
|
||||||
|
if !self.include.is_empty() {
|
||||||
|
write!(f, " INCLUDE ({})", display_separated(&self.include, ","))?;
|
||||||
|
}
|
||||||
|
if let Some(value) = self.nulls_distinct {
|
||||||
|
if value {
|
||||||
|
write!(f, " NULLS DISTINCT")?;
|
||||||
|
} else {
|
||||||
|
write!(f, " NULLS NOT DISTINCT")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(predicate) = &self.predicate {
|
||||||
|
write!(f, " WHERE {predicate}")?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// CREATE TABLE statement.
|
/// CREATE TABLE statement.
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
|
|
|
@ -3383,48 +3383,7 @@ impl fmt::Display for Statement {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(create_index) => create_index.fmt(f),
|
||||||
name,
|
|
||||||
table_name,
|
|
||||||
using,
|
|
||||||
columns,
|
|
||||||
unique,
|
|
||||||
concurrently,
|
|
||||||
if_not_exists,
|
|
||||||
include,
|
|
||||||
nulls_distinct,
|
|
||||||
predicate,
|
|
||||||
}) => {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"CREATE {unique}INDEX {concurrently}{if_not_exists}",
|
|
||||||
unique = if *unique { "UNIQUE " } else { "" },
|
|
||||||
concurrently = if *concurrently { "CONCURRENTLY " } else { "" },
|
|
||||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
|
||||||
)?;
|
|
||||||
if let Some(value) = name {
|
|
||||||
write!(f, "{value} ")?;
|
|
||||||
}
|
|
||||||
write!(f, "ON {table_name}")?;
|
|
||||||
if let Some(value) = using {
|
|
||||||
write!(f, " USING {value} ")?;
|
|
||||||
}
|
|
||||||
write!(f, "({})", display_separated(columns, ","))?;
|
|
||||||
if !include.is_empty() {
|
|
||||||
write!(f, " INCLUDE ({})", display_separated(include, ","))?;
|
|
||||||
}
|
|
||||||
if let Some(value) = nulls_distinct {
|
|
||||||
if *value {
|
|
||||||
write!(f, " NULLS DISTINCT")?;
|
|
||||||
} else {
|
|
||||||
write!(f, " NULLS NOT DISTINCT")?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(predicate) = predicate {
|
|
||||||
write!(f, " WHERE {predicate}")?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Statement::CreateExtension {
|
Statement::CreateExtension {
|
||||||
name,
|
name,
|
||||||
if_not_exists,
|
if_not_exists,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue