Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor create schema statement parse logic #17703

Merged
merged 5 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,73 +27,10 @@ revoke
: REVOKE optionForClause? (privilegeClause | roleClause) (CASCADE | RESTRICT)?
;

privilegeClause
: privilegeTypes ON onObjectClause (FROM | TO) granteeList (WITH GRANT OPTION)?
;

roleClause
: privilegeList (FROM | TO) roleList (WITH ADMIN OPTION)? (GRANTED BY roleSpec)?
;

optionForClause
: (GRANT | ADMIN) OPTION FOR
;

privilegeTypes
: privilegeType columnNames? (COMMA_ privilegeType columnNames?)*
;

privilegeType
: SELECT
| INSERT
| UPDATE
| DELETE
| TRUNCATE
| REFERENCES
| TRIGGER
| CREATE
| CONNECT
| TEMPORARY
| TEMP
| EXECUTE
| USAGE
| ALL PRIVILEGES?
;

onObjectClause
: DATABASE nameList
| SCHEMA nameList
| DOMAIN anyNameList
| FUNCTION functionWithArgtypesList
| PROCEDURE functionWithArgtypesList
| ROUTINE functionWithArgtypesList
| LANGUAGE nameList
| LARGE OBJECT numericOnlyList
| TABLESPACE nameList
| TYPE anyNameList
| SEQUENCE qualifiedNameList
| TABLE? privilegeLevel
| FOREIGN DATA WRAPPER nameList
| FOREIGN SERVER nameList
| ALL TABLES IN SCHEMA nameList
| ALL SEQUENCES IN SCHEMA nameList
| ALL FUNCTIONS IN SCHEMA nameList
| ALL PROCEDURES IN SCHEMA nameList
| ALL ROUTINES IN SCHEMA nameList
;

privilegeLevel
: ASTERISK_ | ASTERISK_ DOT_ASTERISK_ | identifier DOT_ASTERISK_ | tableNames | schemaName DOT_ routineName
;

routineName
: identifier
;

numericOnlyList
: numericOnly (COMMA_ numericOnly)*
;

createUser
: CREATE USER roleSpec WITH? createOptRoleElem*
;
Expand Down Expand Up @@ -161,4 +98,3 @@ dropDroup
reassignOwned
: REASSIGN OWNED BY roleList TO roleSpec
;

Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,74 @@ schemaEltList

schemaStmt
: createTable | createIndex | createSequence | createTrigger | grant | createView
;
;

grant
: GRANT (privilegeClause | roleClause)
;

privilegeClause
: privilegeTypes ON onObjectClause (FROM | TO) granteeList (WITH GRANT OPTION)?
;

roleClause
: privilegeList (FROM | TO) roleList (WITH ADMIN OPTION)? (GRANTED BY roleSpec)?
;

privilegeTypes
: privilegeType columnNames? (COMMA_ privilegeType columnNames?)*
;

onObjectClause
: DATABASE nameList
| SCHEMA nameList
| DOMAIN anyNameList
| FUNCTION functionWithArgtypesList
| PROCEDURE functionWithArgtypesList
| ROUTINE functionWithArgtypesList
| LANGUAGE nameList
| LARGE OBJECT numericOnlyList
| TABLESPACE nameList
| TYPE anyNameList
| SEQUENCE qualifiedNameList
| TABLE? privilegeLevel
| FOREIGN DATA WRAPPER nameList
| FOREIGN SERVER nameList
| ALL TABLES IN SCHEMA nameList
| ALL SEQUENCES IN SCHEMA nameList
| ALL FUNCTIONS IN SCHEMA nameList
| ALL PROCEDURES IN SCHEMA nameList
| ALL ROUTINES IN SCHEMA nameList
;

numericOnlyList
: numericOnly (COMMA_ numericOnly)*
;

privilegeLevel
: ASTERISK_ | ASTERISK_ DOT_ASTERISK_ | identifier DOT_ASTERISK_ | tableNames | schemaName DOT_ routineName
;

routineName
: identifier
;

privilegeType
: SELECT
| INSERT
| UPDATE
| DELETE
| TRUNCATE
| REFERENCES
| TRIGGER
| CREATE
| CONNECT
| TEMPORARY
| TEMP
| EXECUTE
| USAGE
| ALL PRIVILEGES?
;

alterSchema
: ALTER SCHEMA name (RENAME TO name | OWNER TO roleSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,73 +29,10 @@ revoke
: REVOKE optionForClause? (privilegeClause | roleClause) (CASCADE | RESTRICT)?
;

privilegeClause
: privilegeTypes ON onObjectClause (FROM | TO) granteeList (WITH GRANT OPTION)?
;

roleClause
: privilegeList (FROM | TO) roleList (WITH ADMIN OPTION)? (GRANTED BY roleSpec)?
;

optionForClause
: (GRANT | ADMIN) OPTION FOR
;

privilegeTypes
: privilegeType columnNames? (COMMA_ privilegeType columnNames?)*
;

privilegeType
: SELECT
| INSERT
| UPDATE
| DELETE
| TRUNCATE
| REFERENCES
| TRIGGER
| CREATE
| CONNECT
| TEMPORARY
| TEMP
| EXECUTE
| USAGE
| ALL PRIVILEGES?
;

onObjectClause
: DATABASE nameList
| SCHEMA nameList
| DOMAIN anyNameList
| FUNCTION functionWithArgtypesList
| PROCEDURE functionWithArgtypesList
| ROUTINE functionWithArgtypesList
| LANGUAGE nameList
| LARGE OBJECT numericOnlyList
| TABLESPACE nameList
| TYPE anyNameList
| SEQUENCE qualifiedNameList
| TABLE? privilegeLevel
| FOREIGN DATA WRAPPER nameList
| FOREIGN SERVER nameList
| ALL TABLES IN SCHEMA nameList
| ALL SEQUENCES IN SCHEMA nameList
| ALL FUNCTIONS IN SCHEMA nameList
| ALL PROCEDURES IN SCHEMA nameList
| ALL ROUTINES IN SCHEMA nameList
;

privilegeLevel
: ASTERISK_ | ASTERISK_ DOT_ASTERISK_ | identifier DOT_ASTERISK_ | tableNames | schemaName DOT_ routineName
;

routineName
: identifier
;

numericOnlyList
: numericOnly (COMMA_ numericOnly)*
;

createUser
: CREATE USER roleSpec WITH? createOptRoleElem*
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,73 @@ schemaStmt
: createTable | createIndex | createSequence | createTrigger | grant | createView
;

grant
: GRANT (privilegeClause | roleClause)
;

privilegeClause
: privilegeTypes ON onObjectClause (FROM | TO) granteeList (WITH GRANT OPTION)?
;

roleClause
: privilegeList (FROM | TO) roleList (WITH ADMIN OPTION)? (GRANTED BY roleSpec)?
;

privilegeTypes
: privilegeType columnNames? (COMMA_ privilegeType columnNames?)*
;

onObjectClause
: DATABASE nameList
| SCHEMA nameList
| DOMAIN anyNameList
| FUNCTION functionWithArgtypesList
| PROCEDURE functionWithArgtypesList
| ROUTINE functionWithArgtypesList
| LANGUAGE nameList
| LARGE OBJECT numericOnlyList
| TABLESPACE nameList
| TYPE anyNameList
| SEQUENCE qualifiedNameList
| TABLE? privilegeLevel
| FOREIGN DATA WRAPPER nameList
| FOREIGN SERVER nameList
| ALL TABLES IN SCHEMA nameList
| ALL SEQUENCES IN SCHEMA nameList
| ALL FUNCTIONS IN SCHEMA nameList
| ALL PROCEDURES IN SCHEMA nameList
| ALL ROUTINES IN SCHEMA nameList
;

numericOnlyList
: numericOnly (COMMA_ numericOnly)*
;

privilegeLevel
: ASTERISK_ | ASTERISK_ DOT_ASTERISK_ | identifier DOT_ASTERISK_ | tableNames | schemaName DOT_ routineName
;

routineName
: identifier
;

privilegeType
: SELECT
| INSERT
| UPDATE
| DELETE
| TRUNCATE
| REFERENCES
| TRIGGER
| CREATE
| CONNECT
| TEMPORARY
| TEMP
| EXECUTE
| USAGE
| ALL PRIVILEGES?
;

alterSchema
: ALTER SCHEMA name (RENAME TO name | OWNER TO roleSpec)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
-->

<sql-parser-test-cases>
<create-schema sql-case-id="create_schema_grant_permissions" />
<create-schema sql-case-id="create_schema" />
<create-schema sql-case-id="create_schema_with_grant_permissions" />
<create-schema sql-case-id="create_schema_with_if_not_exists" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
-->

<sql-cases>
<sql-case id="create_schema_grant_permissions" value="CREATE SCHEMA Sprockets AUTHORIZATION Annik
<sql-case id="create_schema" value="CREATE SCHEMA test_schema" db-types="SQLServer,PostgreSQL,openGauss"/>
<sql-case id="create_schema_with_grant_permissions" value="CREATE SCHEMA test_schema AUTHORIZATION Annik
CREATE TABLE NineProngs (source int, cost int, partnumber int)
GRANT SELECT ON SCHEMA::Sprockets TO Mandar
DENY SELECT ON SCHEMA::Sprockets TO Prasanna" db-types="SQLServer" />
<sql-case id="create_schema" value="CREATE SCHEMA alt_nsp1" db-types="SQLServer,PostgreSQL,openGauss"/>
<sql-case id="create_schema_with_if_not_exists" value="CREATE SCHEMA IF NOT EXISTS test_schema" db-types="PostgreSQL"/>
</sql-cases>