Skip to content

Commit

Permalink
Support parsing Oracle CREATE LIBRARY SQL (#28920)
Browse files Browse the repository at this point in the history
* support parsing Oracle CREATE LIBRARY sql

* format code

* format code
  • Loading branch information
chakkk309 authored Nov 3, 2023
1 parent 15bfe90 commit 58b2a2a
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2098,3 +2098,19 @@ keyForBlob
sourceText
: identifier
;

fullPathName
: STRING_
;

directoryObject
: identifier
;

credentialName
: identifier
;

agentDblink
: STRING_
;
Original file line number Diff line number Diff line change
Expand Up @@ -4114,3 +4114,15 @@ fileType
| CLOB
| BLOB
;

createLibrary
: CREATE (OR REPLACE)? (EDITIONABLE | NONEDITIONABLE)? LIBRARY plsqlLibrarySource
;

plsqlLibrarySource
: libraryName sharingClause? (IS | AS) (fullPathName | (fileName IN directoryObject)) agentClause
;

agentClause
: (AGENT agentDblink)? (CREDENTIAL credentialName)?
;
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ execute
| createCluster
| createJava
| plsqlBlock
| createLibrary
) SEMI_?
;
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateIndexContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateInmemoryJoinGroupContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateJavaContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateLibraryContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateLockdownProfileContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewLogContext;
Expand Down Expand Up @@ -248,6 +249,7 @@
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateInmemoryJoinGroupStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateJavaStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateLibraryStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateLockdownProfileStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewLogStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewStatement;
Expand Down Expand Up @@ -1342,4 +1344,9 @@ public ASTNode visitAlterType(final AlterTypeContext ctx) {
public ASTNode visitCreateJava(final CreateJavaContext ctx) {
return new OracleCreateJavaStatement();
}

@Override
public ASTNode visitCreateLibrary(final CreateLibraryContext ctx) {
return new OracleCreateLibraryStatement();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,9 @@ public enum SQLVisitorRule {

CREATE_JAVA("CreateJava", SQLStatementType.DDL),

PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL);
PLSQL_BLOCK("PlsqlBlock", SQLStatementType.DDL),

CREATE_LIBRARY("CreateLibrary", 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 library statement.
*/
public final class OracleCreateLibraryStatement extends AbstractSQLStatement implements OracleStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateInmemoryJoinGroupStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateJavaStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateLanguageStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateLibraryStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateLockdownProfileStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateMaterializedViewLogStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateMaterializedViewStatementTestCase;
Expand Down Expand Up @@ -1716,6 +1717,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "create-java")
private final List<CreateJavaStatementTestCase> createJavaStatementTestCases = new LinkedList<>();

@XmlElement(name = "create-library")
private final List<CreateLibraryStatementTestCase> createLibraryStatementTestCases = 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 library statement test case.
*/
public final class CreateLibraryStatementTestCase extends SQLParserTestCase {
}
21 changes: 21 additions & 0 deletions test/it/parser/src/main/resources/case/ddl/create-library.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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-library sql-case-id="create_library" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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_library" value="CREATE LIBRARY app_lib as '${ORACLE_HOME}/lib/app_lib.so' AGENT 'sales.hq.example.com';" db-types="Oracle" />
</sql-cases>

0 comments on commit 58b2a2a

Please sign in to comment.