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 7fdbb39d0b6 Support parsing `ALTER TEXT SEARCH` in PostgreSQL (#20333)
7fdbb39d0b6 is described below

commit 7fdbb39d0b6a25982c0c84658e7e4b10433b3cba
Author: Everly Precia Suresh <[email protected]>
AuthorDate: Mon Aug 22 06:24:52 2022 +0530

    Support parsing `ALTER TEXT SEARCH` in PostgreSQL (#20333)
    
    * Support parsing ALTER TEXT SEARCH CONFIGURATION
    
    * Correct grammar + add testcases
---
 .../main/antlr4/imports/postgresql/DDLStatement.g4 |  4 ++--
 .../parser/autogen/PostgreSQLStatementParser.g4    |  1 +
 .../impl/PostgreSQLDDLStatementSQLVisitor.java     |  6 ++++++
 .../core/database/visitor/SQLVisitorRule.java      |  2 ++
 .../main/resources/case/ddl/alter-text-search.xml  |  4 ++++
 .../sql/supported/ddl/alter-text-search.xml        |  3 +++
 .../main/resources/sql/unsupported/unsupported.xml | 24 ----------------------
 7 files changed, 18 insertions(+), 26 deletions(-)

diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
index 28e804b0497..ad3cecb52b4 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
@@ -1120,11 +1120,11 @@ alterTextSearchDictionary
     ;
 
 alterTextSearchParser
-    : ALTER TEXT SEARCH PARSER (anyName RENAME TO name | SET SCHEMA name)
+    : ALTER TEXT SEARCH PARSER anyName (RENAME TO name | SET SCHEMA name)
     ;
 
 alterTextSearchTemplate
-    : ALTER TEXT SEARCH TEMPLATE (anyName RENAME TO name | SET SCHEMA name)
+    : ALTER TEXT SEARCH TEMPLATE anyName (RENAME TO name | SET SCHEMA name)
     ;
 
 alterTrigger
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
index 447fde1af9f..b69e15ff6ff 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/PostgreSQLStatementParser.g4
@@ -175,5 +175,6 @@ execute
     | alterSubscription
     | createMaterializedView
     | createOperator
+    | alterTextSearchConfiguration
     ) SEMI_? EOF
     ;
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
index 66b136f489c..e1852ba4566 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java
@@ -54,6 +54,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Al
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTableActionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTableContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTablespaceContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchConfigurationContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchDictionaryContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchParserContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTextSearchTemplateContext;
@@ -984,6 +985,11 @@ public final class PostgreSQLDDLStatementSQLVisitor 
extends PostgreSQLStatementS
         return new PostgreSQLCreateTextSearchStatement();
     }
     
+    @Override
+    public ASTNode visitAlterTextSearchConfiguration(final 
AlterTextSearchConfigurationContext ctx) {
+        return new PostgreSQLAlterTextSearchStatement();
+    }
+    
     @Override
     public ASTNode visitAlterTextSearchDictionary(final 
AlterTextSearchDictionaryContext ctx) {
         return new PostgreSQLAlterTextSearchStatement();
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
index f6cf9940163..0095921449a 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/database/visitor/SQLVisitorRule.java
@@ -512,6 +512,8 @@ public enum SQLVisitorRule {
     
     CREATE_TEXT_SEARCH("CreateTextSearch", SQLStatementType.DDL),
     
+    ALTER_TEXT_SEARCH_CONFIGURATION("AlterTextSearchConfiguration", 
SQLStatementType.DDL),
+    
     ALTER_TEXT_SEARCH_DICTIONARY("AlterTextSearchDictionary", 
SQLStatementType.DDL),
     
     ALTER_TEXT_SEARCH_TEMPLATE("AlterTextSearchTemplate", 
SQLStatementType.DDL),
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-text-search.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-text-search.xml
index 53f2f18f557..f92204532ba 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-text-search.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ddl/alter-text-search.xml
@@ -17,6 +17,10 @@
   -->
 
 <sql-parser-test-cases>
+    <alter-text-search sql-case-id="alter_text_search_configuration_rename" />
+    <alter-text-search sql-case-id="alter_text_search_configuration_owner" />
+    <alter-text-search 
sql-case-id="alter_text_search_configuration_set_schema" />
+    <alter-text-search 
sql-case-id="alter_text_search_configuration_alter_mapping" />
     <alter-text-search sql-case-id="alter_text_search_dictionary" />
     <alter-text-search sql-case-id="alter_text_search_template" />
     <alter-text-search sql-case-id="alter_text_search_parser" />
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-text-search.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-text-search.xml
index ca32deaab31..cde5ceea33a 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-text-search.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ddl/alter-text-search.xml
@@ -17,6 +17,9 @@
   -->
 
 <sql-cases>
+    <sql-case id="alter_text_search_configuration_rename" value="ALTER TEXT 
SEARCH CONFIGURATION my_config ALTER MAPPING REPLACE english WITH swedish;" 
db-types="PostgreSQL" />
+    <sql-case id="alter_text_search_configuration_owner" value="ALTER TEXT 
SEARCH CONFIGURATION my_config OWNER TO CURRENT_ROLE;" db-types="PostgreSQL" />
+    <sql-case id="alter_text_search_configuration_set_schema" value="ALTER 
TEXT SEARCH CONFIGURATION config.tmp set schema config" db-types="PostgreSQL" />
     <sql-case id="alter_text_search_dictionary" value="ALTER TEXT SEARCH 
DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict2" db-types="PostgreSQL,openGauss" 
/>
     <sql-case id="alter_text_search_template" value="ALTER TEXT SEARCH 
TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp2" db-types="PostgreSQL,openGauss" />
     <sql-case id="alter_text_search_parser" value="ALTER TEXT SEARCH PARSER 
alt_ts_prs1 RENAME TO alt_ts_prs2" db-types="PostgreSQL,openGauss" />
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
index 41e3feb247f..06b4b28ecbe 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/unsupported/unsupported.xml
@@ -3284,27 +3284,6 @@
     <sql-case id="alter_by_postgresql_source_test_case387" value="ALTER TABLE 
reloptions_test RESET (toast.autovacuum_vacuum_cost_delay);" 
db-types="PostgreSQL" />
     <sql-case id="alter_by_postgresql_source_test_case388" value="ALTER TABLE 
reloptions_test SET (autovacuum_enabled, fillfactor=32);" db-types="PostgreSQL" 
/>
     <sql-case id="alter_by_postgresql_source_test_case389" value="ALTER TABLE 
reloptions_test SET (toast.autovacuum_vacuum_cost_delay = 24);" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case390" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf2;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case391" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf3;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case392" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf4;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case393" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regress_alter_generic_user2;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case394" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regress_alter_generic_user3;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case395" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regress_alter_generic_user3;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case396" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf2 SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case397" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf2 SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case398" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf3 OWNER TO regress_alter_generic_user2;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case399" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf3 RENAME TO alt_ts_conf4;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case400" value="ALTER TEXT 
SEARCH CONFIGURATION alt_ts_conf3 SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case401" value="ALTER TEXT 
SEARCH CONFIGURATION hunspell_tst ALTER MAPPING   REPLACE hunspell WITH 
hunspell_long;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case402" value="ALTER TEXT 
SEARCH CONFIGURATION hunspell_tst ALTER MAPPING   REPLACE hunspell_long WITH 
hunspell_num;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case403" value="ALTER TEXT 
SEARCH CONFIGURATION hunspell_tst ALTER MAPPING   REPLACE ispell WITH 
hunspell;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case404" value="ALTER TEXT 
SEARCH CONFIGURATION ispell_tst ALTER MAPPING FOR         word, numword, 
asciiword, hword, numhword, asciihword, hword_part, hword_numpart, 
hword_asciipart       WITH ispell, english_stem;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case405" value="ALTER TEXT 
SEARCH CONFIGURATION synonym_tst ALTER MAPPING FOR        asciiword, 
hword_asciipart, asciihword  WITH synonym, english_stem;" db-types="PostgreSQL" 
/>
-    <sql-case id="alter_by_postgresql_source_test_case406" value="ALTER TEXT 
SEARCH CONFIGURATION thesaurus_tst ALTER MAPPING FOR      asciiword, 
hword_asciipart, asciihword  WITH synonym, thesaurus, english_stem;" 
db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case407" value="ALTER TEXT 
SEARCH PARSER alt_ts_prs2 SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case408" value="ALTER TEXT 
SEARCH PARSER alt_ts_prs2 SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case409" value="ALTER TEXT 
SEARCH TEMPLATE alt_ts_temp2 SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
-    <sql-case id="alter_by_postgresql_source_test_case410" value="ALTER TEXT 
SEARCH TEMPLATE alt_ts_temp2 SET SCHEMA alt_nsp2;" db-types="PostgreSQL" />
     <sql-case id="alter_by_postgresql_source_test_case411" value="ALTER 
TRIGGER modified_a ON main_table RENAME TO modified_modified_a;" 
db-types="PostgreSQL" />
     <sql-case id="alter_by_postgresql_source_test_case412" value="ALTER TYPE 
bogon ADD VALUE &apos;bad&apos;;" db-types="PostgreSQL" />
     <sql-case id="alter_by_postgresql_source_test_case413" value="ALTER TYPE 
bogon ADD VALUE &apos;bad&apos;;" db-types="PostgreSQL" />
@@ -5318,9 +5297,6 @@
     <sql-case id="low_alter_by_postgresql_source_test_case61" value="alter 
table anothertab alter column atcol1 type boolean         using case when 
atcol1 % 2 = 0 then true else fa alter table anothertab drop constraint 
anothertab_chk;" db-types="PostgreSQL" />
     <sql-case id="low_alter_by_postgresql_source_test_case62" value="alter 
table check_con_tbl add check (check_con_function(check_con_tbl.*));" 
db-types="PostgreSQL" />
     <sql-case id="low_alter_by_postgresql_source_test_case63" value="alter 
table rename;" db-types="PostgreSQL" />
-    <sql-case id="low_alter_by_postgresql_source_test_case64" value="alter 
text search configuration alter1.cfg set schema alter2;" db-types="PostgreSQL" 
/>
-    <sql-case id="low_alter_by_postgresql_source_test_case65" value="alter 
text search parser alter1.prs set schema alter2;" db-types="PostgreSQL" />
-    <sql-case id="low_alter_by_postgresql_source_test_case66" value="alter 
text search template alter1.tmpl set schema alter2;" db-types="PostgreSQL" />
     <sql-case id="low_alter_by_postgresql_source_test_case67" value="alter 
trigger a on grandparent rename to b;" db-types="PostgreSQL" />
     <sql-case id="low_alter_by_postgresql_source_test_case68" value="alter 
type alter1.ctype set schema alter1;" db-types="PostgreSQL" />
     <sql-case id="low_alter_by_postgresql_source_test_case69" value="alter 
type alter1.ctype set schema alter2;" db-types="PostgreSQL" />

Reply via email to