mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-11-19 14:26:43 +00:00
Moving several struct variants out of Statement enum to allow for trait impls for specific sub-variants (#2057)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
This commit is contained in:
parent
e7d42f3d1a
commit
cc595cfd84
15 changed files with 1032 additions and 962 deletions
|
|
@ -377,12 +377,12 @@ fn parse_insert_sqlite() {
|
|||
fn parse_update() {
|
||||
let sql = "UPDATE t SET a = 1, b = 2, c = 3 WHERE d";
|
||||
match verified_stmt(sql) {
|
||||
Statement::Update {
|
||||
Statement::Update(Update {
|
||||
table,
|
||||
assignments,
|
||||
selection,
|
||||
..
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(table.to_string(), "t".to_string());
|
||||
assert_eq!(
|
||||
assignments,
|
||||
|
|
@ -439,7 +439,7 @@ fn parse_update_set_from() {
|
|||
let stmt = dialects.verified_stmt(sql);
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::Update {
|
||||
Statement::Update(Update {
|
||||
table: TableWithJoins {
|
||||
relation: table_from_name(ObjectName::from(vec![Ident::new("t1")])),
|
||||
joins: vec![],
|
||||
|
|
@ -516,7 +516,7 @@ fn parse_update_set_from() {
|
|||
returning: None,
|
||||
or: None,
|
||||
limit: None
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
let sql = "UPDATE T SET a = b FROM U, (SELECT foo FROM V) AS W WHERE 1 = 1";
|
||||
|
|
@ -527,7 +527,7 @@ fn parse_update_set_from() {
|
|||
fn parse_update_with_table_alias() {
|
||||
let sql = "UPDATE users AS u SET u.username = 'new_user' WHERE u.username = 'old_user'";
|
||||
match verified_stmt(sql) {
|
||||
Statement::Update {
|
||||
Statement::Update(Update {
|
||||
table,
|
||||
assignments,
|
||||
from: _from,
|
||||
|
|
@ -535,7 +535,7 @@ fn parse_update_with_table_alias() {
|
|||
returning,
|
||||
or: None,
|
||||
limit: None,
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(
|
||||
TableWithJoins {
|
||||
relation: TableFactor::Table {
|
||||
|
|
@ -591,7 +591,7 @@ fn parse_update_with_table_alias() {
|
|||
#[test]
|
||||
fn parse_update_or() {
|
||||
let expect_or_clause = |sql: &str, expected_action: SqliteOnConflict| match verified_stmt(sql) {
|
||||
Statement::Update { or, .. } => assert_eq!(or, Some(expected_action)),
|
||||
Statement::Update(Update { or, .. }) => assert_eq!(or, Some(expected_action)),
|
||||
other => unreachable!("Expected update with or, got {:?}", other),
|
||||
};
|
||||
expect_or_clause(
|
||||
|
|
@ -4846,9 +4846,9 @@ fn test_alter_table_with_on_cluster() {
|
|||
match all_dialects()
|
||||
.verified_stmt("ALTER TABLE t ON CLUSTER 'cluster' ADD CONSTRAINT bar PRIMARY KEY (baz)")
|
||||
{
|
||||
Statement::AlterTable {
|
||||
Statement::AlterTable(AlterTable {
|
||||
name, on_cluster, ..
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(name.to_string(), "t");
|
||||
assert_eq!(on_cluster, Some(Ident::with_quote('\'', "cluster")));
|
||||
}
|
||||
|
|
@ -4858,9 +4858,9 @@ fn test_alter_table_with_on_cluster() {
|
|||
match all_dialects()
|
||||
.verified_stmt("ALTER TABLE t ON CLUSTER cluster_name ADD CONSTRAINT bar PRIMARY KEY (baz)")
|
||||
{
|
||||
Statement::AlterTable {
|
||||
Statement::AlterTable(AlterTable {
|
||||
name, on_cluster, ..
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(name.to_string(), "t");
|
||||
assert_eq!(on_cluster, Some(Ident::new("cluster_name")));
|
||||
}
|
||||
|
|
@ -7615,7 +7615,7 @@ fn parse_ctes() {
|
|||
// CTE in a view
|
||||
let sql = &format!("CREATE VIEW v AS {with}");
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView { query, .. } => assert_ctes_in_select(&cte_sqls, &query),
|
||||
Statement::CreateView(create_view) => assert_ctes_in_select(&cte_sqls, &create_view.query),
|
||||
_ => panic!("Expected: CREATE VIEW"),
|
||||
}
|
||||
// CTE in a CTE...
|
||||
|
|
@ -8103,7 +8103,7 @@ fn parse_drop_database_if_exists() {
|
|||
fn parse_create_view() {
|
||||
let sql = "CREATE VIEW myschema.myview AS SELECT foo FROM bar";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
Statement::CreateView(CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
columns,
|
||||
|
|
@ -8120,7 +8120,7 @@ fn parse_create_view() {
|
|||
params,
|
||||
name_before_not_exists: _,
|
||||
secure: _,
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(or_alter, false);
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
|
|
@ -8146,7 +8146,7 @@ fn parse_create_view() {
|
|||
fn parse_create_view_with_options() {
|
||||
let sql = "CREATE VIEW v WITH (foo = 'bar', a = 123) AS SELECT 1";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView { options, .. } => {
|
||||
Statement::CreateView(create_view) => {
|
||||
assert_eq!(
|
||||
CreateTableOptions::With(vec![
|
||||
SqlOption::KeyValue {
|
||||
|
|
@ -8160,7 +8160,7 @@ fn parse_create_view_with_options() {
|
|||
value: Expr::value(number("123")),
|
||||
},
|
||||
]),
|
||||
options
|
||||
create_view.options
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
|
@ -8173,24 +8173,21 @@ fn parse_create_view_with_columns() {
|
|||
// TODO: why does this fail for ClickHouseDialect? (#1449)
|
||||
// match all_dialects().verified_stmt(sql) {
|
||||
match all_dialects_except(|d| d.is::<ClickHouseDialect>()).verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
columns,
|
||||
or_replace,
|
||||
options,
|
||||
query,
|
||||
materialized,
|
||||
cluster_by,
|
||||
comment,
|
||||
with_no_schema_binding: late_binding,
|
||||
if_not_exists,
|
||||
temporary,
|
||||
to,
|
||||
params,
|
||||
name_before_not_exists: _,
|
||||
secure: _,
|
||||
} => {
|
||||
Statement::CreateView(create_view) => {
|
||||
let or_alter = create_view.or_alter;
|
||||
let name = create_view.name;
|
||||
let columns = create_view.columns;
|
||||
let or_replace = create_view.or_replace;
|
||||
let options = create_view.options;
|
||||
let query = create_view.query;
|
||||
let materialized = create_view.materialized;
|
||||
let cluster_by = create_view.cluster_by;
|
||||
let comment = create_view.comment;
|
||||
let late_binding = create_view.with_no_schema_binding;
|
||||
let if_not_exists = create_view.if_not_exists;
|
||||
let temporary = create_view.temporary;
|
||||
let to = create_view.to;
|
||||
let params = create_view.params;
|
||||
assert_eq!(or_alter, false);
|
||||
assert_eq!("v", name.to_string());
|
||||
assert_eq!(
|
||||
|
|
@ -8224,7 +8221,7 @@ fn parse_create_view_with_columns() {
|
|||
fn parse_create_view_temporary() {
|
||||
let sql = "CREATE TEMPORARY VIEW myschema.myview AS SELECT foo FROM bar";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
Statement::CreateView(CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
columns,
|
||||
|
|
@ -8241,7 +8238,7 @@ fn parse_create_view_temporary() {
|
|||
params,
|
||||
name_before_not_exists: _,
|
||||
secure: _,
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(or_alter, false);
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
|
|
@ -8265,7 +8262,7 @@ fn parse_create_view_temporary() {
|
|||
fn parse_create_or_replace_view() {
|
||||
let sql = "CREATE OR REPLACE VIEW v AS SELECT 1";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
Statement::CreateView(CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
columns,
|
||||
|
|
@ -8282,7 +8279,7 @@ fn parse_create_or_replace_view() {
|
|||
params,
|
||||
name_before_not_exists: _,
|
||||
secure: _,
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(or_alter, false);
|
||||
assert_eq!("v", name.to_string());
|
||||
assert_eq!(columns, vec![]);
|
||||
|
|
@ -8310,7 +8307,7 @@ fn parse_create_or_replace_materialized_view() {
|
|||
// https://docs.snowflake.com/en/sql-reference/sql/create-materialized-view.html
|
||||
let sql = "CREATE OR REPLACE MATERIALIZED VIEW v AS SELECT 1";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
Statement::CreateView(CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
columns,
|
||||
|
|
@ -8327,7 +8324,7 @@ fn parse_create_or_replace_materialized_view() {
|
|||
params,
|
||||
name_before_not_exists: _,
|
||||
secure: _,
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(or_alter, false);
|
||||
assert_eq!("v", name.to_string());
|
||||
assert_eq!(columns, vec![]);
|
||||
|
|
@ -8351,7 +8348,7 @@ fn parse_create_or_replace_materialized_view() {
|
|||
fn parse_create_materialized_view() {
|
||||
let sql = "CREATE MATERIALIZED VIEW myschema.myview AS SELECT foo FROM bar";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
Statement::CreateView(CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
or_replace,
|
||||
|
|
@ -8368,7 +8365,7 @@ fn parse_create_materialized_view() {
|
|||
params,
|
||||
name_before_not_exists: _,
|
||||
secure: _,
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(or_alter, false);
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
|
|
@ -8392,7 +8389,7 @@ fn parse_create_materialized_view() {
|
|||
fn parse_create_materialized_view_with_cluster_by() {
|
||||
let sql = "CREATE MATERIALIZED VIEW myschema.myview CLUSTER BY (foo) AS SELECT foo FROM bar";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateView {
|
||||
Statement::CreateView(CreateView {
|
||||
or_alter,
|
||||
name,
|
||||
or_replace,
|
||||
|
|
@ -8409,7 +8406,7 @@ fn parse_create_materialized_view_with_cluster_by() {
|
|||
params,
|
||||
name_before_not_exists: _,
|
||||
secure: _,
|
||||
} => {
|
||||
}) => {
|
||||
assert_eq!(or_alter, false);
|
||||
assert_eq!("myschema.myview", name.to_string());
|
||||
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
|
||||
|
|
@ -9417,21 +9414,17 @@ fn parse_drop_index() {
|
|||
fn parse_create_role() {
|
||||
let sql = "CREATE ROLE consultant";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateRole { names, .. } => {
|
||||
assert_eq_vec(&["consultant"], &names);
|
||||
Statement::CreateRole(create_role) => {
|
||||
assert_eq_vec(&["consultant"], &create_role.names);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let sql = "CREATE ROLE IF NOT EXISTS mysql_a, mysql_b";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateRole {
|
||||
names,
|
||||
if_not_exists,
|
||||
..
|
||||
} => {
|
||||
assert_eq_vec(&["mysql_a", "mysql_b"], &names);
|
||||
assert!(if_not_exists);
|
||||
Statement::CreateRole(create_role) => {
|
||||
assert_eq_vec(&["mysql_a", "mysql_b"], &create_role.names);
|
||||
assert!(create_role.if_not_exists);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
@ -13351,8 +13344,8 @@ fn test_extract_seconds_single_quote_err() {
|
|||
fn test_truncate_table_with_on_cluster() {
|
||||
let sql = "TRUNCATE TABLE t ON CLUSTER cluster_name";
|
||||
match all_dialects().verified_stmt(sql) {
|
||||
Statement::Truncate { on_cluster, .. } => {
|
||||
assert_eq!(on_cluster, Some(Ident::new("cluster_name")));
|
||||
Statement::Truncate(truncate) => {
|
||||
assert_eq!(truncate.on_cluster, Some(Ident::new("cluster_name")));
|
||||
}
|
||||
_ => panic!("Expected: TRUNCATE TABLE statement"),
|
||||
}
|
||||
|
|
@ -16407,14 +16400,14 @@ fn parse_truncate_only() {
|
|||
];
|
||||
|
||||
assert_eq!(
|
||||
Statement::Truncate {
|
||||
Statement::Truncate(Truncate {
|
||||
table_names,
|
||||
partitions: None,
|
||||
table: true,
|
||||
identity: None,
|
||||
cascade: None,
|
||||
on_cluster: None,
|
||||
},
|
||||
}),
|
||||
truncate
|
||||
);
|
||||
}
|
||||
|
|
@ -17288,9 +17281,9 @@ fn parse_invisible_column() {
|
|||
let sql = r#"ALTER TABLE t ADD COLUMN bar INT INVISIBLE"#;
|
||||
let stmt = verified_stmt(sql);
|
||||
match stmt {
|
||||
Statement::AlterTable { operations, .. } => {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!(
|
||||
operations,
|
||||
alter_table.operations,
|
||||
vec![AlterTableOperation::AddColumn {
|
||||
column_keyword: true,
|
||||
if_not_exists: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue