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 07a51551459 Add support for partition tables in Postgresql (#34329)
(#34346)
07a51551459 is described below
commit 07a51551459cdecf497ce20b44a779879009f168
Author: Amir H Movahed <[email protected]>
AuthorDate: Fri Jan 17 01:08:58 2025 +0100
Add support for partition tables in Postgresql (#34329) (#34346)
---
RELEASE-NOTES.md | 1 +
.../core/metadata/data/loader/type/SchemaMetaDataLoader.java | 6 +++++-
.../metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java | 10 ++++++----
.../data/loader/OpenGaussSchemaMetaDataLoaderTest.java | 9 +++++----
.../data/loader/PostgreSQLSchemaMetaDataLoaderTest.java | 9 +++++----
.../single/datanode/SingleTableDataNodeLoaderTest.java | 4 +++-
.../org/apache/shardingsphere/single/rule/SingleRuleTest.java | 5 ++++-
7 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 623928f6902..9418b2f0b4e 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -56,6 +56,7 @@
1. Mode: Support modifying Hikari-CP configurations via props in standalone
mode [#34185](https://github.com/apache/shardingsphere/pull/34185)
1. Encrypt: Support insert statement rewrite use quote
[#34259](https://github.com/apache/shardingsphere/pull/34259)
1. Infra: Support connecting to Firebird via jdbcUrl containing the absolute
path to fdb - [#34335](https://github.com/apache/shardingsphere/pull/34335)
+1. Add support for partition tables in Postgresql
[#34346](https://github.com/apache/shardingsphere/pull/34346)
### Bug Fixes
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
index a1ec5e4ea84..f048b8574cf 100644
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
+++
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/data/loader/type/SchemaMetaDataLoader.java
@@ -43,6 +43,8 @@ public final class SchemaMetaDataLoader {
private static final String TABLE_TYPE = "TABLE";
+ private static final String PARTITIONED_TABLE_TYPE = "PARTITIONED TABLE";
+
private static final String VIEW_TYPE = "VIEW";
private static final String SYSTEM_TABLE_TYPE = "SYSTEM TABLE";
@@ -105,7 +107,9 @@ public final class SchemaMetaDataLoader {
private static Collection<String> loadTableNames(final Connection
connection, final String schemaName, final Collection<String> excludedTables)
throws SQLException {
Collection<String> result = new LinkedList<>();
- try (ResultSet resultSet =
connection.getMetaData().getTables(connection.getCatalog(), schemaName, null,
new String[]{TABLE_TYPE, VIEW_TYPE, SYSTEM_TABLE_TYPE, SYSTEM_VIEW_TYPE})) {
+ try (
+ ResultSet resultSet =
connection.getMetaData().getTables(connection.getCatalog(), schemaName, null,
+ new String[]{TABLE_TYPE, PARTITIONED_TABLE_TYPE,
VIEW_TYPE, SYSTEM_TABLE_TYPE, SYSTEM_VIEW_TYPE})) {
while (resultSet.next()) {
String table = resultSet.getString(TABLE_NAME);
if (!isSystemTable(table) && !excludedTables.contains(table)) {
diff --git
a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
index aa572238bd4..6a1f24deb46 100644
---
a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
+++
b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java
@@ -32,6 +32,7 @@ import org.mockito.quality.Strictness;
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -51,7 +52,8 @@ class MySQLSchemaMetaDataLoaderTest {
@BeforeEach
void setUp() throws SQLException {
ResultSet tableResultSet = mockTableResultSet();
- when(dataSource.getConnection().getMetaData().getTables("catalog",
"public", null, new String[]{"TABLE", "VIEW", "SYSTEM TABLE", "SYSTEM
VIEW"})).thenReturn(tableResultSet);
+ when(dataSource.getConnection().getMetaData().getTables("catalog",
"public", null, new String[]{"TABLE", "PARTITIONED TABLE", "VIEW", "SYSTEM
TABLE", "SYSTEM VIEW"}))
+ .thenReturn(tableResultSet);
when(dataSource.getConnection().getCatalog()).thenReturn("catalog");
when(dataSource.getConnection().getSchema()).thenReturn("public");
ResultSet schemaResultSet = mockSchemaResultSet();
@@ -60,8 +62,8 @@ class MySQLSchemaMetaDataLoaderTest {
private ResultSet mockTableResultSet() throws SQLException {
ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, true, true, false);
- when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl",
"##tbl");
+ when(result.next()).thenReturn(true, true, true, true, true, false);
+ when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl",
"##tbl", "partitioned_tbl");
return result;
}
@@ -74,7 +76,7 @@ class MySQLSchemaMetaDataLoaderTest {
@Test
void assertLoadSchemaTableNames() throws SQLException {
- Map<String, Collection<String>> schemaTableNames =
Collections.singletonMap("foo_db", Collections.singletonList("tbl"));
+ Map<String, Collection<String>> schemaTableNames =
Collections.singletonMap("foo_db", Arrays.asList("tbl", "partitioned_tbl"));
assertThat(SchemaMetaDataLoader.loadSchemaTableNames("foo_db",
TypedSPILoader.getService(DatabaseType.class, "MySQL"), dataSource,
Collections.emptyList()), is(schemaTableNames));
}
diff --git
a/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
b/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
index f53f08552ce..0add785fdea 100644
---
a/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
+++
b/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java
@@ -53,7 +53,8 @@ class OpenGaussSchemaMetaDataLoaderTest {
@BeforeEach
void setUp() throws SQLException {
ResultSet tableResultSet = mockTableResultSet();
- when(dataSource.getConnection().getMetaData().getTables("catalog",
"public", null, new String[]{"TABLE", "VIEW", "SYSTEM TABLE", "SYSTEM
VIEW"})).thenReturn(tableResultSet);
+ when(dataSource.getConnection().getMetaData().getTables("catalog",
"public", null, new String[]{"TABLE", "PARTITIONED TABLE", "VIEW", "SYSTEM
TABLE", "SYSTEM VIEW"}))
+ .thenReturn(tableResultSet);
when(dataSource.getConnection().getCatalog()).thenReturn("catalog");
when(dataSource.getConnection().getSchema()).thenReturn("public");
ResultSet schemaResultSet = mockSchemaResultSet();
@@ -62,8 +63,8 @@ class OpenGaussSchemaMetaDataLoaderTest {
private ResultSet mockTableResultSet() throws SQLException {
ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, true, true, false);
- when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl",
"##tbl");
+ when(result.next()).thenReturn(true, true, true, true, true, false);
+ when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl",
"##tbl", "partitioned_tbl");
return result;
}
@@ -81,7 +82,7 @@ class OpenGaussSchemaMetaDataLoaderTest {
private Map<String, Collection<String>> createSchemaTableNames() {
Map<String, Collection<String>> result = new LinkedHashMap<>();
- result.put("public", Collections.singletonList("tbl"));
+ result.put("public", Arrays.asList("tbl", "partitioned_tbl"));
result.put("schema_1", Collections.emptyList());
result.put("schema_2", Collections.emptyList());
return result;
diff --git
a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
index bfea6330d98..6094691c7b0 100644
---
a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
+++
b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java
@@ -53,7 +53,8 @@ class PostgreSQLSchemaMetaDataLoaderTest {
@BeforeEach
void setUp() throws SQLException {
ResultSet tableResultSet = mockTableResultSet();
- when(dataSource.getConnection().getMetaData().getTables("catalog",
"public", null, new String[]{"TABLE", "VIEW", "SYSTEM TABLE", "SYSTEM
VIEW"})).thenReturn(tableResultSet);
+ when(dataSource.getConnection().getMetaData().getTables("catalog",
"public", null, new String[]{"TABLE", "PARTITIONED TABLE", "VIEW", "SYSTEM
TABLE", "SYSTEM VIEW"}))
+ .thenReturn(tableResultSet);
when(dataSource.getConnection().getCatalog()).thenReturn("catalog");
when(dataSource.getConnection().getSchema()).thenReturn("public");
ResultSet schemaResultSet = mockSchemaResultSet();
@@ -62,8 +63,8 @@ class PostgreSQLSchemaMetaDataLoaderTest {
private ResultSet mockTableResultSet() throws SQLException {
ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, true, true, false);
- when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl",
"##tbl");
+ when(result.next()).thenReturn(true, true, true, true, true, false);
+ when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl",
"##tbl", "partitioned_tbl");
return result;
}
@@ -82,7 +83,7 @@ class PostgreSQLSchemaMetaDataLoaderTest {
private Map<String, Collection<String>> createSchemaTableNames() {
Map<String, Collection<String>> result = new LinkedHashMap<>();
- result.put("public", Collections.singletonList("tbl"));
+ result.put("public", Arrays.asList("tbl", "partitioned_tbl"));
result.put("schema_1", Collections.emptyList());
result.put("schema_2", Collections.emptyList());
return result;
diff --git
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
index afdcfc44c30..a62e4fd6e7b 100644
---
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
+++
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
@@ -51,6 +51,8 @@ class SingleTableDataNodeLoaderTest {
private static final String TABLE_TYPE = "TABLE";
+ private static final String PARTITIONED_TABLE_TYPE = "PARTITIONED TABLE";
+
private static final String VIEW_TYPE = "VIEW";
private static final String SYSTEM_TABLE_TYPE = "SYSTEM TABLE";
@@ -74,7 +76,7 @@ class SingleTableDataNodeLoaderTest {
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getCatalog()).thenReturn(dataSourceName);
ResultSet resultSet = mockResultSet(tableNames);
- when(connection.getMetaData().getTables(dataSourceName, null, null,
new String[]{TABLE_TYPE, VIEW_TYPE, SYSTEM_TABLE_TYPE,
SYSTEM_VIEW_TYPE})).thenReturn(resultSet);
+ when(connection.getMetaData().getTables(dataSourceName, null, null,
new String[]{TABLE_TYPE, PARTITIONED_TABLE_TYPE, VIEW_TYPE, SYSTEM_TABLE_TYPE,
SYSTEM_VIEW_TYPE})).thenReturn(resultSet);
when(connection.getMetaData().getURL()).thenReturn("jdbc:mock://127.0.0.1/foo_ds");
return new MockedDataSource(connection);
}
diff --git
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
index a4147f3c7d0..e27025edeb8 100644
---
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
+++
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
@@ -58,6 +58,8 @@ class SingleRuleTest {
private static final String TABLE_TYPE = "TABLE";
+ private static final String PARTITIONED_TABLE_TYPE = "PARTITIONED TABLE";
+
private static final String VIEW_TYPE = "VIEW";
private static final String SYSTEM_TABLE_TYPE = "SYSTEM TABLE";
@@ -85,7 +87,8 @@ class SingleRuleTest {
when(connection.getMetaData().getURL()).thenReturn(String.format("jdbc:h2:mem:%s",
dataSourceName));
DataSource result = new MockedDataSource(connection);
ResultSet resultSet = mockResultSet(tableNames);
- when(result.getConnection().getMetaData().getTables(dataSourceName,
null, null, new String[]{TABLE_TYPE, VIEW_TYPE, SYSTEM_TABLE_TYPE,
SYSTEM_VIEW_TYPE})).thenReturn(resultSet);
+ when(result.getConnection().getMetaData().getTables(dataSourceName,
null, null, new String[]{TABLE_TYPE, PARTITIONED_TABLE_TYPE, VIEW_TYPE,
SYSTEM_TABLE_TYPE, SYSTEM_VIEW_TYPE}))
+ .thenReturn(resultSet);
return result;
}