Skip to content

Commit

Permalink
feat(grammar): Support CREATE/DROP DIRECTORY
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed Mar 31, 2024
1 parent 0485465 commit ffa0f67
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"demos/02_create_temp_directory.sql": [
4
],
"demos/string_util_pkg_demo.sql": [
39
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,6 @@
"BETWEEN-Condition-4.sql": [
2
],
"BFILENAME-0.sql": [
2
],
"BITMAP_CONSTRUCT_AGG-0.sql": [
2
],
Expand Down Expand Up @@ -1286,18 +1283,6 @@
"CREATE-DIMENSION-2.sql": [
2
],
"CREATE-DIRECTORY-0.sql": [
2
],
"CREATE-DIRECTORY-1.sql": [
2
],
"CREATE-DIRECTORY-2.sql": [
2
],
"CREATE-DIRECTORY-3.sql": [
2
],
"CREATE-DISKGROUP-0.sql": [
2
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ enum class DdlGrammar : GrammarRuleKey {
PARTITION_COMPOSITE,
SUBPARTITION_BY_LIST,
SUBPARTITION_BY_HASH,
SUBPARTITION_TEMPLATE;
SUBPARTITION_TEMPLATE,
CREATE_DIRECTORY,
DROP_DIRECTORY;

companion object {
fun buildOn(b: PlSqlGrammarBuilder) {
Expand Down Expand Up @@ -614,7 +616,26 @@ enum class DdlGrammar : GrammarRuleKey {
b.optional(b.firstOf(ORDER, NOORDER))),
b.optional(SEMICOLON))

b.rule(DDL_COMMAND).define(b.firstOf(DDL_COMMENT, CREATE_TABLE, ALTER_TABLE, ALTER_PLSQL_UNIT, DROP_COMMAND, CREATE_SYNONYM, CREATE_SEQUENCE))
b.rule(CREATE_DIRECTORY).define(
CREATE, b.optional(OR, REPLACE), DIRECTORY,
b.optional(IF, NOT, EXISTS), IDENTIFIER_NAME,
b.optional(SHARING, EQUALS_OPERATOR, b.firstOf(METADATA, NONE)),
AS, CHARACTER_LITERAL,
b.optional(SEMICOLON))

b.rule(DROP_DIRECTORY).define(
DROP, DIRECTORY, b.optional(IF, EXISTS), IDENTIFIER_NAME, b.optional(SEMICOLON))

b.rule(DDL_COMMAND).define(b.firstOf(
DDL_COMMENT,
CREATE_TABLE,
ALTER_TABLE,
ALTER_PLSQL_UNIT,
CREATE_SYNONYM,
CREATE_SEQUENCE,
CREATE_DIRECTORY,
DROP_DIRECTORY,
DROP_COMMAND))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ enum class PlSqlKeyword(override val value: String, val isReserved: Boolean = fa
DENSE_RANK("dense_rank"),
DEPRECATE("deprecate"),
DETERMINISTIC("deterministic"),
DIRECTORY("directory"),
DISABLE("disable"),
DISASSOCIATE("disassociate"),
DOCUMENT("document"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Z PL/SQL Analyzer
* Copyright (C) 2015-2024 Felipe Zorzo
* mailto:felipe AT felipezorzo DOT com DOT br
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugins.plsqlopen.api.ddl

import com.felipebz.flr.tests.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.sonar.plugins.plsqlopen.api.DdlGrammar
import org.sonar.plugins.plsqlopen.api.RuleTest

class CreateDirectoryTest : RuleTest() {

@BeforeEach
fun init() {
setRootRule(DdlGrammar.CREATE_DIRECTORY)
}

@Test
fun matchesSimpleCreateDirectory() {
assertThat(p).matches("create directory foo as 'path';")
}

@Test
fun matchesSimpleCreateOrReplaceDirectory() {
assertThat(p).matches("create or replace directory foo as 'path';")
}

@Test
fun matchesCreateIfNotExistsDirectory() {
assertThat(p).matches("create directory if not exists foo as 'path';")
}

@Test
fun matchesLongCreateDirectory() {
assertThat(p).matches("create directory if not exists foo sharing = metadata as 'path';")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Z PL/SQL Analyzer
* Copyright (C) 2015-2024 Felipe Zorzo
* mailto:felipe AT felipezorzo DOT com DOT br
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugins.plsqlopen.api.ddl

import com.felipebz.flr.tests.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.sonar.plugins.plsqlopen.api.DdlGrammar
import org.sonar.plugins.plsqlopen.api.RuleTest

class DropDirectoryTest : RuleTest() {

@BeforeEach
fun init() {
setRootRule(DdlGrammar.DROP_DIRECTORY)
}

@Test
fun matchesSimpleDropDirectory() {
assertThat(p).matches("drop directory foo;")
}

@Test
fun matchesDropDirectoryIfExists() {
assertThat(p).matches("drop directory if exists foo;")
}

}

0 comments on commit ffa0f67

Please sign in to comment.