mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
chore: fix clippy error in ci (#803)
* chore: fix clippy error in ci * chore: fix fmt
This commit is contained in:
parent
4955863bdf
commit
b31ede7733
16 changed files with 371 additions and 444 deletions
|
@ -46,7 +46,7 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname]
|
|||
"--hive" => Box::new(HiveDialect {}),
|
||||
"--redshift" => Box::new(RedshiftSqlDialect {}),
|
||||
"--generic" | "" => Box::new(GenericDialect {}),
|
||||
s => panic!("Unexpected parameter: {}", s),
|
||||
s => panic!("Unexpected parameter: {s}"),
|
||||
};
|
||||
|
||||
println!("Parsing from file '{}' using {:?}", &filename, dialect);
|
||||
|
@ -75,16 +75,16 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname]
|
|||
#[cfg(feature = "json_example")]
|
||||
{
|
||||
let serialized = serde_json::to_string_pretty(&statements).unwrap();
|
||||
println!("Serialized as JSON:\n{}", serialized);
|
||||
println!("Serialized as JSON:\n{serialized}");
|
||||
}
|
||||
} else {
|
||||
println!("Parse results:\n{:#?}", statements);
|
||||
println!("Parse results:\n{statements:#?}");
|
||||
}
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error during parsing: {:?}", e);
|
||||
println!("Error during parsing: {e:?}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,5 +25,5 @@ fn main() {
|
|||
|
||||
let ast = Parser::parse_sql(&dialect, sql).unwrap();
|
||||
|
||||
println!("AST: {:?}", ast);
|
||||
println!("AST: {ast:?}");
|
||||
}
|
||||
|
|
|
@ -186,13 +186,13 @@ impl fmt::Display for DataType {
|
|||
}
|
||||
DataType::Blob(size) => format_type_with_optional_length(f, "BLOB", size, false),
|
||||
DataType::Numeric(info) => {
|
||||
write!(f, "NUMERIC{}", info)
|
||||
write!(f, "NUMERIC{info}")
|
||||
}
|
||||
DataType::Decimal(info) => {
|
||||
write!(f, "DECIMAL{}", info)
|
||||
write!(f, "DECIMAL{info}")
|
||||
}
|
||||
DataType::Dec(info) => {
|
||||
write!(f, "DEC{}", info)
|
||||
write!(f, "DEC{info}")
|
||||
}
|
||||
DataType::Float(size) => format_type_with_optional_length(f, "FLOAT", size, false),
|
||||
DataType::TinyInt(zerofill) => {
|
||||
|
@ -250,14 +250,14 @@ impl fmt::Display for DataType {
|
|||
DataType::Bytea => write!(f, "BYTEA"),
|
||||
DataType::Array(ty) => {
|
||||
if let Some(t) = &ty {
|
||||
write!(f, "{}[]", t)
|
||||
write!(f, "{t}[]")
|
||||
} else {
|
||||
write!(f, "ARRAY")
|
||||
}
|
||||
}
|
||||
DataType::Custom(ty, modifiers) => {
|
||||
if modifiers.is_empty() {
|
||||
write!(f, "{}", ty)
|
||||
write!(f, "{ty}")
|
||||
} else {
|
||||
write!(f, "{}({})", ty, modifiers.join(", "))
|
||||
}
|
||||
|
@ -292,9 +292,9 @@ fn format_type_with_optional_length(
|
|||
len: &Option<u64>,
|
||||
unsigned: bool,
|
||||
) -> fmt::Result {
|
||||
write!(f, "{}", sql_type)?;
|
||||
write!(f, "{sql_type}")?;
|
||||
if let Some(len) = len {
|
||||
write!(f, "({})", len)?;
|
||||
write!(f, "({len})")?;
|
||||
}
|
||||
if unsigned {
|
||||
write!(f, " UNSIGNED")?;
|
||||
|
@ -307,9 +307,9 @@ fn format_character_string_type(
|
|||
sql_type: &str,
|
||||
size: &Option<CharacterLength>,
|
||||
) -> fmt::Result {
|
||||
write!(f, "{}", sql_type)?;
|
||||
write!(f, "{sql_type}")?;
|
||||
if let Some(size) = size {
|
||||
write!(f, "({})", size)?;
|
||||
write!(f, "({size})")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ fn format_datetime_precision_and_tz(
|
|||
len: &Option<u64>,
|
||||
time_zone: &TimezoneInfo,
|
||||
) -> fmt::Result {
|
||||
write!(f, "{}", sql_type)?;
|
||||
write!(f, "{sql_type}")?;
|
||||
let len_fmt = len.as_ref().map(|l| format!("({l})")).unwrap_or_default();
|
||||
|
||||
match time_zone {
|
||||
|
@ -432,7 +432,7 @@ impl fmt::Display for CharacterLength {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.length)?;
|
||||
if let Some(unit) = &self.unit {
|
||||
write!(f, " {}", unit)?;
|
||||
write!(f, " {unit}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ impl fmt::Display for AlterTableOperation {
|
|||
display_comma_separated(new_partitions),
|
||||
ine = if *if_not_exists { " IF NOT EXISTS" } else { "" }
|
||||
),
|
||||
AlterTableOperation::AddConstraint(c) => write!(f, "ADD {}", c),
|
||||
AlterTableOperation::AddConstraint(c) => write!(f, "ADD {c}"),
|
||||
AlterTableOperation::AddColumn {
|
||||
column_keyword,
|
||||
if_not_exists,
|
||||
|
@ -135,7 +135,7 @@ impl fmt::Display for AlterTableOperation {
|
|||
Ok(())
|
||||
}
|
||||
AlterTableOperation::AlterColumn { column_name, op } => {
|
||||
write!(f, "ALTER COLUMN {} {}", column_name, op)
|
||||
write!(f, "ALTER COLUMN {column_name} {op}")
|
||||
}
|
||||
AlterTableOperation::DropPartitions {
|
||||
partitions,
|
||||
|
@ -183,13 +183,9 @@ impl fmt::Display for AlterTableOperation {
|
|||
AlterTableOperation::RenameColumn {
|
||||
old_column_name,
|
||||
new_column_name,
|
||||
} => write!(
|
||||
f,
|
||||
"RENAME COLUMN {} TO {}",
|
||||
old_column_name, new_column_name
|
||||
),
|
||||
} => write!(f, "RENAME COLUMN {old_column_name} TO {new_column_name}"),
|
||||
AlterTableOperation::RenameTable { table_name } => {
|
||||
write!(f, "RENAME TO {}", table_name)
|
||||
write!(f, "RENAME TO {table_name}")
|
||||
}
|
||||
AlterTableOperation::ChangeColumn {
|
||||
old_name,
|
||||
|
@ -197,7 +193,7 @@ impl fmt::Display for AlterTableOperation {
|
|||
data_type,
|
||||
options,
|
||||
} => {
|
||||
write!(f, "CHANGE COLUMN {} {} {}", old_name, new_name, data_type)?;
|
||||
write!(f, "CHANGE COLUMN {old_name} {new_name} {data_type}")?;
|
||||
if options.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -205,7 +201,7 @@ impl fmt::Display for AlterTableOperation {
|
|||
}
|
||||
}
|
||||
AlterTableOperation::RenameConstraint { old_name, new_name } => {
|
||||
write!(f, "RENAME CONSTRAINT {} TO {}", old_name, new_name)
|
||||
write!(f, "RENAME CONSTRAINT {old_name} TO {new_name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +211,7 @@ impl fmt::Display for AlterIndexOperation {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
AlterIndexOperation::RenameIndex { index_name } => {
|
||||
write!(f, "RENAME TO {}", index_name)
|
||||
write!(f, "RENAME TO {index_name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -248,16 +244,16 @@ impl fmt::Display for AlterColumnOperation {
|
|||
AlterColumnOperation::SetNotNull => write!(f, "SET NOT NULL",),
|
||||
AlterColumnOperation::DropNotNull => write!(f, "DROP NOT NULL",),
|
||||
AlterColumnOperation::SetDefault { value } => {
|
||||
write!(f, "SET DEFAULT {}", value)
|
||||
write!(f, "SET DEFAULT {value}")
|
||||
}
|
||||
AlterColumnOperation::DropDefault {} => {
|
||||
write!(f, "DROP DEFAULT")
|
||||
}
|
||||
AlterColumnOperation::SetDataType { data_type, using } => {
|
||||
if let Some(expr) = using {
|
||||
write!(f, "SET DATA TYPE {} USING {}", data_type, expr)
|
||||
write!(f, "SET DATA TYPE {data_type} USING {expr}")
|
||||
} else {
|
||||
write!(f, "SET DATA TYPE {}", data_type)
|
||||
write!(f, "SET DATA TYPE {data_type}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -369,10 +365,10 @@ impl fmt::Display for TableConstraint {
|
|||
display_comma_separated(referred_columns),
|
||||
)?;
|
||||
if let Some(action) = on_delete {
|
||||
write!(f, " ON DELETE {}", action)?;
|
||||
write!(f, " ON DELETE {action}")?;
|
||||
}
|
||||
if let Some(action) = on_update {
|
||||
write!(f, " ON UPDATE {}", action)?;
|
||||
write!(f, " ON UPDATE {action}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -387,10 +383,10 @@ impl fmt::Display for TableConstraint {
|
|||
} => {
|
||||
write!(f, "{}", if *display_as_key { "KEY" } else { "INDEX" })?;
|
||||
if let Some(name) = name {
|
||||
write!(f, " {}", name)?;
|
||||
write!(f, " {name}")?;
|
||||
}
|
||||
if let Some(index_type) = index_type {
|
||||
write!(f, " USING {}", index_type)?;
|
||||
write!(f, " USING {index_type}")?;
|
||||
}
|
||||
write!(f, " ({})", display_comma_separated(columns))?;
|
||||
|
||||
|
@ -409,11 +405,11 @@ impl fmt::Display for TableConstraint {
|
|||
}
|
||||
|
||||
if !matches!(index_type_display, KeyOrIndexDisplay::None) {
|
||||
write!(f, " {}", index_type_display)?;
|
||||
write!(f, " {index_type_display}")?;
|
||||
}
|
||||
|
||||
if let Some(name) = opt_index_name {
|
||||
write!(f, " {}", name)?;
|
||||
write!(f, " {name}")?;
|
||||
}
|
||||
|
||||
write!(f, " ({})", display_comma_separated(columns))?;
|
||||
|
@ -500,7 +496,7 @@ impl fmt::Display for ColumnDef {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{} {}", self.name, self.data_type)?;
|
||||
for option in &self.options {
|
||||
write!(f, " {}", option)?;
|
||||
write!(f, " {option}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -580,7 +576,7 @@ impl fmt::Display for ColumnOption {
|
|||
match self {
|
||||
Null => write!(f, "NULL"),
|
||||
NotNull => write!(f, "NOT NULL"),
|
||||
Default(expr) => write!(f, "DEFAULT {}", expr),
|
||||
Default(expr) => write!(f, "DEFAULT {expr}"),
|
||||
Unique { is_primary } => {
|
||||
write!(f, "{}", if *is_primary { "PRIMARY KEY" } else { "UNIQUE" })
|
||||
}
|
||||
|
@ -590,23 +586,23 @@ impl fmt::Display for ColumnOption {
|
|||
on_delete,
|
||||
on_update,
|
||||
} => {
|
||||
write!(f, "REFERENCES {}", foreign_table)?;
|
||||
write!(f, "REFERENCES {foreign_table}")?;
|
||||
if !referred_columns.is_empty() {
|
||||
write!(f, " ({})", display_comma_separated(referred_columns))?;
|
||||
}
|
||||
if let Some(action) = on_delete {
|
||||
write!(f, " ON DELETE {}", action)?;
|
||||
write!(f, " ON DELETE {action}")?;
|
||||
}
|
||||
if let Some(action) = on_update {
|
||||
write!(f, " ON UPDATE {}", action)?;
|
||||
write!(f, " ON UPDATE {action}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Check(expr) => write!(f, "CHECK ({})", expr),
|
||||
Check(expr) => write!(f, "CHECK ({expr})"),
|
||||
DialectSpecific(val) => write!(f, "{}", display_separated(val, " ")),
|
||||
CharacterSet(n) => write!(f, "CHARACTER SET {}", n),
|
||||
CharacterSet(n) => write!(f, "CHARACTER SET {n}"),
|
||||
Comment(v) => write!(f, "COMMENT '{}'", escape_single_quote_string(v)),
|
||||
OnUpdate(expr) => write!(f, "ON UPDATE {}", expr),
|
||||
OnUpdate(expr) => write!(f, "ON UPDATE {expr}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -616,7 +612,7 @@ fn display_constraint_name(name: &'_ Option<Ident>) -> impl fmt::Display + '_ {
|
|||
impl<'a> fmt::Display for ConstraintName<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(name) = self.0 {
|
||||
write!(f, "CONSTRAINT {} ", name)?;
|
||||
write!(f, "CONSTRAINT {name} ")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
413
src/ast/mod.rs
413
src/ast/mod.rs
File diff suppressed because it is too large
Load diff
|
@ -46,20 +46,20 @@ pub struct Query {
|
|||
impl fmt::Display for Query {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(ref with) = self.with {
|
||||
write!(f, "{} ", with)?;
|
||||
write!(f, "{with} ")?;
|
||||
}
|
||||
write!(f, "{}", self.body)?;
|
||||
if !self.order_by.is_empty() {
|
||||
write!(f, " ORDER BY {}", display_comma_separated(&self.order_by))?;
|
||||
}
|
||||
if let Some(ref limit) = self.limit {
|
||||
write!(f, " LIMIT {}", limit)?;
|
||||
write!(f, " LIMIT {limit}")?;
|
||||
}
|
||||
if let Some(ref offset) = self.offset {
|
||||
write!(f, " {}", offset)?;
|
||||
write!(f, " {offset}")?;
|
||||
}
|
||||
if let Some(ref fetch) = self.fetch {
|
||||
write!(f, " {}", fetch)?;
|
||||
write!(f, " {fetch}")?;
|
||||
}
|
||||
if !self.locks.is_empty() {
|
||||
write!(f, " {}", display_separated(&self.locks, " "))?;
|
||||
|
@ -95,25 +95,23 @@ pub enum SetExpr {
|
|||
impl fmt::Display for SetExpr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SetExpr::Select(s) => write!(f, "{}", s),
|
||||
SetExpr::Query(q) => write!(f, "({})", q),
|
||||
SetExpr::Values(v) => write!(f, "{}", v),
|
||||
SetExpr::Insert(v) => write!(f, "{}", v),
|
||||
SetExpr::Table(t) => write!(f, "{}", t),
|
||||
SetExpr::Select(s) => write!(f, "{s}"),
|
||||
SetExpr::Query(q) => write!(f, "({q})"),
|
||||
SetExpr::Values(v) => write!(f, "{v}"),
|
||||
SetExpr::Insert(v) => write!(f, "{v}"),
|
||||
SetExpr::Table(t) => write!(f, "{t}"),
|
||||
SetExpr::SetOperation {
|
||||
left,
|
||||
right,
|
||||
op,
|
||||
set_quantifier,
|
||||
} => {
|
||||
write!(f, "{} {}", left, op)?;
|
||||
write!(f, "{left} {op}")?;
|
||||
match set_quantifier {
|
||||
SetQuantifier::All | SetQuantifier::Distinct => {
|
||||
write!(f, " {}", set_quantifier)?
|
||||
}
|
||||
SetQuantifier::None => write!(f, "{}", set_quantifier)?,
|
||||
SetQuantifier::All | SetQuantifier::Distinct => write!(f, " {set_quantifier}")?,
|
||||
SetQuantifier::None => write!(f, "{set_quantifier}")?,
|
||||
}
|
||||
write!(f, " {}", right)?;
|
||||
write!(f, " {right}")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -224,12 +222,12 @@ impl fmt::Display for Select {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "SELECT{}", if self.distinct { " DISTINCT" } else { "" })?;
|
||||
if let Some(ref top) = self.top {
|
||||
write!(f, " {}", top)?;
|
||||
write!(f, " {top}")?;
|
||||
}
|
||||
write!(f, " {}", display_comma_separated(&self.projection))?;
|
||||
|
||||
if let Some(ref into) = self.into {
|
||||
write!(f, " {}", into)?;
|
||||
write!(f, " {into}")?;
|
||||
}
|
||||
|
||||
if !self.from.is_empty() {
|
||||
|
@ -237,11 +235,11 @@ impl fmt::Display for Select {
|
|||
}
|
||||
if !self.lateral_views.is_empty() {
|
||||
for lv in &self.lateral_views {
|
||||
write!(f, "{}", lv)?;
|
||||
write!(f, "{lv}")?;
|
||||
}
|
||||
}
|
||||
if let Some(ref selection) = self.selection {
|
||||
write!(f, " WHERE {}", selection)?;
|
||||
write!(f, " WHERE {selection}")?;
|
||||
}
|
||||
if !self.group_by.is_empty() {
|
||||
write!(f, " GROUP BY {}", display_comma_separated(&self.group_by))?;
|
||||
|
@ -264,10 +262,10 @@ impl fmt::Display for Select {
|
|||
write!(f, " SORT BY {}", display_comma_separated(&self.sort_by))?;
|
||||
}
|
||||
if let Some(ref having) = self.having {
|
||||
write!(f, " HAVING {}", having)?;
|
||||
write!(f, " HAVING {having}")?;
|
||||
}
|
||||
if let Some(ref qualify) = self.qualify {
|
||||
write!(f, " QUALIFY {}", qualify)?;
|
||||
write!(f, " QUALIFY {qualify}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -344,7 +342,7 @@ impl fmt::Display for Cte {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{} AS ({})", self.alias, self.query)?;
|
||||
if let Some(ref fr) = self.from {
|
||||
write!(f, " FROM {}", fr)?;
|
||||
write!(f, " FROM {fr}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -531,10 +529,10 @@ impl fmt::Display for ExceptSelectItem {
|
|||
impl fmt::Display for SelectItem {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match &self {
|
||||
SelectItem::UnnamedExpr(expr) => write!(f, "{}", expr),
|
||||
SelectItem::ExprWithAlias { expr, alias } => write!(f, "{} AS {}", expr, alias),
|
||||
SelectItem::UnnamedExpr(expr) => write!(f, "{expr}"),
|
||||
SelectItem::ExprWithAlias { expr, alias } => write!(f, "{expr} AS {alias}"),
|
||||
SelectItem::QualifiedWildcard(prefix, additional_options) => {
|
||||
write!(f, "{}.*", prefix)?;
|
||||
write!(f, "{prefix}.*")?;
|
||||
write!(f, "{additional_options}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -559,7 +557,7 @@ impl fmt::Display for TableWithJoins {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.relation)?;
|
||||
for join in &self.joins {
|
||||
write!(f, "{}", join)?;
|
||||
write!(f, "{join}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -632,12 +630,12 @@ impl fmt::Display for TableFactor {
|
|||
args,
|
||||
with_hints,
|
||||
} => {
|
||||
write!(f, "{}", name)?;
|
||||
write!(f, "{name}")?;
|
||||
if let Some(args) = args {
|
||||
write!(f, "({})", display_comma_separated(args))?;
|
||||
}
|
||||
if let Some(alias) = alias {
|
||||
write!(f, " AS {}", alias)?;
|
||||
write!(f, " AS {alias}")?;
|
||||
}
|
||||
if !with_hints.is_empty() {
|
||||
write!(f, " WITH ({})", display_comma_separated(with_hints))?;
|
||||
|
@ -652,16 +650,16 @@ impl fmt::Display for TableFactor {
|
|||
if *lateral {
|
||||
write!(f, "LATERAL ")?;
|
||||
}
|
||||
write!(f, "({})", subquery)?;
|
||||
write!(f, "({subquery})")?;
|
||||
if let Some(alias) = alias {
|
||||
write!(f, " AS {}", alias)?;
|
||||
write!(f, " AS {alias}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
TableFactor::TableFunction { expr, alias } => {
|
||||
write!(f, "TABLE({})", expr)?;
|
||||
write!(f, "TABLE({expr})")?;
|
||||
if let Some(alias) = alias {
|
||||
write!(f, " AS {}", alias)?;
|
||||
write!(f, " AS {alias}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -671,15 +669,15 @@ impl fmt::Display for TableFactor {
|
|||
with_offset,
|
||||
with_offset_alias,
|
||||
} => {
|
||||
write!(f, "UNNEST({})", array_expr)?;
|
||||
write!(f, "UNNEST({array_expr})")?;
|
||||
if let Some(alias) = alias {
|
||||
write!(f, " AS {}", alias)?;
|
||||
write!(f, " AS {alias}")?;
|
||||
}
|
||||
if *with_offset {
|
||||
write!(f, " WITH OFFSET")?;
|
||||
}
|
||||
if let Some(alias) = with_offset_alias {
|
||||
write!(f, " AS {}", alias)?;
|
||||
write!(f, " AS {alias}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -687,9 +685,9 @@ impl fmt::Display for TableFactor {
|
|||
table_with_joins,
|
||||
alias,
|
||||
} => {
|
||||
write!(f, "({})", table_with_joins)?;
|
||||
write!(f, "({table_with_joins})")?;
|
||||
if let Some(alias) = alias {
|
||||
write!(f, " AS {}", alias)?;
|
||||
write!(f, " AS {alias}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -736,7 +734,7 @@ impl fmt::Display for Join {
|
|||
impl<'a> fmt::Display for Suffix<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {
|
||||
JoinConstraint::On(expr) => write!(f, " ON {}", expr),
|
||||
JoinConstraint::On(expr) => write!(f, " ON {expr}"),
|
||||
JoinConstraint::Using(attrs) => {
|
||||
write!(f, " USING({})", display_comma_separated(attrs))
|
||||
}
|
||||
|
@ -921,9 +919,9 @@ impl fmt::Display for Fetch {
|
|||
let extension = if self.with_ties { "WITH TIES" } else { "ONLY" };
|
||||
if let Some(ref quantity) = self.quantity {
|
||||
let percent = if self.percent { " PERCENT" } else { "" };
|
||||
write!(f, "FETCH FIRST {}{} ROWS {}", quantity, percent, extension)
|
||||
write!(f, "FETCH FIRST {quantity}{percent} ROWS {extension}")
|
||||
} else {
|
||||
write!(f, "FETCH FIRST ROWS {}", extension)
|
||||
write!(f, "FETCH FIRST ROWS {extension}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -941,10 +939,10 @@ impl fmt::Display for LockClause {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "FOR {}", &self.lock_type)?;
|
||||
if let Some(ref of) = self.of {
|
||||
write!(f, " OF {}", of)?;
|
||||
write!(f, " OF {of}")?;
|
||||
}
|
||||
if let Some(ref nb) = self.nonblock {
|
||||
write!(f, " {}", nb)?;
|
||||
write!(f, " {nb}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -964,7 +962,7 @@ impl fmt::Display for LockType {
|
|||
LockType::Share => "SHARE",
|
||||
LockType::Update => "UPDATE",
|
||||
};
|
||||
write!(f, "{}", select_lock)
|
||||
write!(f, "{select_lock}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -982,7 +980,7 @@ impl fmt::Display for NonBlock {
|
|||
NonBlock::Nowait => "NOWAIT",
|
||||
NonBlock::SkipLocked => "SKIP LOCKED",
|
||||
};
|
||||
write!(f, "{}", nonblock)
|
||||
write!(f, "{nonblock}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1001,9 +999,9 @@ impl fmt::Display for Top {
|
|||
let extension = if self.with_ties { " WITH TIES" } else { "" };
|
||||
if let Some(ref quantity) = self.quantity {
|
||||
let percent = if self.percent { " PERCENT" } else { "" };
|
||||
write!(f, "TOP ({}){}{}", quantity, percent, extension)
|
||||
write!(f, "TOP ({quantity}){percent}{extension}")
|
||||
} else {
|
||||
write!(f, "TOP{}", extension)
|
||||
write!(f, "TOP{extension}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1024,7 +1022,7 @@ impl fmt::Display for Values {
|
|||
let prefix = if self.explicit_row { "ROW" } else { "" };
|
||||
let mut delim = "";
|
||||
for row in &self.rows {
|
||||
write!(f, "{}", delim)?;
|
||||
write!(f, "{delim}")?;
|
||||
delim = ", ";
|
||||
write!(f, "{prefix}({})", display_comma_separated(row))?;
|
||||
}
|
||||
|
|
|
@ -61,16 +61,16 @@ impl fmt::Display for Value {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Value::Number(v, l) => write!(f, "{}{long}", v, long = if *l { "L" } else { "" }),
|
||||
Value::DoubleQuotedString(v) => write!(f, "\"{}\"", v),
|
||||
Value::DoubleQuotedString(v) => write!(f, "\"{v}\""),
|
||||
Value::SingleQuotedString(v) => write!(f, "'{}'", escape_single_quote_string(v)),
|
||||
Value::DollarQuotedString(v) => write!(f, "{}", v),
|
||||
Value::DollarQuotedString(v) => write!(f, "{v}"),
|
||||
Value::EscapedStringLiteral(v) => write!(f, "E'{}'", escape_escaped_string(v)),
|
||||
Value::NationalStringLiteral(v) => write!(f, "N'{}'", v),
|
||||
Value::HexStringLiteral(v) => write!(f, "X'{}'", v),
|
||||
Value::Boolean(v) => write!(f, "{}", v),
|
||||
Value::NationalStringLiteral(v) => write!(f, "N'{v}'"),
|
||||
Value::HexStringLiteral(v) => write!(f, "X'{v}'"),
|
||||
Value::Boolean(v) => write!(f, "{v}"),
|
||||
Value::Null => write!(f, "NULL"),
|
||||
Value::Placeholder(v) => write!(f, "{}", v),
|
||||
Value::UnQuotedString(v) => write!(f, "{}", v),
|
||||
Value::Placeholder(v) => write!(f, "{v}"),
|
||||
Value::UnQuotedString(v) => write!(f, "{v}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ impl<'a> fmt::Display for EscapeQuotedString<'a> {
|
|||
if c == self.quote {
|
||||
write!(f, "{q}{q}", q = self.quote)?;
|
||||
} else {
|
||||
write!(f, "{}", c)?;
|
||||
write!(f, "{c}")?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -215,7 +215,7 @@ impl<'a> fmt::Display for EscapeEscapedStringLiteral<'a> {
|
|||
write!(f, r#"\r"#)?;
|
||||
}
|
||||
_ => {
|
||||
write!(f, "{}", c)?;
|
||||
write!(f, "{c}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -600,32 +600,32 @@ mod tests {
|
|||
type Break = ();
|
||||
|
||||
fn pre_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow<Self::Break> {
|
||||
self.visited.push(format!("PRE: RELATION: {}", relation));
|
||||
self.visited.push(format!("PRE: RELATION: {relation}"));
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn post_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow<Self::Break> {
|
||||
self.visited.push(format!("POST: RELATION: {}", relation));
|
||||
self.visited.push(format!("POST: RELATION: {relation}"));
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn pre_visit_expr(&mut self, expr: &Expr) -> ControlFlow<Self::Break> {
|
||||
self.visited.push(format!("PRE: EXPR: {}", expr));
|
||||
self.visited.push(format!("PRE: EXPR: {expr}"));
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn post_visit_expr(&mut self, expr: &Expr) -> ControlFlow<Self::Break> {
|
||||
self.visited.push(format!("POST: EXPR: {}", expr));
|
||||
self.visited.push(format!("POST: EXPR: {expr}"));
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn pre_visit_statement(&mut self, statement: &Statement) -> ControlFlow<Self::Break> {
|
||||
self.visited.push(format!("PRE: STATEMENT: {}", statement));
|
||||
self.visited.push(format!("PRE: STATEMENT: {statement}"));
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn post_visit_statement(&mut self, statement: &Statement) -> ControlFlow<Self::Break> {
|
||||
self.visited.push(format!("POST: STATEMENT: {}", statement));
|
||||
self.visited.push(format!("POST: STATEMENT: {statement}"));
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -805,7 +805,7 @@ impl<'a> Parser<'a> {
|
|||
let tok = self.next_token();
|
||||
let key = match tok.token {
|
||||
Token::Word(word) => word.to_ident(),
|
||||
_ => return parser_err!(format!("Expected identifier, found: {}", tok)),
|
||||
_ => return parser_err!(format!("Expected identifier, found: {tok}")),
|
||||
};
|
||||
Ok(Expr::CompositeAccess {
|
||||
expr: Box::new(expr),
|
||||
|
@ -2083,7 +2083,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Report unexpected token
|
||||
pub fn expected<T>(&self, expected: &str, found: TokenWithLocation) -> Result<T, ParserError> {
|
||||
parser_err!(format!("Expected {}, found: {}", expected, found))
|
||||
parser_err!(format!("Expected {expected}, found: {found}"))
|
||||
}
|
||||
|
||||
/// Look for an expected keyword and consume it if it exists
|
||||
|
@ -2135,7 +2135,7 @@ impl<'a> Parser<'a> {
|
|||
if let Some(keyword) = self.parse_one_of_keywords(keywords) {
|
||||
Ok(keyword)
|
||||
} else {
|
||||
let keywords: Vec<String> = keywords.iter().map(|x| format!("{:?}", x)).collect();
|
||||
let keywords: Vec<String> = keywords.iter().map(|x| format!("{x:?}")).collect();
|
||||
self.expected(
|
||||
&format!("one of {}", keywords.join(" or ")),
|
||||
self.peek_token(),
|
||||
|
@ -2495,7 +2495,7 @@ impl<'a> Parser<'a> {
|
|||
Keyword::ARCHIVE => Ok(Some(CreateFunctionUsing::Archive(uri))),
|
||||
_ => self.expected(
|
||||
"JAR, FILE or ARCHIVE, got {:?}",
|
||||
TokenWithLocation::wrap(Token::make_keyword(format!("{:?}", keyword).as_str())),
|
||||
TokenWithLocation::wrap(Token::make_keyword(format!("{keyword:?}").as_str())),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
@ -4028,7 +4028,7 @@ impl<'a> Parser<'a> {
|
|||
fn parse_literal_char(&mut self) -> Result<char, ParserError> {
|
||||
let s = self.parse_literal_string()?;
|
||||
if s.len() != 1 {
|
||||
return parser_err!(format!("Expect a char, found {:?}", s));
|
||||
return parser_err!(format!("Expect a char, found {s:?}"));
|
||||
}
|
||||
Ok(s.chars().next().unwrap())
|
||||
}
|
||||
|
@ -4107,7 +4107,7 @@ impl<'a> Parser<'a> {
|
|||
// (i.e., it returns the input string).
|
||||
Token::Number(ref n, l) => match n.parse() {
|
||||
Ok(n) => Ok(Value::Number(n, l)),
|
||||
Err(e) => parser_err!(format!("Could not parse '{}' as number: {}", n, e)),
|
||||
Err(e) => parser_err!(format!("Could not parse '{n}' as number: {e}")),
|
||||
},
|
||||
Token::SingleQuotedString(ref s) => Ok(Value::SingleQuotedString(s.to_string())),
|
||||
Token::DoubleQuotedString(ref s) => Ok(Value::DoubleQuotedString(s.to_string())),
|
||||
|
@ -4147,7 +4147,7 @@ impl<'a> Parser<'a> {
|
|||
let next_token = self.next_token();
|
||||
match next_token.token {
|
||||
Token::Number(s, _) => s.parse::<u64>().map_err(|e| {
|
||||
ParserError::ParserError(format!("Could not parse '{}' as u64: {}", s, e))
|
||||
ParserError::ParserError(format!("Could not parse '{s}' as u64: {e}"))
|
||||
}),
|
||||
_ => self.expected("literal int", next_token),
|
||||
}
|
||||
|
@ -5267,8 +5267,7 @@ impl<'a> Parser<'a> {
|
|||
Keyword::EVENT => Ok(ShowCreateObject::Event),
|
||||
Keyword::VIEW => Ok(ShowCreateObject::View),
|
||||
keyword => Err(ParserError::ParserError(format!(
|
||||
"Unable to map keyword to ShowCreateObject: {:?}",
|
||||
keyword
|
||||
"Unable to map keyword to ShowCreateObject: {keyword:?}"
|
||||
))),
|
||||
}?;
|
||||
|
||||
|
@ -5437,8 +5436,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
_ => {
|
||||
return Err(ParserError::ParserError(format!(
|
||||
"expected OUTER, SEMI, ANTI or JOIN after {:?}",
|
||||
kw
|
||||
"expected OUTER, SEMI, ANTI or JOIN after {kw:?}"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
@ -5561,8 +5559,7 @@ impl<'a> Parser<'a> {
|
|||
// but not `FROM (mytable AS alias1) AS alias2`.
|
||||
if let Some(inner_alias) = alias {
|
||||
return Err(ParserError::ParserError(format!(
|
||||
"duplicate alias {}",
|
||||
inner_alias
|
||||
"duplicate alias {inner_alias}"
|
||||
)));
|
||||
}
|
||||
// Act as if the alias was specified normally next
|
||||
|
@ -5731,8 +5728,7 @@ impl<'a> Parser<'a> {
|
|||
if !err.is_empty() {
|
||||
let errors: Vec<Keyword> = err.into_iter().filter_map(|x| x.err()).collect();
|
||||
return Err(ParserError::ParserError(format!(
|
||||
"INTERNAL ERROR: GRANT/REVOKE unexpected keyword(s) - {:?}",
|
||||
errors
|
||||
"INTERNAL ERROR: GRANT/REVOKE unexpected keyword(s) - {errors:?}"
|
||||
)));
|
||||
}
|
||||
let act = actions.into_iter().filter_map(|x| x.ok()).collect();
|
||||
|
|
|
@ -49,8 +49,7 @@ impl TestedDialects {
|
|||
if let Some((prev_dialect, prev_parsed)) = s {
|
||||
assert_eq!(
|
||||
prev_parsed, parsed,
|
||||
"Parse results with {:?} are different from {:?}",
|
||||
prev_dialect, dialect
|
||||
"Parse results with {prev_dialect:?} are different from {dialect:?}"
|
||||
);
|
||||
}
|
||||
Some((dialect, parsed))
|
||||
|
|
|
@ -180,17 +180,17 @@ impl fmt::Display for Token {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Token::EOF => f.write_str("EOF"),
|
||||
Token::Word(ref w) => write!(f, "{}", w),
|
||||
Token::Word(ref w) => write!(f, "{w}"),
|
||||
Token::Number(ref n, l) => write!(f, "{}{long}", n, long = if *l { "L" } else { "" }),
|
||||
Token::Char(ref c) => write!(f, "{}", c),
|
||||
Token::SingleQuotedString(ref s) => write!(f, "'{}'", s),
|
||||
Token::DoubleQuotedString(ref s) => write!(f, "\"{}\"", s),
|
||||
Token::DollarQuotedString(ref s) => write!(f, "{}", s),
|
||||
Token::NationalStringLiteral(ref s) => write!(f, "N'{}'", s),
|
||||
Token::EscapedStringLiteral(ref s) => write!(f, "E'{}'", s),
|
||||
Token::HexStringLiteral(ref s) => write!(f, "X'{}'", s),
|
||||
Token::Char(ref c) => write!(f, "{c}"),
|
||||
Token::SingleQuotedString(ref s) => write!(f, "'{s}'"),
|
||||
Token::DoubleQuotedString(ref s) => write!(f, "\"{s}\""),
|
||||
Token::DollarQuotedString(ref s) => write!(f, "{s}"),
|
||||
Token::NationalStringLiteral(ref s) => write!(f, "N'{s}'"),
|
||||
Token::EscapedStringLiteral(ref s) => write!(f, "E'{s}'"),
|
||||
Token::HexStringLiteral(ref s) => write!(f, "X'{s}'"),
|
||||
Token::Comma => f.write_str(","),
|
||||
Token::Whitespace(ws) => write!(f, "{}", ws),
|
||||
Token::Whitespace(ws) => write!(f, "{ws}"),
|
||||
Token::DoubleEq => f.write_str("=="),
|
||||
Token::Spaceship => f.write_str("<=>"),
|
||||
Token::Eq => f.write_str("="),
|
||||
|
@ -232,7 +232,7 @@ impl fmt::Display for Token {
|
|||
Token::ShiftRight => f.write_str(">>"),
|
||||
Token::PGSquareRoot => f.write_str("|/"),
|
||||
Token::PGCubeRoot => f.write_str("||/"),
|
||||
Token::Placeholder(ref s) => write!(f, "{}", s),
|
||||
Token::Placeholder(ref s) => write!(f, "{s}"),
|
||||
Token::Arrow => write!(f, "->"),
|
||||
Token::LongArrow => write!(f, "->>"),
|
||||
Token::HashArrow => write!(f, "#>"),
|
||||
|
@ -323,8 +323,8 @@ impl fmt::Display for Whitespace {
|
|||
Whitespace::Space => f.write_str(" "),
|
||||
Whitespace::Newline => f.write_str("\n"),
|
||||
Whitespace::Tab => f.write_str("\t"),
|
||||
Whitespace::SingleLineComment { prefix, comment } => write!(f, "{}{}", prefix, comment),
|
||||
Whitespace::MultiLineComment(s) => write!(f, "/*{}*/", s),
|
||||
Whitespace::SingleLineComment { prefix, comment } => write!(f, "{prefix}{comment}"),
|
||||
Whitespace::MultiLineComment(s) => write!(f, "/*{s}*/"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -595,13 +595,13 @@ impl<'a> Tokenizer<'a> {
|
|||
} else {
|
||||
self.tokenizer_error(
|
||||
error_loc,
|
||||
format!("Expected close delimiter '{}' before EOF.", quote_end),
|
||||
format!("Expected close delimiter '{quote_end}' before EOF."),
|
||||
)
|
||||
}
|
||||
}
|
||||
// numbers and period
|
||||
'0'..='9' | '.' => {
|
||||
let mut s = peeking_take_while(chars, |ch| matches!(ch, '0'..='9'));
|
||||
let mut s = peeking_take_while(chars, |ch| ch.is_ascii_digit());
|
||||
|
||||
// match binary literal that starts with 0x
|
||||
if s == "0" && chars.peek() == Some(&'x') {
|
||||
|
@ -618,7 +618,7 @@ impl<'a> Tokenizer<'a> {
|
|||
s.push('.');
|
||||
chars.next();
|
||||
}
|
||||
s += &peeking_take_while(chars, |ch| matches!(ch, '0'..='9'));
|
||||
s += &peeking_take_while(chars, |ch| ch.is_ascii_digit());
|
||||
|
||||
// No number -> Token::Period
|
||||
if s == "." {
|
||||
|
@ -642,12 +642,12 @@ impl<'a> Tokenizer<'a> {
|
|||
|
||||
match char_clone.peek() {
|
||||
// Definitely an exponent, get original iterator up to speed and use it
|
||||
Some(&c) if matches!(c, '0'..='9') => {
|
||||
Some(&c) if c.is_ascii_digit() => {
|
||||
for _ in 0..exponent_part.len() {
|
||||
chars.next();
|
||||
}
|
||||
exponent_part +=
|
||||
&peeking_take_while(chars, |ch| matches!(ch, '0'..='9'));
|
||||
&peeking_take_while(chars, |ch| ch.is_ascii_digit());
|
||||
s += exponent_part.as_str();
|
||||
}
|
||||
// Not an exponent, discard the work done
|
||||
|
@ -907,8 +907,7 @@ impl<'a> Tokenizer<'a> {
|
|||
return self.tokenizer_error(
|
||||
chars.location(),
|
||||
format!(
|
||||
"Unterminated dollar-quoted string at or near \"{}\"",
|
||||
value
|
||||
"Unterminated dollar-quoted string at or near \"{value}\""
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ fn parse_literal_string() {
|
|||
#[test]
|
||||
fn parse_table_identifiers() {
|
||||
fn test_table_ident(ident: &str, expected: Vec<Ident>) {
|
||||
let sql = format!("SELECT 1 FROM {}", ident);
|
||||
let sql = format!("SELECT 1 FROM {ident}");
|
||||
let select = bigquery().verified_only_select(&sql);
|
||||
assert_eq!(
|
||||
select.from,
|
||||
|
@ -51,7 +51,7 @@ fn parse_table_identifiers() {
|
|||
);
|
||||
}
|
||||
fn test_table_ident_err(ident: &str) {
|
||||
let sql = format!("SELECT 1 FROM {}", ident);
|
||||
let sql = format!("SELECT 1 FROM {ident}");
|
||||
assert!(bigquery().parse_sql_statements(&sql).is_err());
|
||||
}
|
||||
|
||||
|
|
|
@ -2435,7 +2435,7 @@ fn parse_create_or_replace_table() {
|
|||
#[test]
|
||||
fn parse_create_table_with_on_delete_on_update_2in_any_order() -> Result<(), ParserError> {
|
||||
let sql = |options: &str| -> String {
|
||||
format!("create table X (y_id int references Y (id) {})", options)
|
||||
format!("create table X (y_id int references Y (id) {options})")
|
||||
};
|
||||
|
||||
parse_sql_statements(&sql("on update cascade on delete no action"))?;
|
||||
|
@ -2777,7 +2777,7 @@ fn parse_alter_table_constraints() {
|
|||
check_one("CHECK (end_date > start_date OR end_date IS NULL)");
|
||||
|
||||
fn check_one(constraint_text: &str) {
|
||||
match verified_stmt(&format!("ALTER TABLE tab ADD {}", constraint_text)) {
|
||||
match verified_stmt(&format!("ALTER TABLE tab ADD {constraint_text}")) {
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
operation: AlterTableOperation::AddConstraint(constraint),
|
||||
|
@ -2787,7 +2787,7 @@ fn parse_alter_table_constraints() {
|
|||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
verified_stmt(&format!("CREATE TABLE foo (id INT, {})", constraint_text));
|
||||
verified_stmt(&format!("CREATE TABLE foo (id INT, {constraint_text})"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2804,7 +2804,7 @@ fn parse_alter_table_drop_column() {
|
|||
);
|
||||
|
||||
fn check_one(constraint_text: &str) {
|
||||
match verified_stmt(&format!("ALTER TABLE tab {}", constraint_text)) {
|
||||
match verified_stmt(&format!("ALTER TABLE tab {constraint_text}")) {
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
operation:
|
||||
|
@ -2827,10 +2827,7 @@ fn parse_alter_table_drop_column() {
|
|||
#[test]
|
||||
fn parse_alter_table_alter_column() {
|
||||
let alter_stmt = "ALTER TABLE tab";
|
||||
match verified_stmt(&format!(
|
||||
"{} ALTER COLUMN is_active SET NOT NULL",
|
||||
alter_stmt
|
||||
)) {
|
||||
match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active SET NOT NULL")) {
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
operation: AlterTableOperation::AlterColumn { column_name, op },
|
||||
|
@ -2848,8 +2845,7 @@ fn parse_alter_table_alter_column() {
|
|||
);
|
||||
|
||||
match verified_stmt(&format!(
|
||||
"{} ALTER COLUMN is_active SET DEFAULT false",
|
||||
alter_stmt
|
||||
"{alter_stmt} ALTER COLUMN is_active SET DEFAULT false"
|
||||
)) {
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
|
@ -2867,10 +2863,7 @@ fn parse_alter_table_alter_column() {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
match verified_stmt(&format!(
|
||||
"{} ALTER COLUMN is_active DROP DEFAULT",
|
||||
alter_stmt
|
||||
)) {
|
||||
match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active DROP DEFAULT")) {
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
operation: AlterTableOperation::AlterColumn { column_name, op },
|
||||
|
@ -2906,7 +2899,7 @@ fn parse_alter_table_alter_column_type() {
|
|||
|
||||
let res = Parser::parse_sql(
|
||||
&GenericDialect {},
|
||||
&format!("{} ALTER COLUMN is_active TYPE TEXT", alter_stmt),
|
||||
&format!("{alter_stmt} ALTER COLUMN is_active TYPE TEXT"),
|
||||
);
|
||||
assert_eq!(
|
||||
ParserError::ParserError("Expected SET/DROP NOT NULL, SET DEFAULT, SET DATA TYPE after ALTER COLUMN, found: TYPE".to_string()),
|
||||
|
@ -2915,10 +2908,7 @@ fn parse_alter_table_alter_column_type() {
|
|||
|
||||
let res = Parser::parse_sql(
|
||||
&GenericDialect {},
|
||||
&format!(
|
||||
"{} ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'",
|
||||
alter_stmt
|
||||
),
|
||||
&format!("{alter_stmt} ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'"),
|
||||
);
|
||||
assert_eq!(
|
||||
ParserError::ParserError("Expected end of statement, found: USING".to_string()),
|
||||
|
@ -2966,7 +2956,7 @@ fn parse_alter_table_drop_constraint() {
|
|||
|
||||
let res = Parser::parse_sql(
|
||||
&GenericDialect {},
|
||||
&format!("{} DROP CONSTRAINT is_active TEXT", alter_stmt),
|
||||
&format!("{alter_stmt} DROP CONSTRAINT is_active TEXT"),
|
||||
);
|
||||
assert_eq!(
|
||||
ParserError::ParserError("Expected end of statement, found: TEXT".to_string()),
|
||||
|
@ -2997,7 +2987,7 @@ fn parse_scalar_function_in_projection() {
|
|||
|
||||
for function_name in names {
|
||||
// like SELECT sqrt(id) FROM foo
|
||||
let sql = dbg!(format!("SELECT {}(id) FROM foo", function_name));
|
||||
let sql = dbg!(format!("SELECT {function_name}(id) FROM foo"));
|
||||
let select = verified_only_select(&sql);
|
||||
assert_eq!(
|
||||
&Expr::Function(Function {
|
||||
|
@ -4221,7 +4211,7 @@ fn parse_ctes() {
|
|||
// Top-level CTE
|
||||
assert_ctes_in_select(&cte_sqls, &verified_query(with));
|
||||
// CTE in a subquery
|
||||
let sql = &format!("SELECT ({})", with);
|
||||
let sql = &format!("SELECT ({with})");
|
||||
let select = verified_only_select(sql);
|
||||
match expr_from_projection(only(&select.projection)) {
|
||||
Expr::Subquery(ref subquery) => {
|
||||
|
@ -4230,7 +4220,7 @@ fn parse_ctes() {
|
|||
_ => panic!("Expected subquery"),
|
||||
}
|
||||
// CTE in a derived table
|
||||
let sql = &format!("SELECT * FROM ({})", with);
|
||||
let sql = &format!("SELECT * FROM ({with})");
|
||||
let select = verified_only_select(sql);
|
||||
match only(select.from).relation {
|
||||
TableFactor::Derived { subquery, .. } => {
|
||||
|
@ -4239,13 +4229,13 @@ fn parse_ctes() {
|
|||
_ => panic!("Expected derived table"),
|
||||
}
|
||||
// CTE in a view
|
||||
let sql = &format!("CREATE VIEW v AS {}", with);
|
||||
let sql = &format!("CREATE VIEW v AS {with}");
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView { query, .. } => assert_ctes_in_select(&cte_sqls, &query),
|
||||
_ => panic!("Expected CREATE VIEW"),
|
||||
}
|
||||
// CTE in a CTE...
|
||||
let sql = &format!("WITH outer_cte AS ({}) SELECT * FROM outer_cte", with);
|
||||
let sql = &format!("WITH outer_cte AS ({with}) SELECT * FROM outer_cte");
|
||||
let select = verified_query(sql);
|
||||
assert_ctes_in_select(&cte_sqls, &only(&select.with.unwrap().cte_tables).query);
|
||||
}
|
||||
|
@ -4270,10 +4260,7 @@ fn parse_cte_renamed_columns() {
|
|||
#[test]
|
||||
fn parse_recursive_cte() {
|
||||
let cte_query = "SELECT 1 UNION ALL SELECT val + 1 FROM nums WHERE val < 10".to_owned();
|
||||
let sql = &format!(
|
||||
"WITH RECURSIVE nums (val) AS ({}) SELECT * FROM nums",
|
||||
cte_query
|
||||
);
|
||||
let sql = &format!("WITH RECURSIVE nums (val) AS ({cte_query}) SELECT * FROM nums");
|
||||
|
||||
let cte_query = verified_query(&cte_query);
|
||||
let query = verified_query(sql);
|
||||
|
@ -5029,9 +5016,8 @@ fn lateral_derived() {
|
|||
fn chk(lateral_in: bool) {
|
||||
let lateral_str = if lateral_in { "LATERAL " } else { "" };
|
||||
let sql = format!(
|
||||
"SELECT * FROM customer LEFT JOIN {}\
|
||||
(SELECT * FROM order WHERE order.customer = customer.id LIMIT 3) AS order ON true",
|
||||
lateral_str
|
||||
"SELECT * FROM customer LEFT JOIN {lateral_str}\
|
||||
(SELECT * FROM order WHERE order.customer = customer.id LIMIT 3) AS order ON true"
|
||||
);
|
||||
let select = verified_only_select(&sql);
|
||||
let from = only(select.from);
|
||||
|
@ -6286,9 +6272,7 @@ fn parse_cache_table() {
|
|||
let query = all_dialects().verified_query(sql);
|
||||
|
||||
assert_eq!(
|
||||
verified_stmt(
|
||||
format!("CACHE TABLE '{table_name}'", table_name = cache_table_name).as_str()
|
||||
),
|
||||
verified_stmt(format!("CACHE TABLE '{cache_table_name}'").as_str()),
|
||||
Statement::Cache {
|
||||
table_flag: None,
|
||||
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
|
||||
|
@ -6299,14 +6283,7 @@ fn parse_cache_table() {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
verified_stmt(
|
||||
format!(
|
||||
"CACHE {flag} TABLE '{table_name}'",
|
||||
flag = table_flag,
|
||||
table_name = cache_table_name
|
||||
)
|
||||
.as_str()
|
||||
),
|
||||
verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}'").as_str()),
|
||||
Statement::Cache {
|
||||
table_flag: Some(ObjectName(vec![Ident::new(table_flag)])),
|
||||
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
|
||||
|
@ -6319,9 +6296,7 @@ fn parse_cache_table() {
|
|||
assert_eq!(
|
||||
verified_stmt(
|
||||
format!(
|
||||
"CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88)",
|
||||
flag = table_flag,
|
||||
table_name = cache_table_name,
|
||||
"CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88)",
|
||||
)
|
||||
.as_str()
|
||||
),
|
||||
|
@ -6346,10 +6321,7 @@ fn parse_cache_table() {
|
|||
assert_eq!(
|
||||
verified_stmt(
|
||||
format!(
|
||||
"CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) {sql}",
|
||||
flag = table_flag,
|
||||
table_name = cache_table_name,
|
||||
sql = sql,
|
||||
"CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) {sql}",
|
||||
)
|
||||
.as_str()
|
||||
),
|
||||
|
@ -6374,10 +6346,7 @@ fn parse_cache_table() {
|
|||
assert_eq!(
|
||||
verified_stmt(
|
||||
format!(
|
||||
"CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) AS {sql}",
|
||||
flag = table_flag,
|
||||
table_name = cache_table_name,
|
||||
sql = sql,
|
||||
"CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) AS {sql}",
|
||||
)
|
||||
.as_str()
|
||||
),
|
||||
|
@ -6400,15 +6369,7 @@ fn parse_cache_table() {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
verified_stmt(
|
||||
format!(
|
||||
"CACHE {flag} TABLE '{table_name}' {sql}",
|
||||
flag = table_flag,
|
||||
table_name = cache_table_name,
|
||||
sql = sql
|
||||
)
|
||||
.as_str()
|
||||
),
|
||||
verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}' {sql}").as_str()),
|
||||
Statement::Cache {
|
||||
table_flag: Some(ObjectName(vec![Ident::new(table_flag)])),
|
||||
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
|
||||
|
@ -6419,14 +6380,7 @@ fn parse_cache_table() {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
verified_stmt(
|
||||
format!(
|
||||
"CACHE {flag} TABLE '{table_name}' AS {sql}",
|
||||
flag = table_flag,
|
||||
table_name = cache_table_name
|
||||
)
|
||||
.as_str()
|
||||
),
|
||||
verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}' AS {sql}").as_str()),
|
||||
Statement::Cache {
|
||||
table_flag: Some(ObjectName(vec![Ident::new(table_flag)])),
|
||||
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
|
||||
|
@ -6574,7 +6528,7 @@ fn parse_with_recursion_limit() {
|
|||
.expect("tokenize to work")
|
||||
.parse_statements();
|
||||
|
||||
assert!(matches!(res, Ok(_)), "{:?}", res);
|
||||
assert!(matches!(res, Ok(_)), "{res:?}");
|
||||
|
||||
// limit recursion to something smaller, expect parsing to fail
|
||||
let res = Parser::new(&dialect)
|
||||
|
@ -6592,7 +6546,7 @@ fn parse_with_recursion_limit() {
|
|||
.with_recursion_limit(50)
|
||||
.parse_statements();
|
||||
|
||||
assert!(matches!(res, Ok(_)), "{:?}", res);
|
||||
assert!(matches!(res, Ok(_)), "{res:?}");
|
||||
}
|
||||
|
||||
/// Makes a predicate that looks like ((user_id = $id) OR user_id = $2...)
|
||||
|
@ -6604,7 +6558,7 @@ fn make_where_clause(num: usize) -> String {
|
|||
if i > 0 {
|
||||
write!(&mut output, " OR ").unwrap();
|
||||
}
|
||||
write!(&mut output, "user_id = {}", i).unwrap();
|
||||
write!(&mut output, "user_id = {i}").unwrap();
|
||||
if i < num - 1 {
|
||||
write!(&mut output, ")").unwrap();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ fn custom_prefix_parser() -> Result<(), ParserError> {
|
|||
let sql = "SELECT 1 + 2";
|
||||
let ast = Parser::parse_sql(&dialect, sql)?;
|
||||
let query = &ast[0];
|
||||
assert_eq!("SELECT NULL + 2", &format!("{}", query));
|
||||
assert_eq!("SELECT NULL + 2", &format!("{query}"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ fn custom_infix_parser() -> Result<(), ParserError> {
|
|||
let sql = "SELECT 1 + 2";
|
||||
let ast = Parser::parse_sql(&dialect, sql)?;
|
||||
let query = &ast[0];
|
||||
assert_eq!("SELECT 1 * 2", &format!("{}", query));
|
||||
assert_eq!("SELECT 1 * 2", &format!("{query}"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ fn custom_statement_parser() -> Result<(), ParserError> {
|
|||
let sql = "SELECT 1 + 2";
|
||||
let ast = Parser::parse_sql(&dialect, sql)?;
|
||||
let query = &ast[0];
|
||||
assert_eq!("COMMIT", &format!("{}", query));
|
||||
assert_eq!("COMMIT", &format!("{query}"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ fn parse_show_create() {
|
|||
ShowCreateObject::View,
|
||||
] {
|
||||
assert_eq!(
|
||||
mysql_and_generic().verified_stmt(format!("SHOW CREATE {} myident", obj_type).as_str()),
|
||||
mysql_and_generic().verified_stmt(format!("SHOW CREATE {obj_type} myident").as_str()),
|
||||
Statement::ShowCreate {
|
||||
obj_type: *obj_type,
|
||||
obj_name: obj_name.clone(),
|
||||
|
|
|
@ -485,7 +485,7 @@ PHP ₱ USD $
|
|||
\N Some other value
|
||||
\\."#;
|
||||
let ast = pg_and_generic().one_statement_parses_to(sql, "");
|
||||
println!("{:#?}", ast);
|
||||
println!("{ast:#?}");
|
||||
//assert_eq!(sql, ast.to_string());
|
||||
}
|
||||
|
||||
|
@ -2069,7 +2069,7 @@ fn parse_create_role() {
|
|||
assert_eq!(*login, Some(true));
|
||||
assert_eq!(*password, Some(Password::NullPassword));
|
||||
}
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {err:?}"),
|
||||
}
|
||||
|
||||
let sql = "CREATE ROLE abc WITH LOGIN PASSWORD NULL";
|
||||
|
@ -2086,7 +2086,7 @@ fn parse_create_role() {
|
|||
assert_eq!(*login, Some(true));
|
||||
assert_eq!(*password, Some(Password::NullPassword));
|
||||
}
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {err:?}"),
|
||||
}
|
||||
|
||||
let sql = "CREATE ROLE magician WITH SUPERUSER CREATEROLE NOCREATEDB BYPASSRLS INHERIT PASSWORD 'abcdef' LOGIN VALID UNTIL '2025-01-01' IN ROLE role1, role2 ROLE role3 ADMIN role4, role5 REPLICATION";
|
||||
|
@ -2141,7 +2141,7 @@ fn parse_create_role() {
|
|||
assert_eq_vec(&["role4", "role5"], admin);
|
||||
assert_eq!(*authorization_owner, None);
|
||||
}
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {err:?}"),
|
||||
}
|
||||
|
||||
let sql = "CREATE ROLE abc WITH USER foo, bar ROLE baz ";
|
||||
|
@ -2155,7 +2155,7 @@ fn parse_create_role() {
|
|||
assert_eq_vec(&["foo", "bar"], user);
|
||||
assert_eq_vec(&["baz"], role);
|
||||
}
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
|
||||
err => panic!("Failed to parse CREATE ROLE test case: {err:?}"),
|
||||
}
|
||||
|
||||
let negatables = vec![
|
||||
|
@ -2169,9 +2169,9 @@ fn parse_create_role() {
|
|||
];
|
||||
|
||||
for negatable_kw in negatables.iter() {
|
||||
let sql = format!("CREATE ROLE abc {kw} NO{kw}", kw = negatable_kw);
|
||||
let sql = format!("CREATE ROLE abc {negatable_kw} NO{negatable_kw}");
|
||||
if pg().parse_sql_statements(&sql).is_ok() {
|
||||
panic!("Should not be able to parse CREATE ROLE containing both negated and non-negated versions of the same keyword: {}", negatable_kw)
|
||||
panic!("Should not be able to parse CREATE ROLE containing both negated and non-negated versions of the same keyword: {negatable_kw}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue