mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
Support CREATE TABLE x AS TABLE y
(#704)
* first commit * fix style and edit test * fix test? * remove unnecessary logic * refactor implementation * codestyle * add schema support * codestyle and lint * Apply suggestions from code review Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> * PartialOrd and Ord * clean up parser logic * codestyle and lint Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
8e1c90c0d8
commit
528b3f2234
4 changed files with 131 additions and 2 deletions
|
@ -2273,6 +2273,55 @@ fn parse_create_table_as() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_as_table() {
|
||||
let sql1 = "CREATE TABLE new_table AS TABLE old_table";
|
||||
|
||||
let expected_query1 = Box::new(Query {
|
||||
with: None,
|
||||
body: Box::new(SetExpr::Table(Box::new(Table {
|
||||
table_name: Some("old_table".to_string()),
|
||||
schema_name: None,
|
||||
}))),
|
||||
order_by: vec![],
|
||||
limit: None,
|
||||
offset: None,
|
||||
fetch: None,
|
||||
lock: None,
|
||||
});
|
||||
|
||||
match verified_stmt(sql1) {
|
||||
Statement::CreateTable { query, name, .. } => {
|
||||
assert_eq!(name, ObjectName(vec![Ident::new("new_table")]));
|
||||
assert_eq!(query.unwrap(), expected_query1);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let sql2 = "CREATE TABLE new_table AS TABLE schema_name.old_table";
|
||||
|
||||
let expected_query2 = Box::new(Query {
|
||||
with: None,
|
||||
body: Box::new(SetExpr::Table(Box::new(Table {
|
||||
table_name: Some("old_table".to_string()),
|
||||
schema_name: Some("schema_name".to_string()),
|
||||
}))),
|
||||
order_by: vec![],
|
||||
limit: None,
|
||||
offset: None,
|
||||
fetch: None,
|
||||
lock: None,
|
||||
});
|
||||
|
||||
match verified_stmt(sql2) {
|
||||
Statement::CreateTable { query, name, .. } => {
|
||||
assert_eq!(name, ObjectName(vec![Ident::new("new_table")]));
|
||||
assert_eq!(query.unwrap(), expected_query2);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_on_cluster() {
|
||||
// Using single-quote literal to define current cluster
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue