Skip to content

Commit

Permalink
sql: sql parser for CREATE FUNCTION statement
Browse files Browse the repository at this point in the history
This commit added parser support for `CREATE FUNCTION` sql
statement. Scanner was extended so that it can recognize the
`BEGIN ATOMIC` context so that it doesnot return early when it
sees `;` charater which normally indicates the end of a
statement.

Release note (sql change): `CREATE FUNCTION` statement now
can be parsed by crdb, but an unimplemented error would be
thrown since the statement processing is not done yet.
  • Loading branch information
chengxiong-ruan committed Jul 6, 2022
1 parent f6d0d84 commit 527c546
Show file tree
Hide file tree
Showing 26 changed files with 1,001 additions and 107 deletions.
7 changes: 7 additions & 0 deletions docs/generated/sql/bnf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ FILES = [
"create_database_stmt",
"create_ddl_stmt",
"create_extension_stmt",
"create_func_stmt",
"create_index_stmt",
"create_inverted_index_stmt",
"create_role_stmt",
Expand Down Expand Up @@ -126,6 +127,9 @@ FILES = [
"insert_stmt",
"iso_level",
"joined_table",
"legacy_begin_stmt",
"legacy_end_stmt",
"legacy_transaction_stmt",
"like_table_option_list",
"limit_clause",
"move_cursor_stmt",
Expand Down Expand Up @@ -163,6 +167,8 @@ FILES = [
"resume_stmt",
"revoke_stmt",
"rollback_transaction",
"routine_body_stmt",
"routine_return_stmt",
"row_source_extension_stmt",
"savepoint_stmt",
"scrub_database_stmt",
Expand Down Expand Up @@ -226,6 +232,7 @@ FILES = [
"split_table_at",
"stmt",
"stmt_block",
"stmt_without_legacy_transaction",
"table_clause",
"table_constraint",
"table_ref",
Expand Down
18 changes: 0 additions & 18 deletions docs/generated/sql/bnf/begin_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
begin_stmt ::=
'BEGIN' 'TRANSACTION' 'PRIORITY' 'LOW' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'PRIORITY' 'NORMAL' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'PRIORITY' 'HIGH' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'READ' 'ONLY' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'READ' 'WRITE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'NOT' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION'
| 'BEGIN' 'PRIORITY' 'LOW' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'PRIORITY' 'NORMAL' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'PRIORITY' 'HIGH' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'READ' 'ONLY' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'READ' 'WRITE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'NOT' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN'
2 changes: 0 additions & 2 deletions docs/generated/sql/bnf/commit_transaction.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
commit_stmt ::=
'COMMIT' 'TRANSACTION'
| 'COMMIT'
| 'END' 'TRANSACTION'
| 'END'
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/create_ddl_stmt.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ create_ddl_stmt ::=
| create_type_stmt
| create_view_stmt
| create_sequence_stmt
| create_func_stmt
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/create_func_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create_func_stmt ::=
'CREATE' opt_or_replace 'FUNCTION' func_create_name '(' opt_func_arg_with_default_list ')' 'RETURNS' opt_return_set func_return_type opt_create_func_opt_list opt_routine_body
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/legacy_begin_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
legacy_begin_stmt ::=
'BEGIN' opt_transaction begin_transaction
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/legacy_end_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
legacy_end_stmt ::=
'END' opt_transaction
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/legacy_transaction_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
legacy_transaction_stmt ::=
legacy_begin_stmt
| legacy_end_stmt
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/routine_body_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
routine_body_stmt ::=
stmt_without_legacy_transaction
| routine_return_stmt
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/routine_return_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
routine_return_stmt ::=
'RETURN' a_expr
23 changes: 2 additions & 21 deletions docs/generated/sql/bnf/stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
stmt ::=
'HELPTOKEN'
| preparable_stmt
| analyze_stmt
| copy_from_stmt
| comment_stmt
| execute_stmt
| deallocate_stmt
| discard_stmt
| grant_stmt
| prepare_stmt
| revoke_stmt
| savepoint_stmt
| reassign_owned_by_stmt
| drop_owned_by_stmt
| release_stmt
| refresh_stmt
| nonpreparable_set_stmt
| transaction_stmt
| close_cursor_stmt
| declare_cursor_stmt
| fetch_cursor_stmt
| move_cursor_stmt
| stmt_without_legacy_transaction
| legacy_transaction_stmt
Loading

0 comments on commit 527c546

Please sign in to comment.