Skip to content

Commit

Permalink
Support parsing Oracle CREATE PROFILE SQL (#28962)
Browse files Browse the repository at this point in the history
* Support Oracle CREATE PROFILE SQL

* resolve conflict and format code
  • Loading branch information
chakkk309 authored Nov 7, 2023
1 parent 85c20ce commit 362c929
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4140,3 +4140,8 @@ switchClause
datafileSpecClause
: SQ_ fileName SQ_ | INTEGER_
;

createProfile
: CREATE MANDATORY? PROFILE profileName LIMIT (resourceParameters | passwordParameters)+ (CONTAINER EQ_ (CURRENT | ALL))?
;

Original file line number Diff line number Diff line change
Expand Up @@ -7743,3 +7743,7 @@ PERSISTABLE
DB_RECOVERY_FILE_DEST_SIZE
: D B UL_ R E C O V E R Y UL_ F I L E UL_ D E S T UL_ S I Z E
;

MANDATORY
: M A N D A T O R Y
;
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@ execute
| plsqlBlock
| createLibrary
| switch
| createProfile
) SEMI_?
;
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewLogContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreatePFileContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateProcedureContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateProfileContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateRestorePointContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateRollbackSegmentContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateSPFileContext;
Expand Down Expand Up @@ -258,6 +259,7 @@
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateObjectTypeStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreatePFileStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateProcedureStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateProfileStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateRestorePointStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateRollbackSegmentStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateSPFileStatement;
Expand Down Expand Up @@ -1357,4 +1359,8 @@ public ASTNode visitSwitch(final SwitchContext ctx) {
return new OracleSwitchStatement();
}

@Override
public ASTNode visitCreateProfile(final CreateProfileContext ctx) {
return new OracleCreateProfileStatement();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,9 @@ public enum SQLVisitorRule {

CREATE_LIBRARY("CreateLibrary", SQLStatementType.DDL),

SWITCH("Switch", SQLStatementType.DDL);
SWITCH("Switch", SQLStatementType.DDL),

CREATE_PROFILE("CreateProfile", SQLStatementType.DDL);

private final String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -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.AbstractSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;

/**
* Oracle create profile statement.
*/
public final class OracleCreateProfileStatement extends AbstractSQLStatement implements OracleStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreatePFileStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreatePolicyStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateProcedureStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateProfileStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreatePublicationStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateRestorePointStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateRollbackSegmentStatementTestCase;
Expand Down Expand Up @@ -1724,6 +1725,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "switch")
private final List<SwitchStatementTestCase> switchStatementTestCases = new LinkedList<>();

@XmlElement(name = "create-profile")
private final List<CreateProfileStatementTestCase> createProfileStatementTestCases = new LinkedList<>();

/**
* Get all SQL parser test cases.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl;

import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;

/**
* Create profile statement test case.
*/
public final class CreateProfileStatementTestCase extends SQLParserTestCase {
}
22 changes: 22 additions & 0 deletions test/it/parser/src/main/resources/case/ddl/create-profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<sql-parser-test-cases>
<create-profile sql-case-id="create_mandatory_profile" />
<create-profile sql-case-id="create_limit_profile" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<sql-cases>
<sql-case id="create_mandatory_profile" value="CREATE MANDATORY PROFILE c##cdb_profile LIMIT PASSWORD_VERIFY_FUNCTION my_mandatory_function
CONTAINER = ALL;" db-types="Oracle" />
<sql-case id="create_limit_profile" value="CREATE PROFILE prof LIMIT
FAILED_LOGIN_ATTEMPTS 4
PASSWORD_LOCK_TIME 30
PASSWORD_LIFE_TIME 180;" db-types="Oracle" />
</sql-cases>

0 comments on commit 362c929

Please sign in to comment.