Skip to content

Commit b08cdfd

Browse files
committed
fix merge error
2 parents 9576438 + 3b4dc0f commit b08cdfd

19 files changed

+1228
-200
lines changed

src/ast/ddl.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ pub enum AlterTableOperation {
115115
DropConstraint {
116116
if_exists: bool,
117117
name: Ident,
118-
cascade: bool,
118+
drop_behavior: Option<DropBehavior>,
119119
},
120120
/// `DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ CASCADE ]`
121121
DropColumn {
122122
column_name: Ident,
123123
if_exists: bool,
124-
cascade: bool,
124+
drop_behavior: Option<DropBehavior>,
125125
},
126126
/// `ATTACH PART|PARTITION <partition_expr>`
127127
/// Note: this is a ClickHouse-specific operation, please refer to
@@ -451,27 +451,35 @@ impl fmt::Display for AlterTableOperation {
451451
AlterTableOperation::DropConstraint {
452452
if_exists,
453453
name,
454-
cascade,
454+
drop_behavior,
455455
} => {
456456
write!(
457457
f,
458458
"DROP CONSTRAINT {}{}{}",
459459
if *if_exists { "IF EXISTS " } else { "" },
460460
name,
461-
if *cascade { " CASCADE" } else { "" },
461+
match drop_behavior {
462+
None => "",
463+
Some(DropBehavior::Restrict) => " RESTRICT",
464+
Some(DropBehavior::Cascade) => " CASCADE",
465+
}
462466
)
463467
}
464468
AlterTableOperation::DropPrimaryKey => write!(f, "DROP PRIMARY KEY"),
465469
AlterTableOperation::DropColumn {
466470
column_name,
467471
if_exists,
468-
cascade,
472+
drop_behavior,
469473
} => write!(
470474
f,
471475
"DROP COLUMN {}{}{}",
472476
if *if_exists { "IF EXISTS " } else { "" },
473477
column_name,
474-
if *cascade { " CASCADE" } else { "" }
478+
match drop_behavior {
479+
None => "",
480+
Some(DropBehavior::Restrict) => " RESTRICT",
481+
Some(DropBehavior::Cascade) => " CASCADE",
482+
}
475483
),
476484
AlterTableOperation::AttachPartition { partition } => {
477485
write!(f, "ATTACH {partition}")

src/ast/dml.rs

+30-12
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ use sqlparser_derive::{Visit, VisitMut};
3232
pub use super::ddl::{ColumnDef, TableConstraint};
3333

3434
use super::{
35-
display_comma_separated, display_separated, Assignment, ClusteredBy, CommentDef, Expr,
36-
FileFormat, FromTable, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident,
37-
InsertAliases, MysqlInsertPriority, ObjectName, OnCommit, OnInsert, OneOrManyWithParens,
38-
OrderByExpr, Query, RowAccessPolicy, SelectItem, SqlOption, SqliteOnConflict, TableEngine,
39-
TableWithJoins, Tag, WrappedCollection,
35+
display_comma_separated, display_separated, query::InputFormatClause, Assignment, ClusteredBy,
36+
CommentDef, Expr, FileFormat, FromTable, HiveDistributionStyle, HiveFormat, HiveIOFormat,
37+
HiveRowFormat, Ident, InsertAliases, MysqlInsertPriority, ObjectName, OnCommit, OnInsert,
38+
OneOrManyWithParens, OrderByExpr, Query, RowAccessPolicy, SelectItem, Setting, SqlOption,
39+
SqliteOnConflict, TableEngine, TableObject, TableWithJoins, Tag, WrappedCollection,
4040
};
4141

4242
/// CREATE INDEX statement.
@@ -470,8 +470,7 @@ pub struct Insert {
470470
/// INTO - optional keyword
471471
pub into: bool,
472472
/// TABLE
473-
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
474-
pub table_name: ObjectName,
473+
pub table: TableObject,
475474
/// table_name as foo (for PostgreSQL)
476475
pub table_alias: Option<Ident>,
477476
/// COLUMNS
@@ -488,7 +487,7 @@ pub struct Insert {
488487
/// Columns defined after PARTITION
489488
pub after_columns: Vec<Ident>,
490489
/// whether the insert has the table keyword (Hive)
491-
pub table: bool,
490+
pub has_table_keyword: bool,
492491
pub on: Option<OnInsert>,
493492
/// RETURNING
494493
pub returning: Option<Vec<SelectItem>>,
@@ -498,14 +497,27 @@ pub struct Insert {
498497
pub priority: Option<MysqlInsertPriority>,
499498
/// Only for mysql
500499
pub insert_alias: Option<InsertAliases>,
500+
/// Settings used for ClickHouse.
501+
///
502+
/// ClickHouse syntax: `INSERT INTO tbl SETTINGS format_template_resultset = '/some/path/resultset.format'`
503+
///
504+
/// [ClickHouse `INSERT INTO`](https://clickhouse.com/docs/en/sql-reference/statements/insert-into)
505+
pub settings: Option<Vec<Setting>>,
506+
/// Format for `INSERT` statement when not using standard SQL format. Can be e.g. `CSV`,
507+
/// `JSON`, `JSONAsString`, `LineAsString` and more.
508+
///
509+
/// ClickHouse syntax: `INSERT INTO tbl FORMAT JSONEachRow {"foo": 1, "bar": 2}, {"foo": 3}`
510+
///
511+
/// [ClickHouse formats JSON insert](https://clickhouse.com/docs/en/interfaces/formats#json-inserting-data)
512+
pub format_clause: Option<InputFormatClause>,
501513
}
502514

503515
impl Display for Insert {
504516
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
505517
let table_name = if let Some(alias) = &self.table_alias {
506-
format!("{0} AS {alias}", self.table_name)
518+
format!("{0} AS {alias}", self.table)
507519
} else {
508-
self.table_name.to_string()
520+
self.table.to_string()
509521
};
510522

511523
if let Some(on_conflict) = self.or {
@@ -531,7 +543,7 @@ impl Display for Insert {
531543
ignore = if self.ignore { " IGNORE" } else { "" },
532544
over = if self.overwrite { " OVERWRITE" } else { "" },
533545
int = if self.into { " INTO" } else { "" },
534-
tbl = if self.table { " TABLE" } else { "" },
546+
tbl = if self.has_table_keyword { " TABLE" } else { "" },
535547
)?;
536548
}
537549
if !self.columns.is_empty() {
@@ -546,12 +558,18 @@ impl Display for Insert {
546558
write!(f, "({}) ", display_comma_separated(&self.after_columns))?;
547559
}
548560

561+
if let Some(settings) = &self.settings {
562+
write!(f, "SETTINGS {} ", display_comma_separated(settings))?;
563+
}
564+
549565
if let Some(source) = &self.source {
550566
write!(f, "{source}")?;
551567
} else if !self.assignments.is_empty() {
552568
write!(f, "SET ")?;
553569
write!(f, "{}", display_comma_separated(&self.assignments))?;
554-
} else if self.source.is_none() && self.columns.is_empty() {
570+
} else if let Some(format_clause) = &self.format_clause {
571+
write!(f, "{format_clause}")?;
572+
} else if self.columns.is_empty() {
555573
write!(f, "DEFAULT VALUES")?;
556574
}
557575

0 commit comments

Comments
 (0)