This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9ca766bcf1a Fix oracle parser create user error (#30394)
9ca766bcf1a is described below
commit 9ca766bcf1ab49a152576c0e1467f429ec10fee3
Author: LotusMoon <[email protected]>
AuthorDate: Wed Mar 6 09:27:44 2024 +0800
Fix oracle parser create user error (#30394)
* Fix oracle parser create user error
* Modify formatting issues
---
.../src/main/antlr4/imports/oracle/DCLStatement.g4 | 69 +++++++++++++++++++++-
.../src/main/antlr4/imports/oracle/DDLStatement.g4 | 2 +-
.../main/antlr4/imports/oracle/OracleKeyword.g4 | 8 +++
.../sql/parser/autogen/OracleStatement.g4 | 1 +
.../statement/type/OracleDDLStatementVisitor.java | 7 +++
.../oracle/ddl/OracleDropDatabaseStatement.java | 27 +++++++++
.../sql/parser/internal/InternalSQLParserIT.java | 4 +-
.../resources/sql/supported/dcl/create-user.xml | 8 +--
.../main/resources/sql/supported/dcl/drop-user.xml | 4 +-
9 files changed, 119 insertions(+), 11 deletions(-)
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DCLStatement.g4
b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DCLStatement.g4
index b1207221c08..5c3f0e03177 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DCLStatement.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DCLStatement.g4
@@ -341,7 +341,74 @@ miscellaneousSystemPrivilege
;
createUser
- : CREATE USER
+ : CREATE USER username createUserIdentifiedClause createUserOption*
+ ;
+
+createUserIdentifiedClause
+ : IDENTIFIED createUseridentifiedSegment
+ | noAuthOption
+ ;
+
+createUseridentifiedSegment
+ : BY password HTTP? DIGEST? (ENABLE | DISABLE)?
+ | identifiedExternallyOption
+ | identifiedGloballyOption
+ ;
+
+identifiedExternallyOption
+ : EXTERNALLY (AS SQ_ name SQ_)?
+ ;
+
+identifiedGloballyOption
+ : GLOBALLY (AS SQ_ (name | (AZURE_ROLE | AZURE_USER | IAM_GROUP_NAME |
IAM_PRINCIPAL_NAME) EQ_ name) SQ_)
+ ;
+
+noAuthOption
+ : NO AUTHENTICATION
+ ;
+
+createUserOption
+ : collationOption
+ | tablespaceOption
+ | temporaryOption
+ | quotaOption
+ | profileOption
+ | passwordOption
+ | accountOption
+ | ENABLE EDITIONS
+ | containerOption
+ ;
+
+collationOption
+ : DEFAULT COLLATION collationName
+ ;
+
+tablespaceOption
+ : DEFAULT TABLESPACE tablespaceName
+ ;
+
+temporaryOption
+ : LOCAL? TEMPORARY TABLESPACE tablespaceName tablespaceGroupName
+ ;
+
+quotaOption
+ : QUOTA (sizeClause | UNLIMITED) ON tablespaceName
+ ;
+
+profileOption
+ : PROFILE profileName
+ ;
+
+passwordOption
+ : PASSWORD EXPIRE
+ ;
+
+accountOption
+ : ACCOUNT (LOCK | UNLOCK)
+ ;
+
+containerOption
+ : CONTAINER EQ_ (CURRENT | ALL)
;
dropUser
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
index ab58b165672..f94075da8d6 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/DDLStatement.g4
@@ -142,7 +142,7 @@ dropTrigger
;
dropIndex
- : DROP INDEX indexName ONLINE? FORCE? invalidationSpecification?
+ : DROP INDEX indexName ONLINE? FORCE? invalidationSpecification? (ON
tableName)?
;
dropView
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
index a6a1e8d234d..494c5e7d611 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/OracleKeyword.g4
@@ -3096,10 +3096,18 @@ AZURE_ROLE
: A Z U R E UL_ R O L E
;
+AZURE_USER
+ : A Z U R E UL_ U S E R
+ ;
+
IAM_GROUP_NAME
: I A M UL_ G R O U P UL_ N A M E
;
+IAM_PRINCIPAL_NAME
+ : I A M UL_ P R I N C I P A L UL_ N A M E
+ ;
+
LOGICAL_READS_PER_SESSION
: L O G I C A L UL_ R E A D S UL_ P E R UL_ S E S S I O N
;
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
index a03adcd9d43..c27ea823d56 100644
---
a/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
+++
b/parser/sql/dialect/oracle/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OracleStatement.g4
@@ -85,6 +85,7 @@ execute
| dropEdition
| dropTableSpace
| dropOutline
+ | dropDatabase
| alterOutline
| alterAnalyticView
| alterAttributeDimension
diff --git
a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java
b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java
index a6d92b4d3ea..ca47eda76c0 100644
---
a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java
+++
b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java
@@ -192,6 +192,7 @@ import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.Trunca
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TypeNameContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.VariableNameContext;
import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.VarrayTypeSpecContext;
+import
org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropDatabaseContext;
import
org.apache.shardingsphere.sql.parser.oracle.visitor.statement.OracleStatementVisitor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment;
@@ -342,6 +343,7 @@ import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.Ora
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleSwitchStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleSystemActionStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleTruncateStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropDatabaseStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleSelectStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.plsql.CursorForLoopStatementSegment;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.plsql.ProcedureBodyEndNameSegment;
@@ -1753,4 +1755,9 @@ public final class OracleDDLStatementVisitor extends
OracleStatementVisitor impl
public ASTNode visitCreateProfile(final CreateProfileContext ctx) {
return new OracleCreateProfileStatement();
}
+
+ @Override
+ public ASTNode visitDropDatabase(final DropDatabaseContext ctx) {
+ return new OracleDropDatabaseStatement();
+ }
}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleDropDatabaseStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleDropDatabaseStatement.java
new file mode 100644
index 00000000000..c7f62ebbbe5
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/oracle/ddl/OracleDropDatabaseStatement.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropDatabaseStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
+
+/**
+ * Oracle drop database statement.
+ */
+public final class OracleDropDatabaseStatement extends DropDatabaseStatement
implements OracleStatement {
+}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java
index 77f26a704ab..157c947adaf 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java
@@ -58,9 +58,7 @@ public abstract class InternalSQLParserIT {
"create_materialized_view_log_with_pctfree_storage_purge_repeat",
"create_materialized_view_log_with_row_id_sequence_including_new",
"create_materialized_view_log_with_tablespace",
"create_no_identified_role", "create_role",
"create_role_identified_by", "create_role_with_container",
"create_role_with_identified_by_password",
"create_table_with_out_of_line_constraints_oracle",
"create_table_with_xmltype_column_clob_oracle",
"create_table_with_xmltype_column_oracle", "create_tablespace_with_blocksize",
- "create_tablespace_with_temporary_tablespace_group",
"create_tablespace_with_temporary_tempfile_spec_extent_management",
"create_tablespace_with_undo_tablespace_spec",
- "create_user_identified_by_without_hostname",
"create_user_with_lock_option", "create_user_with_password",
"create_user_with_password_expire_lock", "create_user_with_password_option",
- "create_user_with_quota_option", "create_user_with_tablespace",
"drop_database_including_backups_noprompt", "drop_index_with_quota",
"drop_user_with_hostname", "drop_user_with_ip"));
+ "create_tablespace_with_temporary_tablespace_group",
"create_tablespace_with_temporary_tempfile_spec_extent_management",
"create_tablespace_with_undo_tablespace_spec"));
// CHECKSTYLE:ON
@ParameterizedTest(name = "{0} ({1}) -> {2}")
diff --git
a/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml
b/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml
index eb726f5097c..d61ce444e6d 100644
--- a/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dcl/create-user.xml
@@ -31,16 +31,16 @@
<sql-case id="create_user_with_password_default_role" value="CREATE USER
user1 IDENTIFIED BY RANDOM password DEFAULT ROLE role1" db-types="MySQL" />
<sql-case id="create_user_with_resource_option" value="CREATE USER user1
DEFAULT ROLE role1 WITH MAX_QUERIES_PER_HOUR 1" db-types="MySQL" />
<sql-case id="create_user_with_resource_options" value="CREATE USER user1
DEFAULT ROLE role1 WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 1"
db-types="MySQL" />
- <sql-case id="create_user_with_password_option" value="CREATE USER user1
DEFAULT ROLE role1 PASSWORD EXPIRE DEFAULT" db-types="MySQL,Oracle" />
+ <sql-case id="create_user_with_password_option" value="CREATE USER user1
DEFAULT ROLE role1 PASSWORD EXPIRE DEFAULT" db-types="MySQL" />
<sql-case id="create_user_with_password_options" value="CREATE USER user1
DEFAULT ROLE role1 PASSWORD EXPIRE DEFAULT PASSWORD HISTORY DEFAULT"
db-types="MySQL" />
- <sql-case id="create_user_with_lock_option" value="CREATE USER user1
DEFAULT ROLE role1 ACCOUNT LOCK" db-types="MySQL,Oracle" />
+ <sql-case id="create_user_with_lock_option" value="CREATE USER user1
DEFAULT ROLE role1 ACCOUNT LOCK" db-types="MySQL" />
<sql-case id="create_user_with_options" value="CREATE USER user1 DEFAULT
ROLE role1 WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 1 PASSWORD EXPIRE
DEFAULT PASSWORD HISTORY DEFAULT ACCOUNT LOCK" db-types="MySQL" />
<sql-case id="create_external_user" value="CREATE USER user1 IDENTIFIED
EXTERNALLY" db-types="Oracle" />
<sql-case id="create_global_user" value="CREATE USER user1 IDENTIFIED
GLOBALLY" db-types="Oracle" />
- <sql-case id="create_user_with_password" value="CREATE USER user1
IDENTIFIED BY RANDOM password default role role1"
db-types="H2,MySQL,Oracle,SQLServer" />
+ <sql-case id="create_user_with_password" value="CREATE USER user1
IDENTIFIED BY RANDOM password default role role1" db-types="H2,MySQL,SQLServer"
/>
<sql-case id="create_user_with_tablespace" value="CREATE USER user1
IDENTIFIED BY password DEFAULT TABLESPACE tablespace1" db-types="Oracle" />
<sql-case id="create_user_with_quota_option" value="CREATE USER user1
IDENTIFIED BY password QUOTA 1M ON tablespace1" db-types="Oracle" />
- <sql-case id="create_user_with_password_expire_lock" value="CREATE USER
user1 IDENTIFIED BY RANDOM password default role role1 PASSWORD EXPIRE ACCOUNT
LOCK" db-types="H2,MySQL,Oracle,SQLServer" />
+ <sql-case id="create_user_with_password_expire_lock" value="CREATE USER
user1 IDENTIFIED BY RANDOM password default role role1 PASSWORD EXPIRE ACCOUNT
LOCK" db-types="H2,MySQL,SQLServer" />
<sql-case id="create_user_only_with_name" value="CREATE USER user1"
db-types="PostgreSQL,openGauss,SQLServer" />
<sql-case id="create_user_with_password_postgresql" value="CREATE USER
user1 WITH ENCRYPTED PASSWORD 'password'" db-types="PostgreSQL,openGauss" />
<sql-case id="create_user_with_option_postgresql" value="CREATE USER user1
WITH SUPERUSER" db-types="PostgreSQL,openGauss" />
diff --git a/test/it/parser/src/main/resources/sql/supported/dcl/drop-user.xml
b/test/it/parser/src/main/resources/sql/supported/dcl/drop-user.xml
index 297a520c0d0..c46b3f8b138 100644
--- a/test/it/parser/src/main/resources/sql/supported/dcl/drop-user.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dcl/drop-user.xml
@@ -18,8 +18,8 @@
<sql-cases>
<sql-case id="drop_user_without_hostname" value="DROP USER user_dev"
db-types="Oracle,PostgreSQL,openGauss,SQLServer" />
- <sql-case id="drop_user_with_hostname" value="DROP USER
user_dev@localhost" db-types="MySQL,Oracle" />
- <sql-case id="drop_user_with_ip" value="DROP USER [email protected]"
db-types="MySQL,Oracle" />
+ <sql-case id="drop_user_with_hostname" value="DROP USER
user_dev@localhost" db-types="MySQL" />
+ <sql-case id="drop_user_with_ip" value="DROP USER [email protected]"
db-types="MySQL" />
<sql-case id="drop_user_cascade" value="DROP USER user_dev CASCADE"
db-types="Oracle,openGauss" />
<sql-case id="drop_user_restrict" value="DROP USER user_name RESTRICT"
db-types="openGauss" />
<sql-case id="drop_user" value="DROP USER user1"
db-types="MySQL,Oracle,PostgreSQL,openGauss,SQLServer" />