Encapsulate CreateTable, CreateIndex into specific structs (#1291)

This commit is contained in:
Philip Cristiano 2024-06-05 05:25:42 -04:00 committed by GitHub
parent f3f5de51e5
commit a0f511cb21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 387 additions and 400 deletions

View file

@ -354,7 +354,7 @@ fn parse_create_view_with_unquoted_hyphen() {
fn parse_create_table_with_unquoted_hyphen() {
let sql = "CREATE TABLE my-pro-ject.mydataset.mytable (x INT64)";
match bigquery().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(
name,
ObjectName(vec![
@ -388,14 +388,14 @@ fn parse_create_table_with_options() {
r#"OPTIONS(partition_expiration_days = 1, description = "table option description")"#
);
match bigquery().verified_stmt(sql) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
partition_by,
cluster_by,
options,
..
} => {
}) => {
assert_eq!(
name,
ObjectName(vec!["mydataset".into(), "newtable".into()])
@ -477,7 +477,7 @@ fn parse_create_table_with_options() {
fn parse_nested_data_types() {
let sql = "CREATE TABLE table (x STRUCT<a ARRAY<INT64>, b BYTES(42)>, y ARRAY<STRUCT<INT64>>)";
match bigquery_and_generic().one_statement_parses_to(sql, sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name, ObjectName(vec!["table".into()]));
assert_eq!(
columns,

View file

@ -2747,7 +2747,7 @@ fn parse_create_table() {
FOREIGN KEY (lng) REFERENCES othertable4(longitude) ON UPDATE SET NULL)",
);
match ast {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
@ -2757,7 +2757,7 @@ fn parse_create_table() {
file_format: None,
location: None,
..
} => {
}) => {
assert_eq!("uk_cities", name.to_string());
assert_eq!(
columns,
@ -2936,7 +2936,7 @@ fn parse_create_table_with_constraint_characteristics() {
FOREIGN KEY (lng) REFERENCES othertable4(longitude) ON UPDATE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE ENFORCED)",
);
match ast {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
@ -2946,7 +2946,7 @@ fn parse_create_table_with_constraint_characteristics() {
file_format: None,
location: None,
..
} => {
}) => {
assert_eq!("uk_cities", name.to_string());
assert_eq!(
columns,
@ -3104,7 +3104,7 @@ fn parse_create_table_column_constraint_characteristics() {
};
match ast {
Statement::CreateTable { columns, .. } => {
Statement::CreateTable(CreateTable { columns, .. }) => {
assert_eq!(
columns,
vec![ColumnDef {
@ -3214,12 +3214,12 @@ fn parse_create_table_hive_array() {
};
match dialects.one_statement_parses_to(sql.as_str(), sql.as_str()) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
if_not_exists,
name,
columns,
..
} => {
}) => {
assert!(if_not_exists);
assert_eq!(name, ObjectName(vec!["something".into()]));
assert_eq!(
@ -3373,7 +3373,7 @@ fn parse_create_table_as() {
let sql = "CREATE TABLE t AS SELECT * FROM a";
match verified_stmt(sql) {
Statement::CreateTable { name, query, .. } => {
Statement::CreateTable(CreateTable { name, query, .. }) => {
assert_eq!(name.to_string(), "t".to_string());
assert_eq!(query, Some(Box::new(verified_query("SELECT * FROM a"))));
}
@ -3385,7 +3385,7 @@ fn parse_create_table_as() {
// (without data types) in a CTAS, but we have yet to support that.
let sql = "CREATE TABLE t (a INT, b INT) AS SELECT 1 AS b, 2 AS a";
match verified_stmt(sql) {
Statement::CreateTable { columns, query, .. } => {
Statement::CreateTable(CreateTable { columns, query, .. }) => {
assert_eq!(columns.len(), 2);
assert_eq!(columns[0].to_string(), "a INT".to_string());
assert_eq!(columns[1].to_string(), "b INT".to_string());
@ -3418,7 +3418,7 @@ fn parse_create_table_as_table() {
});
match verified_stmt(sql1) {
Statement::CreateTable { query, name, .. } => {
Statement::CreateTable(CreateTable { query, name, .. }) => {
assert_eq!(name, ObjectName(vec![Ident::new("new_table")]));
assert_eq!(query.unwrap(), expected_query1);
}
@ -3443,7 +3443,7 @@ fn parse_create_table_as_table() {
});
match verified_stmt(sql2) {
Statement::CreateTable { query, name, .. } => {
Statement::CreateTable(CreateTable { query, name, .. }) => {
assert_eq!(name, ObjectName(vec![Ident::new("new_table")]));
assert_eq!(query.unwrap(), expected_query2);
}
@ -3456,7 +3456,7 @@ fn parse_create_table_on_cluster() {
// Using single-quote literal to define current cluster
let sql = "CREATE TABLE t ON CLUSTER '{cluster}' (a INT, b INT)";
match verified_stmt(sql) {
Statement::CreateTable { on_cluster, .. } => {
Statement::CreateTable(CreateTable { on_cluster, .. }) => {
assert_eq!(on_cluster.unwrap(), "{cluster}".to_string());
}
_ => unreachable!(),
@ -3465,7 +3465,7 @@ fn parse_create_table_on_cluster() {
// Using explicitly declared cluster name
let sql = "CREATE TABLE t ON CLUSTER my_cluster (a INT, b INT)";
match verified_stmt(sql) {
Statement::CreateTable { on_cluster, .. } => {
Statement::CreateTable(CreateTable { on_cluster, .. }) => {
assert_eq!(on_cluster.unwrap(), "my_cluster".to_string());
}
_ => unreachable!(),
@ -3477,9 +3477,9 @@ fn parse_create_or_replace_table() {
let sql = "CREATE OR REPLACE TABLE t (a INT)";
match verified_stmt(sql) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name, or_replace, ..
} => {
}) => {
assert_eq!(name.to_string(), "t".to_string());
assert!(or_replace);
}
@ -3488,7 +3488,7 @@ fn parse_create_or_replace_table() {
let sql = "CREATE TABLE t (a INT, b INT) AS SELECT 1 AS b, 2 AS a";
match verified_stmt(sql) {
Statement::CreateTable { columns, query, .. } => {
Statement::CreateTable(CreateTable { columns, query, .. }) => {
assert_eq!(columns.len(), 2);
assert_eq!(columns[0].to_string(), "a INT".to_string());
assert_eq!(columns[1].to_string(), "b INT".to_string());
@ -3519,7 +3519,7 @@ fn parse_create_table_with_on_delete_on_update_2in_any_order() -> Result<(), Par
fn parse_create_table_with_options() {
let sql = "CREATE TABLE t (c INT) WITH (foo = 'bar', a = 123)";
match verified_stmt(sql) {
Statement::CreateTable { with_options, .. } => {
Statement::CreateTable(CreateTable { with_options, .. }) => {
assert_eq!(
vec![
SqlOption {
@ -3542,7 +3542,7 @@ fn parse_create_table_with_options() {
fn parse_create_table_clone() {
let sql = "CREATE OR REPLACE TABLE a CLONE a_tmp";
match verified_stmt(sql) {
Statement::CreateTable { name, clone, .. } => {
Statement::CreateTable(CreateTable { name, clone, .. }) => {
assert_eq!(ObjectName(vec![Ident::new("a")]), name);
assert_eq!(Some(ObjectName(vec![(Ident::new("a_tmp"))])), clone)
}
@ -3572,7 +3572,7 @@ fn parse_create_external_table() {
STORED AS TEXTFILE LOCATION '/tmp/example.csv'",
);
match ast {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
@ -3582,7 +3582,7 @@ fn parse_create_external_table() {
file_format,
location,
..
} => {
}) => {
assert_eq!("uk_cities", name.to_string());
assert_eq!(
columns,
@ -3643,7 +3643,7 @@ fn parse_create_or_replace_external_table() {
STORED AS TEXTFILE LOCATION '/tmp/example.csv'",
);
match ast {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
@ -3654,7 +3654,7 @@ fn parse_create_or_replace_external_table() {
location,
or_replace,
..
} => {
}) => {
assert_eq!("uk_cities", name.to_string());
assert_eq!(
columns,
@ -3700,7 +3700,7 @@ fn parse_create_external_table_lowercase() {
lng DOUBLE) \
STORED AS PARQUET LOCATION '/tmp/example.csv'",
);
assert_matches!(ast, Statement::CreateTable { .. });
assert_matches!(ast, Statement::CreateTable(CreateTable { .. }));
}
#[test]
@ -7210,14 +7210,14 @@ fn parse_create_index() {
},
];
match verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(name),
table_name,
columns,
unique,
if_not_exists,
..
} => {
}) => {
assert_eq!("idx_name", name.to_string());
assert_eq!("test", table_name.to_string());
assert_eq!(indexed_columns, columns);
@ -7244,7 +7244,7 @@ fn test_create_index_with_using_function() {
},
];
match verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(name),
table_name,
using,
@ -7255,7 +7255,7 @@ fn test_create_index_with_using_function() {
include,
nulls_distinct: None,
predicate: None,
} => {
}) => {
assert_eq!("idx_name", name.to_string());
assert_eq!("test", table_name.to_string());
assert_eq!("btree", using.unwrap().to_string());

View file

@ -470,7 +470,7 @@ fn parse_set_variables() {
fn parse_create_table_auto_increment() {
let sql = "CREATE TABLE foo (bar INT PRIMARY KEY AUTO_INCREMENT)";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
@ -541,12 +541,12 @@ fn parse_create_table_primary_and_unique_key() {
for (sql, index_type_display) in sqls.iter().zip(index_type_display) {
match mysql().one_statement_parses_to(sql, "") {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
..
} => {
}) => {
assert_eq!(name.to_string(), "foo");
let expected_constraint = table_constraint_unique_primary_ctor(
@ -609,9 +609,9 @@ fn parse_create_table_primary_and_unique_key_with_index_options() {
for (sql, index_type_display) in sqls.iter().zip(index_type_display) {
match mysql_and_generic().one_statement_parses_to(sql, "") {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name, constraints, ..
} => {
}) => {
assert_eq!(name.to_string(), "foo");
let expected_constraint = table_constraint_unique_primary_ctor(
@ -647,9 +647,9 @@ fn parse_create_table_primary_and_unique_key_with_index_type() {
for (sql, index_type_display) in sqls.iter().zip(index_type_display) {
match mysql_and_generic().one_statement_parses_to(sql, "") {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name, constraints, ..
} => {
}) => {
assert_eq!(name.to_string(), "foo");
let expected_constraint = table_constraint_unique_primary_ctor(
@ -690,7 +690,7 @@ fn parse_create_table_comment() {
for sql in [canonical, with_equal] {
match mysql().one_statement_parses_to(sql, canonical) {
Statement::CreateTable { name, comment, .. } => {
Statement::CreateTable(CreateTable { name, comment, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(comment.expect("Should exist").to_string(), "baz");
}
@ -708,11 +708,11 @@ fn parse_create_table_auto_increment_offset() {
for sql in [canonical, with_equal] {
match mysql().one_statement_parses_to(sql, canonical) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
auto_increment_offset,
..
} => {
}) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
auto_increment_offset.expect("Should exist").to_string(),
@ -728,7 +728,7 @@ fn parse_create_table_auto_increment_offset() {
fn parse_create_table_set_enum() {
let sql = "CREATE TABLE foo (bar SET('a', 'b'), baz ENUM('a', 'b'))";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![
@ -756,13 +756,13 @@ fn parse_create_table_set_enum() {
fn parse_create_table_engine_default_charset() {
let sql = "CREATE TABLE foo (id INT(11)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3";
match mysql().verified_stmt(sql) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
engine,
default_charset,
..
} => {
}) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
@ -784,12 +784,12 @@ fn parse_create_table_engine_default_charset() {
fn parse_create_table_collate() {
let sql = "CREATE TABLE foo (id INT(11)) COLLATE=utf8mb4_0900_ai_ci";
match mysql().verified_stmt(sql) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
collation,
..
} => {
}) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
@ -810,7 +810,7 @@ fn parse_create_table_collate() {
fn parse_create_table_comment_character_set() {
let sql = "CREATE TABLE foo (s TEXT CHARACTER SET utf8mb4 COMMENT 'comment')";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
@ -857,7 +857,7 @@ fn parse_create_table_gencol() {
fn parse_quote_identifiers() {
let sql = "CREATE TABLE `PRIMARY` (`BEGIN` INT PRIMARY KEY)";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "`PRIMARY`");
assert_eq!(
vec![ColumnDef {
@ -1126,7 +1126,7 @@ fn check_roundtrip_of_escaped_string() {
fn parse_create_table_with_minimum_display_width() {
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3), bar_smallint SMALLINT(5), bar_mediumint MEDIUMINT(6), bar_int INT(11), bar_bigint BIGINT(20))";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![
@ -1172,7 +1172,7 @@ fn parse_create_table_with_minimum_display_width() {
fn parse_create_table_unsigned() {
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3) UNSIGNED, bar_smallint SMALLINT(5) UNSIGNED, bar_mediumint MEDIUMINT(13) UNSIGNED, bar_int INT(11) UNSIGNED, bar_bigint BIGINT(20) UNSIGNED)";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![
@ -2321,7 +2321,7 @@ fn parse_kill() {
fn parse_table_colum_option_on_update() {
let sql1 = "CREATE TABLE foo (`modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP())";
match mysql().verified_stmt(sql1) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
@ -2622,7 +2622,7 @@ fn parse_create_table_with_column_collate() {
let sql = "CREATE TABLE tb (id TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci)";
let canonical = "CREATE TABLE tb (id TEXT COLLATE utf8mb4_0900_ai_ci CHARACTER SET utf8mb4)";
match mysql().one_statement_parses_to(sql, canonical) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "tb");
assert_eq!(
vec![ColumnDef {

View file

@ -317,7 +317,7 @@ fn parse_create_table_with_defaults() {
active int NOT NULL
) WITH (fillfactor = 20, user_catalog_table = true, autovacuum_vacuum_threshold = 100)";
match pg_and_generic().one_statement_parses_to(sql, "") {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
@ -327,7 +327,7 @@ fn parse_create_table_with_defaults() {
file_format: None,
location: None,
..
} => {
}) => {
use pretty_assertions::assert_eq;
assert_eq!("public.customer", name.to_string());
assert_eq!(
@ -537,12 +537,12 @@ fn parse_create_table_constraints_only() {
let sql = "CREATE TABLE t (CONSTRAINT positive CHECK (2 > 1))";
let ast = pg_and_generic().verified_stmt(sql);
match ast {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
..
} => {
}) => {
assert_eq!("t", name.to_string());
assert!(columns.is_empty());
assert_eq!(
@ -718,11 +718,11 @@ fn parse_create_table_if_not_exists() {
let sql = "CREATE TABLE IF NOT EXISTS uk_cities ()";
let ast = pg_and_generic().verified_stmt(sql);
match ast {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
if_not_exists: true,
..
} => {
}) => {
assert_eq!("uk_cities", name.to_string());
}
_ => unreachable!(),
@ -2086,7 +2086,7 @@ fn parse_array_multi_subscript() {
fn parse_create_index() {
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2)";
match pg().verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
@ -2097,7 +2097,7 @@ fn parse_create_index() {
nulls_distinct: None,
include,
predicate: None,
} => {
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
@ -2115,7 +2115,7 @@ fn parse_create_index() {
fn parse_create_anonymous_index() {
let sql = "CREATE INDEX ON my_table(col1,col2)";
match pg().verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name,
table_name: ObjectName(table_name),
using,
@ -2126,7 +2126,7 @@ fn parse_create_anonymous_index() {
include,
nulls_distinct: None,
predicate: None,
} => {
}) => {
assert_eq!(None, name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
@ -2144,7 +2144,7 @@ fn parse_create_anonymous_index() {
fn parse_create_index_concurrently() {
let sql = "CREATE INDEX CONCURRENTLY IF NOT EXISTS my_index ON my_table(col1,col2)";
match pg().verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
@ -2155,7 +2155,7 @@ fn parse_create_index_concurrently() {
include,
nulls_distinct: None,
predicate: None,
} => {
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
@ -2173,7 +2173,7 @@ fn parse_create_index_concurrently() {
fn parse_create_index_with_predicate() {
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) WHERE col3 IS NULL";
match pg().verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
@ -2184,7 +2184,7 @@ fn parse_create_index_with_predicate() {
include,
nulls_distinct: None,
predicate: Some(_),
} => {
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
@ -2202,7 +2202,7 @@ fn parse_create_index_with_predicate() {
fn parse_create_index_with_include() {
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) INCLUDE (col3)";
match pg().verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
@ -2213,7 +2213,7 @@ fn parse_create_index_with_include() {
include,
nulls_distinct: None,
predicate: None,
} => {
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
@ -2231,7 +2231,7 @@ fn parse_create_index_with_include() {
fn parse_create_index_with_nulls_distinct() {
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) NULLS NOT DISTINCT";
match pg().verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
@ -2242,7 +2242,7 @@ fn parse_create_index_with_nulls_distinct() {
include,
nulls_distinct: Some(nulls_distinct),
predicate: None,
} => {
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
@ -2258,7 +2258,7 @@ fn parse_create_index_with_nulls_distinct() {
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) NULLS DISTINCT";
match pg().verified_stmt(sql) {
Statement::CreateIndex {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
@ -2269,7 +2269,7 @@ fn parse_create_index_with_nulls_distinct() {
include,
nulls_distinct: Some(nulls_distinct),
predicate: None,
} => {
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
@ -3704,7 +3704,7 @@ fn parse_create_table_with_alias() {
bool_col BOOL,
);";
match pg_and_generic().one_statement_parses_to(sql, "") {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
columns,
constraints,
@ -3714,7 +3714,7 @@ fn parse_create_table_with_alias() {
file_format: None,
location: None,
..
} => {
}) => {
assert_eq!("public.datatype_aliases", name.to_string());
assert_eq!(
columns,

View file

@ -33,7 +33,7 @@ use pretty_assertions::assert_eq;
fn test_snowflake_create_table() {
let sql = "CREATE TABLE _my_$table (am00unt number)";
match snowflake_and_generic().verified_stmt(sql) {
Statement::CreateTable { name, .. } => {
Statement::CreateTable(CreateTable { name, .. }) => {
assert_eq!("_my_$table", name.to_string());
}
_ => unreachable!(),
@ -44,9 +44,9 @@ fn test_snowflake_create_table() {
fn test_snowflake_create_transient_table() {
let sql = "CREATE TRANSIENT TABLE CUSTOMER (id INT, name VARCHAR(255))";
match snowflake_and_generic().verified_stmt(sql) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name, transient, ..
} => {
}) => {
assert_eq!("CUSTOMER", name.to_string());
assert!(transient)
}

View file

@ -122,11 +122,11 @@ fn pragma_eq_placeholder_style() {
fn parse_create_table_without_rowid() {
let sql = "CREATE TABLE t (a INT) WITHOUT ROWID";
match sqlite_and_generic().verified_stmt(sql) {
Statement::CreateTable {
Statement::CreateTable(CreateTable {
name,
without_rowid: true,
..
} => {
}) => {
assert_eq!("t", name.to_string());
}
_ => unreachable!(),
@ -200,7 +200,7 @@ fn double_equality_operator() {
fn parse_create_table_auto_increment() {
let sql = "CREATE TABLE foo (bar INT PRIMARY KEY AUTOINCREMENT)";
match sqlite_and_generic().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "foo");
assert_eq!(
vec![ColumnDef {
@ -234,7 +234,7 @@ fn parse_create_table_auto_increment() {
fn parse_create_sqlite_quote() {
let sql = "CREATE TABLE `PRIMARY` (\"KEY\" INT, [INDEX] INT)";
match sqlite().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
Statement::CreateTable(CreateTable { name, columns, .. }) => {
assert_eq!(name.to_string(), "`PRIMARY`");
assert_eq!(
vec![
@ -295,7 +295,7 @@ fn test_placeholder() {
#[test]
fn parse_create_table_with_strict() {
let sql = "CREATE TABLE Fruits (id TEXT NOT NULL PRIMARY KEY) STRICT";
if let Statement::CreateTable { name, strict, .. } = sqlite().verified_stmt(sql) {
if let Statement::CreateTable(CreateTable { name, strict, .. }) = sqlite().verified_stmt(sql) {
assert_eq!(name.to_string(), "Fruits");
assert!(strict);
}