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/10/24 13:56:02 UTC

(shardingsphere) branch master updated: Fix PostgreSQL 15+ pipeline catalog compatibility (#40363)

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 3cbeeeb1a1a Fix PostgreSQL 15+ pipeline catalog compatibility (#40363)
3cbeeeb1a1a is described below

commit 3cbeeeb1a1a251e8eefc2e06b074ed42e05e01e4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Oct 24 21:55:55 2026 +0800

    Fix PostgreSQL 15+ pipeline catalog compatibility (#40363)
---
 .../template/component/table/10_plus/properties.ftl   |  3 +--
 .../template/component/table/11_plus/properties.ftl   |  3 +--
 .../template/component/table/12_plus/properties.ftl   |  3 +--
 .../component/table/default/get_database_id.ftl       |  2 +-
 .../template/component/table/default/properties.ftl   |  3 +--
 .../table/PostgreSQLTablePropertiesLoaderTest.java    | 19 +++++++++----------
 .../PostgreSQLPipelineFreemarkerManagerTest.java      | 11 +++++++----
 7 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/10_plus/properties.ftl b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/10_plus/properties.ftl
index dbeb40d4378..16b3ddbbf4a 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/10_plus/properties.ftl
+++ b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/10_plus/properties.ftl
@@ -75,8 +75,7 @@ rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype,
 CASE WHEN typ.typname IS NOT NULL THEN (select pg_catalog.quote_ident(nspname) FROM pg_catalog.pg_namespace WHERE oid = ${scid?c}::oid )||'.'||pg_catalog.quote_ident(typ.typname) ELSE typ.typname END AS typname,
 typ.typrelid AS typoid, rel.relrowsecurity as rlspolicy, rel.relforcerowsecurity as forcerlspolicy,
 (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
-(SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels,
-(CASE WHEN rel.oid <= ${ datlastsysoid?c}::oid THEN true ElSE false END) AS is_sys_table
+(SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels
 -- Added for partition table
 <#if tid?? >, (CASE WHEN rel.relkind = 'p' THEN pg_catalog.pg_get_partkeydef(${ tid?c }::oid) ELSE '' END) AS partition_scheme </#if>
 FROM pg_catalog.pg_class rel
diff --git a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/11_plus/properties.ftl b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/11_plus/properties.ftl
index bc6c05bd6d4..b31f3c083f3 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/11_plus/properties.ftl
+++ b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/11_plus/properties.ftl
@@ -76,8 +76,7 @@ rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype,
 CASE WHEN typ.typname IS NOT NULL THEN (select pg_catalog.quote_ident(nspname) FROM pg_catalog.pg_namespace WHERE oid = ${scid?c}::oid )||'.'||pg_catalog.quote_ident(typ.typname) ELSE typ.typname END AS typname,
 typ.typrelid AS typoid, rel.relrowsecurity as rlspolicy, rel.relforcerowsecurity as forcerlspolicy,
 (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
-(SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels,
-(CASE WHEN rel.oid <= ${ datlastsysoid?c}::oid THEN true ElSE false END) AS is_sys_table
+(SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels
 -- Added for partition table
 <#if tid?? >, (CASE WHEN rel.relkind = 'p' THEN pg_catalog.pg_get_partkeydef(${ tid?c }::oid) ELSE '' END) AS partition_scheme </#if>
 FROM pg_catalog.pg_class rel
diff --git a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/12_plus/properties.ftl b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/12_plus/properties.ftl
index 983cf168b65..5e3b265f659 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/12_plus/properties.ftl
+++ b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/12_plus/properties.ftl
@@ -76,8 +76,7 @@ rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype,
 CASE WHEN typ.typname IS NOT NULL THEN (select pg_catalog.quote_ident(nspname) FROM pg_catalog.pg_namespace WHERE oid = ${scid?c}::oid )||'.'||pg_catalog.quote_ident(typ.typname) ELSE typ.typname END AS typname,
 typ.typrelid AS typoid, rel.relrowsecurity as rlspolicy, rel.relforcerowsecurity as forcerlspolicy,
 (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
-(SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels,
-(CASE WHEN rel.oid <= ${ datlastsysoid?c}::oid THEN true ElSE false END) AS is_sys_table
+(SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels
 -- Added for partition table
 <#if tid?? >, (CASE WHEN rel.relkind = 'p' THEN pg_catalog.pg_get_partkeydef(${ tid?c }::oid) ELSE '' END) AS partition_scheme </#if>
 FROM pg_catalog.pg_class rel
diff --git a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/get_database_id.ftl b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/get_database_id.ftl
index e5d003cd00c..364ec48908e 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/get_database_id.ftl
+++ b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/get_database_id.ftl
@@ -15,4 +15,4 @@
   ~ limitations under the License.
   -->
 
-SELECT oid AS did, datlastsysoid FROM pg_catalog.pg_database WHERE datname = '${databaseName}';
+SELECT oid AS did FROM pg_catalog.pg_database WHERE datname = '${databaseName}';
diff --git a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/properties.ftl b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/properties.ftl
index 38af8b822e0..d60e26b2149 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/properties.ftl
+++ b/kernel/data-pipeline/dialect/postgresql/src/main/resources/template/component/table/default/properties.ftl
@@ -69,8 +69,7 @@ substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_freez
 rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, NULL AS typname,
 typ.typrelid AS typoid, rel.relrowsecurity as rlspolicy, rel.relforcerowsecurity as forcerlspolicy,
 (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
-ARRAY[]::varchar[] AS seclabels,
-(CASE WHEN rel.oid <= ${ datlastsysoid?c}::oid THEN true ElSE false END) AS is_sys_table
+ARRAY[]::varchar[] AS seclabels
 
 FROM pg_catalog.pg_class rel
 LEFT OUTER JOIN pg_catalog.pg_tablespace spc on spc.oid=rel.reltablespace
diff --git a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/table/PostgreSQLTablePropertiesLoaderTest.java b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/table/PostgreSQLTablePropertiesLoaderTest.java
index 935a9ef8221..9ddd94522fb 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/table/PostgreSQLTablePropertiesLoaderTest.java
+++ b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/ddl/table/PostgreSQLTablePropertiesLoaderTest.java
@@ -17,7 +17,8 @@
 
 package org.apache.shardingsphere.data.pipeline.postgresql.sqlbuilder.ddl.table;
 
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -33,18 +34,18 @@ import static org.mockito.Mockito.when;
 
 class PostgreSQLTablePropertiesLoaderTest {
     
-    @Test
-    void assertLoad() throws SQLException {
+    @ParameterizedTest(name = "PostgreSQL {0}")
+    @ValueSource(ints = {9, 10, 11, 12, 14, 15, 17})
+    void assertLoad(final int majorVersion) throws SQLException {
         Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
         when(connection.getCatalog()).thenReturn("foo_db");
         ResultSet fetchDatabaseIdResultSet = mockFetchDatabaseIdResultSet();
-        when(connection.createStatement().executeQuery("\nSELECT oid AS did, datlastsysoid FROM pg_catalog.pg_database WHERE datname = 'foo_db';\n")).thenReturn(fetchDatabaseIdResultSet);
+        when(connection.createStatement().executeQuery("\nSELECT oid AS did FROM pg_catalog.pg_database WHERE datname = 'foo_db';\n")).thenReturn(fetchDatabaseIdResultSet);
         ResultSet fetchSchemaIdResultSet = mockFetchSchemaIdResultSet();
         when(connection.createStatement().executeQuery("\nSELECT oid AS scid FROM pg_catalog.pg_namespace WHERE nspname = 'foo_schema';\n")).thenReturn(fetchSchemaIdResultSet);
-        Map<String, Object> actual = new PostgreSQLTablePropertiesLoader(connection, "foo_tbl", "foo_schema", 12, 0).load();
-        assertThat(actual.size(), is(7));
+        Map<String, Object> actual = new PostgreSQLTablePropertiesLoader(connection, "foo_tbl", "foo_schema", majorVersion, 0).load();
+        assertThat(actual.size(), is(6));
         assertThat(actual.get("did"), is(1));
-        assertThat(actual.get("datlastsysoid"), is(10));
         assertThat(actual.get("scid"), is(20));
         assertThat(actual.get("autovacuum_enabled"), is("x"));
         assertThat(actual.get("toast_autovacuum_enabled"), is("x"));
@@ -54,12 +55,10 @@ class PostgreSQLTablePropertiesLoaderTest {
     
     private ResultSet mockFetchDatabaseIdResultSet() throws SQLException {
         ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
-        when(result.getMetaData().getColumnCount()).thenReturn(2);
+        when(result.getMetaData().getColumnCount()).thenReturn(1);
         when(result.next()).thenReturn(true);
         when(result.getMetaData().getColumnName(1)).thenReturn("did");
         when(result.getObject(1)).thenReturn(1);
-        when(result.getMetaData().getColumnName(2)).thenReturn("datlastsysoid");
-        when(result.getObject(2)).thenReturn(10);
         return result;
     }
     
diff --git a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/template/PostgreSQLPipelineFreemarkerManagerTest.java b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/template/PostgreSQLPipelineFreemarkerManagerTest.java
index 845d75367d4..d2b830b4fe0 100644
--- a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/template/PostgreSQLPipelineFreemarkerManagerTest.java
+++ b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/template/PostgreSQLPipelineFreemarkerManagerTest.java
@@ -18,6 +18,8 @@
 package org.apache.shardingsphere.data.pipeline.postgresql.sqlbuilder.template;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -33,10 +35,11 @@ class PostgreSQLPipelineFreemarkerManagerTest {
     
     private static final Pattern PATTERN = Pattern.compile("\\s+");
     
-    @Test
-    void assertGetSQLByDefaultVersion() {
-        String actual = PostgreSQLPipelineFreemarkerManager.getSQLByVersion(Collections.singletonMap("databaseName", "foo_db"), "component/table/%s/get_database_id.ftl", 10, 0);
-        String expected = "\nSELECT oid AS did, datlastsysoid FROM pg_catalog.pg_database WHERE datname = 'foo_db';\n";
+    @ParameterizedTest(name = "PostgreSQL {0}")
+    @ValueSource(ints = {10, 11, 12, 13, 14, 15, 16, 17})
+    void assertGetSQLByDefaultVersion(final int majorVersion) {
+        String actual = PostgreSQLPipelineFreemarkerManager.getSQLByVersion(Collections.singletonMap("databaseName", "foo_db"), "component/table/%s/get_database_id.ftl", majorVersion, 0);
+        String expected = "\nSELECT oid AS did FROM pg_catalog.pg_database WHERE datname = 'foo_db';\n";
         assertThat(actual, is(expected));
     }