mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-08 01:15:00 +00:00
feat: support INSERT INTO [TABLE] FUNCTION
of Clickhouse (#1633)
Co-authored-by: Kermit <chenjiawei1@xiaohongshu.com> Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
c54ba4dc41
commit
b09514e492
11 changed files with 147 additions and 53 deletions
|
@ -1406,13 +1406,16 @@ fn parse_simple_insert() {
|
|||
|
||||
match mysql().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("tasks")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert_eq!(
|
||||
|
@ -1460,14 +1463,17 @@ fn parse_ignore_insert() {
|
|||
|
||||
match mysql_and_generic().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
ignore,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("tasks")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert!(ignore);
|
||||
|
@ -1504,14 +1510,17 @@ fn parse_priority_insert() {
|
|||
|
||||
match mysql_and_generic().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
priority,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("tasks")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert_eq!(priority, Some(HighPriority));
|
||||
|
@ -1545,14 +1554,17 @@ fn parse_priority_insert() {
|
|||
|
||||
match mysql().verified_stmt(sql2) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
priority,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("tasks")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert_eq!(priority, Some(LowPriority));
|
||||
|
@ -1588,14 +1600,14 @@ fn parse_insert_as() {
|
|||
let sql = r"INSERT INTO `table` (`date`) VALUES ('2024-01-01') AS `alias`";
|
||||
match mysql_and_generic().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
insert_alias,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(
|
||||
ObjectName(vec![Ident::with_quote('`', "table")]),
|
||||
TableObject::TableName(ObjectName(vec![Ident::with_quote('`', "table")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(vec![Ident::with_quote('`', "date")], columns);
|
||||
|
@ -1640,14 +1652,14 @@ fn parse_insert_as() {
|
|||
let sql = r"INSERT INTO `table` (`id`, `date`) VALUES (1, '2024-01-01') AS `alias` (`mek_id`, `mek_date`)";
|
||||
match mysql_and_generic().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
insert_alias,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(
|
||||
ObjectName(vec![Ident::with_quote('`', "table")]),
|
||||
TableObject::TableName(ObjectName(vec![Ident::with_quote('`', "table")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -1698,7 +1710,7 @@ fn parse_replace_insert() {
|
|||
let sql = r"REPLACE DELAYED INTO tasks (title, priority) VALUES ('Test Some Inserts', 1)";
|
||||
match mysql().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
|
@ -1706,7 +1718,10 @@ fn parse_replace_insert() {
|
|||
priority,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("tasks")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert!(replace_into);
|
||||
|
@ -1744,13 +1759,16 @@ fn parse_empty_row_insert() {
|
|||
|
||||
match mysql().one_statement_parses_to(sql, "INSERT INTO tb VALUES (), ()") {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tb")]), table_name);
|
||||
assert_eq!(
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("tb")])),
|
||||
table_name
|
||||
);
|
||||
assert!(columns.is_empty());
|
||||
assert!(on.is_none());
|
||||
assert_eq!(
|
||||
|
@ -1783,14 +1801,14 @@ fn parse_insert_with_on_duplicate_update() {
|
|||
|
||||
match mysql().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(
|
||||
ObjectName(vec![Ident::new("permission_groups")]),
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("permission_groups")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -1974,12 +1992,12 @@ fn parse_insert_with_numeric_prefix_column_name() {
|
|||
let sql = "INSERT INTO s1.t1 (123col_$@length123) VALUES (67.654)";
|
||||
match mysql().verified_stmt(sql) {
|
||||
Statement::Insert(Insert {
|
||||
table_name,
|
||||
table: table_name,
|
||||
columns,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(
|
||||
ObjectName(vec![Ident::new("s1"), Ident::new("t1")]),
|
||||
TableObject::TableName(ObjectName(vec![Ident::new("s1"), Ident::new("t1")])),
|
||||
table_name
|
||||
);
|
||||
assert_eq!(vec![Ident::new("123col_$@length123")], columns);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue