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:
Sarah Yurick 2022-12-01 06:56:14 -08:00 committed by GitHub
parent 8e1c90c0d8
commit 528b3f2234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 131 additions and 2 deletions

View file

@ -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