mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 19:27:21 +00:00
commit
1337820c06
3 changed files with 36 additions and 56 deletions
|
@ -299,7 +299,7 @@ impl fmt::Display for Expr {
|
|||
results,
|
||||
else_result,
|
||||
} => {
|
||||
f.write_str("CASE")?;
|
||||
write!(f, "CASE")?;
|
||||
if let Some(operand) = operand {
|
||||
write!(f, " {}", operand)?;
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ impl fmt::Display for Expr {
|
|||
if let Some(else_result) = else_result {
|
||||
write!(f, " ELSE {}", else_result)?;
|
||||
}
|
||||
f.write_str(" END")
|
||||
write!(f, " END")
|
||||
}
|
||||
Expr::Exists(s) => write!(f, "EXISTS ({})", s),
|
||||
Expr::Subquery(s) => write!(f, "({})", s),
|
||||
|
@ -626,8 +626,7 @@ impl fmt::Display for Statement {
|
|||
} => {
|
||||
write!(f, "UPDATE {}", table_name)?;
|
||||
if !assignments.is_empty() {
|
||||
write!(f, " SET ")?;
|
||||
write!(f, "{}", display_comma_separated(assignments))?;
|
||||
write!(f, " SET {}", display_comma_separated(assignments))?;
|
||||
}
|
||||
if let Some(selection) = selection {
|
||||
write!(f, " WHERE {}", selection)?;
|
||||
|
@ -652,26 +651,19 @@ impl fmt::Display for Statement {
|
|||
materialized,
|
||||
with_options,
|
||||
} => {
|
||||
write!(f, "CREATE")?;
|
||||
|
||||
if *or_replace {
|
||||
write!(f, " OR REPLACE")?;
|
||||
}
|
||||
|
||||
if *materialized {
|
||||
write!(f, " MATERIALIZED")?;
|
||||
}
|
||||
|
||||
write!(f, " VIEW {}", name)?;
|
||||
|
||||
write!(
|
||||
f,
|
||||
"CREATE {or_replace}{materialized}VIEW {name}",
|
||||
or_replace = if *or_replace { "OR REPLACE " } else { "" },
|
||||
materialized = if *materialized { "MATERIALIZED " } else { "" },
|
||||
name = name
|
||||
)?;
|
||||
if !with_options.is_empty() {
|
||||
write!(f, " WITH ({})", display_comma_separated(with_options))?;
|
||||
}
|
||||
|
||||
if !columns.is_empty() {
|
||||
write!(f, " ({})", display_comma_separated(columns))?;
|
||||
}
|
||||
|
||||
write!(f, " AS {}", query)
|
||||
}
|
||||
Statement::CreateTable {
|
||||
|
@ -716,7 +708,6 @@ impl fmt::Display for Statement {
|
|||
if *without_rowid {
|
||||
write!(f, " WITHOUT ROWID")?;
|
||||
}
|
||||
|
||||
if *external {
|
||||
write!(
|
||||
f,
|
||||
|
@ -757,22 +748,15 @@ impl fmt::Display for Statement {
|
|||
columns,
|
||||
unique,
|
||||
if_not_exists,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"CREATE{}INDEX{}{} ON {}({}",
|
||||
if *unique { " UNIQUE " } else { " " },
|
||||
if *if_not_exists {
|
||||
" IF NOT EXISTS "
|
||||
} else {
|
||||
" "
|
||||
},
|
||||
name,
|
||||
table_name,
|
||||
display_separated(columns, ",")
|
||||
)?;
|
||||
write!(f, ");")
|
||||
}
|
||||
} => write!(
|
||||
f,
|
||||
"CREATE {unique}INDEX {if_not_exists}{name} ON {table_name}({columns})",
|
||||
unique = if *unique { "UNIQUE " } else { "" },
|
||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
||||
name = name,
|
||||
table_name = table_name,
|
||||
columns = display_separated(columns, ",")
|
||||
),
|
||||
Statement::AlterTable { name, operation } => {
|
||||
write!(f, "ALTER TABLE {} {}", name, operation)
|
||||
}
|
||||
|
@ -793,13 +777,13 @@ impl fmt::Display for Statement {
|
|||
local,
|
||||
variable,
|
||||
value,
|
||||
} => {
|
||||
f.write_str("SET ")?;
|
||||
if *local {
|
||||
f.write_str("LOCAL ")?;
|
||||
}
|
||||
write!(f, "{} = {}", variable, value)
|
||||
}
|
||||
} => write!(
|
||||
f,
|
||||
"SET{local} {variable} = {value}",
|
||||
local = if *local { " LOCAL" } else { "" },
|
||||
variable = variable,
|
||||
value = value
|
||||
),
|
||||
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
|
||||
Statement::ShowColumns {
|
||||
extended,
|
||||
|
@ -807,14 +791,13 @@ impl fmt::Display for Statement {
|
|||
table_name,
|
||||
filter,
|
||||
} => {
|
||||
f.write_str("SHOW ")?;
|
||||
if *extended {
|
||||
f.write_str("EXTENDED ")?;
|
||||
}
|
||||
if *full {
|
||||
f.write_str("FULL ")?;
|
||||
}
|
||||
write!(f, "COLUMNS FROM {}", table_name)?;
|
||||
write!(
|
||||
f,
|
||||
"SHOW {extended}{full}COLUMNS FROM {table_name}",
|
||||
extended = if *extended { "EXTENDED " } else { "" },
|
||||
full = if *full { "FULL " } else { "" },
|
||||
table_name = table_name,
|
||||
)?;
|
||||
if let Some(filter) = filter {
|
||||
write!(f, " {}", filter)?;
|
||||
}
|
||||
|
@ -843,7 +826,6 @@ impl fmt::Display for Statement {
|
|||
Statement::CreateSchema { schema_name } => write!(f, "CREATE SCHEMA {}", schema_name),
|
||||
Statement::Assert { condition, message } => {
|
||||
write!(f, "ASSERT {}", condition)?;
|
||||
|
||||
if let Some(m) = message {
|
||||
write!(f, " AS {}", m)?;
|
||||
}
|
||||
|
@ -941,7 +923,7 @@ impl fmt::Display for FileFormat {
|
|||
PARQUET => "PARQUET",
|
||||
AVRO => "AVRO",
|
||||
RCFILE => "RCFILE",
|
||||
JSONFILE => "TEXTFILE",
|
||||
JSONFILE => "JSONFILE",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3152,7 +3152,7 @@ fn ensure_multiple_dialects_are_tested() {
|
|||
|
||||
#[test]
|
||||
fn parse_create_index() {
|
||||
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name,age);";
|
||||
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name,age)";
|
||||
let ident_vec = vec![Ident::new("name"), Ident::new("age")];
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateIndex {
|
||||
|
|
|
@ -474,14 +474,12 @@ fn parse_execute() {
|
|||
);
|
||||
|
||||
let stmt = pg_and_generic().verified_stmt("EXECUTE a(1, 't')");
|
||||
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::Execute {
|
||||
name: "a".into(),
|
||||
parameters: vec![
|
||||
Expr::Value(Value::Number(bigdecimal::BigDecimal::from(1))),
|
||||
Expr::Value(number("1")),
|
||||
Expr::Value(Value::SingleQuotedString("t".to_string()))
|
||||
],
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue