Skip to content

Commit

Permalink
Merge pull request #95 from cvng/create-table-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psteinroe authored Dec 31, 2023
2 parents 67f1ab0 + fbaf2bf commit 8a6eb32
Show file tree
Hide file tree
Showing 13 changed files with 1,725 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ fn custom_handlers(node: &Node) -> TokenStream {
tokens.push(TokenProperty::from(Token::Key));
},
protobuf::ConstrType::ConstrForeign => tokens.push(TokenProperty::from(Token::References)),
protobuf::ConstrType::ConstrUnique => tokens.push(TokenProperty::from(Token::Unique)),
_ => panic!("Unknown Constraint {:#?}", n.contype()),
};
if n.options.len() > 0 {
tokens.push(TokenProperty::from(Token::With));
}
},
"PartitionSpec" => quote! {
Expand Down Expand Up @@ -456,6 +460,29 @@ fn custom_handlers(node: &Node) -> TokenStream {
tokens.push(TokenProperty::from(Token::For));
tokens.push(TokenProperty::from(Token::Values));
}
if let Some(n) = &n.relation {
match n.relpersistence.as_str() {
// Unlogged
"u" => tokens.push(TokenProperty::from(Token::Unlogged)),
// Temporary
"t" => tokens.push(TokenProperty::from(Token::Temporary)),
_ => {},
}
if n.inh {
tokens.push(TokenProperty::from(Token::Inherits));
}
}
},
"TableLikeClause" => quote! {
tokens.push(TokenProperty::from(Token::Like));
// CREATE_TABLE_LIKE_ALL
if n.options == 0x7FFFFFFF {
tokens.push(TokenProperty::from(Token::Including));
tokens.push(TokenProperty::from(Token::All));
} else {
tokens.push(TokenProperty::from(Token::Excluding));
tokens.push(TokenProperty::from(Token::All));
}
},
"PartitionBoundSpec" => quote! {
tokens.push(TokenProperty::from(Token::From));
Expand Down
11 changes: 11 additions & 0 deletions crates/parser/tests/data/statements/valid/0043.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE UNLOGGED TABLE cities (name text, population real, altitude double, identifier smallint, postal_code int, foreign_id bigint);
/* TODO: CREATE TABLE IF NOT EXISTS distributors (name varchar(40) DEFAULT 'Luso Films', len interval hour to second(3), name varchar(40) DEFAULT 'Luso Films', did int DEFAULT nextval('distributors_serial'), stamp timestamp DEFAULT now() NOT NULL, stamptz timestamp with time zone, "time" time NOT NULL, timetz time with time zone, CONSTRAINT name_len PRIMARY KEY (name, len)); */ SELECT 1;
/* TODO: CREATE TABLE types (a real, b double precision, c numeric(2, 3), d char(4), e char(5), f varchar(6), g varchar(7)); */ SELECT 1;
/* TODO: CREATE TABLE types (a geometry(point) NOT NULL); */ SELECT 1;
CREATE TABLE tablename (colname int NOT NULL DEFAULT nextval('tablename_colname_seq'));
CREATE TABLE capitals (state char(2)) INHERITS (cities);
/* TODO: CREATE TEMPORARY TABLE temp AS SELECT c FROM t; */ SELECT 1;
/* TODO: CREATE TABLE films2 AS SELECT * FROM films; */ SELECT 1;
/* TODO: CREATE TEMPORARY TABLE films_recent ON COMMIT DROP AS SELECT * FROM films WHERE date_prod > $1; */ SELECT 1;
CREATE TABLE like_constraint_rename_cache (LIKE constraint_rename_cache INCLUDING ALL);
CREATE TABLE distributors (did int, name varchar(40), UNIQUE (name) WITH (fillfactor=70)) WITH (fillfactor=70);
412 changes: 412 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/[email protected]

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: CREATE TABLE like_constraint_rename_cache (LIKE constraint_rename_cache INCLUDING ALL);
---
Parse {
cst: SourceFile@0..87
CreateStmt@0..87
Create@0..6 "CREATE"
Whitespace@6..7 " "
Table@7..12 "TABLE"
Whitespace@12..13 " "
RangeVar@13..41
Ident@13..41 "like_constraint_renam ..."
Whitespace@41..42 " "
Ascii40@42..43 "("
TableLikeClause@43..85
Like@43..47 "LIKE"
Whitespace@47..48 " "
RangeVar@48..71
Ident@48..71 "constraint_rename_cache"
Whitespace@71..72 " "
Including@72..81 "INCLUDING"
Whitespace@81..82 " "
All@82..85 "ALL"
Ascii41@85..86 ")"
Ascii59@86..87 ";"
,
errors: [],
stmts: [
RawStmt {
stmt: CreateStmt(
CreateStmt {
relation: Some(
RangeVar {
catalogname: "",
schemaname: "",
relname: "like_constraint_rename_cache",
inh: true,
relpersistence: "p",
alias: None,
location: 13,
},
),
table_elts: [
Node {
node: Some(
TableLikeClause(
TableLikeClause {
relation: Some(
RangeVar {
catalogname: "",
schemaname: "",
relname: "constraint_rename_cache",
inh: true,
relpersistence: "p",
alias: None,
location: 48,
},
),
options: 2147483647,
relation_oid: 0,
},
),
),
},
],
inh_relations: [],
partbound: None,
partspec: None,
of_typename: None,
constraints: [],
options: [],
oncommit: OncommitNoop,
tablespacename: "",
access_method: "",
if_not_exists: false,
},
),
range: 0..86,
},
],
}
Loading

0 comments on commit 8a6eb32

Please sign in to comment.