You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/09/14 08:21:15 UTC

(shardingsphere) branch master updated: Support foreign table syntax for openGauss (#39525)

This is an automated email from the ASF dual-hosted git repository.

terrymanu 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 64a038e9e75 Support foreign table syntax for openGauss (#39525)
64a038e9e75 is described below

commit 64a038e9e751de411738fb518cb965a9862adcbd
Author: linyu <54...@users.noreply.github.com>
AuthorDate: Mon Sep 14 16:21:08 2026 +0800

    Support foreign table syntax for openGauss (#39525)
    
    * Support foreign table syntax for openGauss (#25104)
    
    * Support create foreign table without SERVER for openGauss
    
    openGauss accepts CREATE FOREIGN TABLE without a SERVER clause and defaults to mot_server (gram.y ENABLE_MOT branch). Add the no-SERVER alternative to createForeignTableClauses and IT cases for the original reproducer from issue #25103.
    
    ---------
    
    Co-authored-by: lintyu <li...@tencent.com>
---
 .../main/antlr4/imports/opengauss/DDLStatement.g4  |  1 +
 .../sql/parser/autogen/OpenGaussStatementParser.g4 |  2 ++
 .../type/OpenGaussDDLStatementVisitor.java         | 14 ++++++++++
 .../resources/case/ddl/create-foreign-table.xml    |  2 ++
 .../sql/supported/ddl/create-foreign-table.xml     |  8 ++++--
 .../sql/supported/ddl/drop-foreign-table.xml       | 32 +++++++++++-----------
 6 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/parser/sql/engine/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 b/parser/sql/engine/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4
index 90f55ab918e..ea46d1def29 100644
--- a/parser/sql/engine/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4
+++ b/parser/sql/engine/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4
@@ -1369,6 +1369,7 @@ createForeignTableClauses
       (INHERITS LP_ qualifiedNameList RP_)? SERVER name createGenericOptions?
     | ifNotExists? qualifiedName PARTITION OF qualifiedName (LP_ typedTableElementList RP_)? partitionBoundSpec
       SERVER name createGenericOptions?
+    | ifNotExists? qualifiedName LP_ tableElementList? RP_ createGenericOptions?
     ;
 
 tableElementList
diff --git a/parser/sql/engine/dialect/opengauss/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OpenGaussStatementParser.g4 b/parser/sql/engine/dialect/opengauss/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OpenGaussStatementParser.g4
index dbd99e79ff3..c9295b06814 100644
--- a/parser/sql/engine/dialect/opengauss/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OpenGaussStatementParser.g4
+++ b/parser/sql/engine/dialect/opengauss/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/OpenGaussStatementParser.g4
@@ -75,6 +75,7 @@ execute
     | createDatabase
     | createFunction
     | createProcedure
+    | createForeignTable
     | createServer
     | createTrigger
     | createView
@@ -89,6 +90,7 @@ execute
     | createTextSearch
     | dropDatabase
     | dropFunction
+    | dropForeignTable
     | dropProcedure
     | dropRule
     | dropServer
diff --git a/parser/sql/engine/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/engine/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java b/parser/sql/engine/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/engine/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java
index 332ef727d03..13940676461 100644
--- a/parser/sql/engine/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/engine/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java
+++ b/parser/sql/engine/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/engine/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java
@@ -71,6 +71,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.Cre
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateDirectoryContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateDomainContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateExtensionContext;
+import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateForeignTableContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateFunctionContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateIndexContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateLanguageContext;
@@ -97,6 +98,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.Dro
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropDirectoryContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropDomainContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropExtensionContext;
+import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropForeignTableContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropFunctionContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropIndexContext;
 import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DropLanguageContext;
@@ -237,6 +239,8 @@ import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.extension.P
 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.extension.PostgreSQLCreateExtensionStatement;
 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.extension.PostgreSQLDropExtensionStatement;
 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigntable.PostgreSQLAlterForeignTableStatement;
+import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigntable.PostgreSQLCreateForeignTableStatement;
+import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.foreigntable.PostgreSQLDropForeignTableStatement;
 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.group.PostgreSQLAlterGroupStatement;
 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.language.PostgreSQLAlterLanguageStatement;
 import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.language.PostgreSQLCreateLanguageStatement;
@@ -669,11 +673,21 @@ public final class OpenGaussDDLStatementVisitor extends OpenGaussStatementVisito
         return new CreateProcedureStatement(getDatabaseType());
     }
     
+    @Override
+    public ASTNode visitCreateForeignTable(final CreateForeignTableContext ctx) {
+        return new PostgreSQLCreateForeignTableStatement(getDatabaseType());
+    }
+    
     @Override
     public ASTNode visitDropFunction(final DropFunctionContext ctx) {
         return new DropFunctionStatement(getDatabaseType());
     }
     
+    @Override
+    public ASTNode visitDropForeignTable(final DropForeignTableContext ctx) {
+        return new PostgreSQLDropForeignTableStatement(getDatabaseType());
+    }
+    
     @SuppressWarnings("unchecked")
     @Override
     public ASTNode visitDropView(final DropViewContext ctx) {
diff --git a/test/it/parser/src/main/resources/case/ddl/create-foreign-table.xml b/test/it/parser/src/main/resources/case/ddl/create-foreign-table.xml
index 47f8a7dfdc9..503c0709acf 100644
--- a/test/it/parser/src/main/resources/case/ddl/create-foreign-table.xml
+++ b/test/it/parser/src/main/resources/case/ddl/create-foreign-table.xml
@@ -20,4 +20,6 @@
     <create-foreign-table sql-case-id="create_foreign_table" />
     <create-foreign-table sql-case-id="create_foreign_table_server_options" />
     <create-foreign-table sql-case-id="create_foreign_table_without_table_elements" />
+    <create-foreign-table sql-case-id="create_foreign_table_without_server" />
+    <create-foreign-table sql-case-id="create_foreign_table_without_server_with_options" />
 </sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-foreign-table.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-foreign-table.xml
index c0634c219ee..5935d8a29c6 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/create-foreign-table.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-foreign-table.xml
@@ -17,7 +17,9 @@
   -->
 
 <sql-cases>
-    <sql-case id="create_foreign_table" value="CREATE FOREIGN TABLE addr_nsp.genftable (a int) SERVER addr_fserv;" db-types="PostgreSQL" />
-    <sql-case id="create_foreign_table_server_options" value="CREATE FOREIGN TABLE fd_pt2_1 ( 	c1 integer NOT NULL, 	c2 text, 	c3 date ) SERVER s0 OPTIONS (delimiter &apos;,&apos;, quote &apos;&quot;&apos;, &quot;be quoted&quot; &apos;value&apos;);" db-types="PostgreSQL" />
-    <sql-case id="create_foreign_table_without_table_elements" value="CREATE FOREIGN TABLE tableam_fdw_heapx () SERVER fs_heap2;" db-types="PostgreSQL" />
+    <sql-case id="create_foreign_table" value="CREATE FOREIGN TABLE addr_nsp.genftable (a int) SERVER addr_fserv;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="create_foreign_table_server_options" value="CREATE FOREIGN TABLE fd_pt2_1 ( 	c1 integer NOT NULL, 	c2 text, 	c3 date ) SERVER s0 OPTIONS (delimiter &apos;,&apos;, quote &apos;&quot;&apos;, &quot;be quoted&quot; &apos;value&apos;);" db-types="PostgreSQL,openGauss" />
+    <sql-case id="create_foreign_table_without_table_elements" value="CREATE FOREIGN TABLE tableam_fdw_heapx () SERVER fs_heap2;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="create_foreign_table_without_server" value="CREATE FOREIGN TABLE t_order (user_id int, order_name varchar(30));" db-types="openGauss" />
+    <sql-case id="create_foreign_table_without_server_with_options" value="CREATE FOREIGN TABLE t_order (user_id int, order_name varchar(30)) OPTIONS (delimiter &apos;,&apos;);" db-types="openGauss" />
 </sql-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/drop-foreign-table.xml b/test/it/parser/src/main/resources/sql/supported/ddl/drop-foreign-table.xml
index 00f0056d42d..6e639606a01 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/drop-foreign-table.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/drop-foreign-table.xml
@@ -17,20 +17,20 @@
   -->
 
 <sql-cases>
-    <sql-case id="drop_by_postgresql_source_test_case63" value="DROP FOREIGN TABLE IF EXISTS no_such_schema.foo;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case64" value="DROP FOREIGN TABLE IF EXISTS no_table;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case65" value="DROP FOREIGN TABLE fd_pt2_1;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case66" value="DROP FOREIGN TABLE fd_pt2_1;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case67" value="DROP FOREIGN TABLE fd_pt2_1;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case68" value="DROP FOREIGN TABLE foreign_part;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case69" value="DROP FOREIGN TABLE foreign_schema.foreign_table_1;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case70" value="DROP FOREIGN TABLE ft1;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case71" value="DROP FOREIGN TABLE ft2 CASCADE;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case72" value="DROP FOREIGN TABLE ft2;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case73" value="DROP FOREIGN TABLE ft2;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case74" value="DROP FOREIGN TABLE ft_part1, ft_part2;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case75" value="DROP FOREIGN TABLE ft_part2;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case76" value="DROP FOREIGN TABLE ft_part_1_1, ft_part_1_2;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case77" value="DROP FOREIGN TABLE ft_part_1_2;" db-types="PostgreSQL" />
-    <sql-case id="drop_by_postgresql_source_test_case78" value="DROP FOREIGN TABLE no_table;" db-types="PostgreSQL" />
+    <sql-case id="drop_by_postgresql_source_test_case63" value="DROP FOREIGN TABLE IF EXISTS no_such_schema.foo;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case64" value="DROP FOREIGN TABLE IF EXISTS no_table;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case65" value="DROP FOREIGN TABLE fd_pt2_1;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case66" value="DROP FOREIGN TABLE fd_pt2_1;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case67" value="DROP FOREIGN TABLE fd_pt2_1;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case68" value="DROP FOREIGN TABLE foreign_part;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case69" value="DROP FOREIGN TABLE foreign_schema.foreign_table_1;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case70" value="DROP FOREIGN TABLE ft1;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case71" value="DROP FOREIGN TABLE ft2 CASCADE;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case72" value="DROP FOREIGN TABLE ft2;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case73" value="DROP FOREIGN TABLE ft2;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case74" value="DROP FOREIGN TABLE ft_part1, ft_part2;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case75" value="DROP FOREIGN TABLE ft_part2;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case76" value="DROP FOREIGN TABLE ft_part_1_1, ft_part_1_2;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case77" value="DROP FOREIGN TABLE ft_part_1_2;" db-types="PostgreSQL,openGauss" />
+    <sql-case id="drop_by_postgresql_source_test_case78" value="DROP FOREIGN TABLE no_table;" db-types="PostgreSQL,openGauss" />
 </sql-cases>