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 2020/07/30 09:14:00 UTC

[shardingsphere] branch master updated: Fix #3954 : Sharding-JDBC querying support PostgreSQL array type (#6524)

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

zhangyonglun 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 184c6f7  Fix #3954 : Sharding-JDBC querying support PostgreSQL array type (#6524)
184c6f7 is described below

commit 184c6f7528642925b7e6f00b1a3aad28c638ffef
Author: sandynz <42...@users.noreply.github.com>
AuthorDate: Thu Jul 30 17:13:47 2020 +0800

    Fix #3954 : Sharding-JDBC querying support PostgreSQL array type (#6524)
    
    * Sharding-JDBC support PostgreSQL array type
    
    * Sharding-JDBC support PostgreSQL array type
    
    * Sharding-JDBC support PostgreSQL array type, try to fix ci error
---
 .../resourced/jdbc/queryresult/MemoryQueryResult.java    |  2 ++
 .../resourced/jdbc/queryresult/StreamQueryResult.java    |  3 +++
 .../sql/jdbc/queryresult/MemoryQueryResultTest.java      | 12 ++++++++++++
 .../sql/jdbc/queryresult/StreamQueryResultTest.java      |  9 +++++++++
 .../jdbc/core/resultset/ShardingSphereResultSet.java     | 13 ++++++++++++-
 .../AbstractUnsupportedDatabaseMetaDataResultSet.java    | 11 +++++++++++
 .../AbstractUnsupportedGeneratedKeysResultSet.java       | 11 +++++++++++
 .../AbstractUnsupportedOperationResultSet.java           | 11 -----------
 .../jdbc/core/resultset/ShardingSphereResultSetTest.java | 15 +++++++++++++++
 .../unsupported/UnsupportedOperationResultSetTest.java   | 16 +---------------
 .../circuit/resultset/CircuitBreakerResultSet.java       | 11 +++++++++++
 11 files changed, 87 insertions(+), 27 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/MemoryQueryResult.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/MemoryQueryResult.java
index 35d4c26..a58acf0 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/MemoryQueryResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/MemoryQueryResult.java
@@ -107,6 +107,8 @@ public final class MemoryQueryResult implements QueryResult {
             case Types.VARBINARY:
             case Types.LONGVARBINARY:
                 return resultSet.getBlob(columnIndex);
+            case Types.ARRAY:
+                return resultSet.getArray(columnIndex);
             default:
                 return resultSet.getObject(columnIndex);
         }
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/StreamQueryResult.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/StreamQueryResult.java
index ee2e1e1..f8bd296 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/StreamQueryResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/resourced/jdbc/queryresult/StreamQueryResult.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.queryresult;
 
+import java.sql.Array;
 import org.apache.shardingsphere.infra.executor.sql.QueryResult;
 
 import java.io.InputStream;
@@ -87,6 +88,8 @@ public final class StreamQueryResult implements QueryResult {
             return resultSet.getBlob(columnIndex);
         } else if (Clob.class == type) {
             return resultSet.getClob(columnIndex);
+        } else if (Array.class == type) {
+            return resultSet.getArray(columnIndex);
         } else {
             return resultSet.getObject(columnIndex);
         }
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/MemoryQueryResultTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/MemoryQueryResultTest.java
index ff0aaa7..882aa24 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/MemoryQueryResultTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/MemoryQueryResultTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.executor.sql.jdbc.queryresult;
 
+import java.sql.Array;
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.queryresult.MemoryQueryResult;
 import org.hamcrest.core.Is;
@@ -306,6 +307,17 @@ public final class MemoryQueryResultTest {
         assertFalse(actual.next());
     }
     
+    @Test
+    public void assertGetValueByArray() throws SQLException {
+        ResultSet resultSet = getMockedResultSet(Types.ARRAY);
+        Array value = mock(Array.class);
+        when(resultSet.getArray(1)).thenReturn(value);
+        MemoryQueryResult actual = new MemoryQueryResult(resultSet);
+        assertTrue(actual.next());
+        assertThat(actual.getValue(1, Array.class), is(value));
+        assertFalse(actual.next());
+    }
+    
     private ResultSet getMockedResultSet(final int columnTypes) throws SQLException {
         ResultSet resultSet = mock(ResultSet.class);
         when(resultSet.next()).thenReturn(true, false);
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/StreamQueryResultTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/StreamQueryResultTest.java
index 87d7514..a3dab04 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/StreamQueryResultTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/jdbc/queryresult/StreamQueryResultTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.executor.sql.jdbc.queryresult;
 
+import java.sql.Array;
 import org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.queryresult.StreamQueryResult;
 import org.junit.Test;
 
@@ -151,6 +152,14 @@ public final class StreamQueryResultTest {
     }
     
     @Test
+    public void assertGetValueByArray() throws SQLException {
+        ResultSet resultSet = mock(ResultSet.class);
+        Array value = mock(Array.class);
+        when(resultSet.getArray(1)).thenReturn(value);
+        assertThat(new StreamQueryResult(resultSet).getValue(1, Array.class), is(value));
+    }
+    
+    @Test
     public void assertGetValueByTimestamp() throws SQLException {
         ResultSet resultSet = mock(ResultSet.class);
         when(resultSet.getTimestamp(1)).thenReturn(new Timestamp(0L));
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java
index 62aadfe..985a165 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSet.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.driver.jdbc.core.resultset;
 
+import java.sql.Array;
 import org.apache.shardingsphere.driver.jdbc.adapter.AbstractResultSetAdapter;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -317,13 +318,23 @@ public final class ShardingSphereResultSet extends AbstractResultSetAdapter {
     public Clob getClob(final int columnIndex) throws SQLException {
         return (Clob) mergeResultSet.getValue(columnIndex, Clob.class);
     }
-        
+    
     @Override
     public Clob getClob(final String columnLabel) throws SQLException {
         return getClob(getIndexFromColumnLabelAndIndexMap(columnLabel));
     }
     
     @Override
+    public Array getArray(final int columnIndex) throws SQLException {
+        return (Array) mergeResultSet.getValue(columnIndex, Array.class);
+    }
+    
+    @Override
+    public Array getArray(final String columnLabel) throws SQLException {
+        return getArray(getIndexFromColumnLabelAndIndexMap(columnLabel));
+    }
+    
+    @Override
     public URL getURL(final int columnIndex) throws SQLException {
         return (URL) mergeResultSet.getValue(columnIndex, URL.class);
     }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedDatabaseMetaDataResultSet.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedDatabaseMetaDataResultSet.java
index 55c01d7..aedd08c 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedDatabaseMetaDataResultSet.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedDatabaseMetaDataResultSet.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.io.Reader;
 import java.math.BigDecimal;
 import java.net.URL;
+import java.sql.Array;
 import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.Date;
@@ -114,6 +115,16 @@ public abstract class AbstractUnsupportedDatabaseMetaDataResultSet extends Abstr
     }
     
     @Override
+    public final Array getArray(final int columnIndex) throws SQLException {
+        throw new SQLFeatureNotSupportedException("getArray");
+    }
+    
+    @Override
+    public final Array getArray(final String columnLabel) throws SQLException {
+        throw new SQLFeatureNotSupportedException("getArray");
+    }
+    
+    @Override
     public final Blob getBlob(final int columnIndex) throws SQLException {
         throw new SQLFeatureNotSupportedException("getBlob");
     }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java
index 108ea77..ee4efe7 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.driver.jdbc.unsupported;
 import java.io.InputStream;
 import java.io.Reader;
 import java.net.URL;
+import java.sql.Array;
 import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.Date;
@@ -107,6 +108,16 @@ public abstract class AbstractUnsupportedGeneratedKeysResultSet extends Abstract
     }
     
     @Override
+    public final Array getArray(final int columnIndex) throws SQLException {
+        throw new SQLFeatureNotSupportedException("getArray");
+    }
+    
+    @Override
+    public final Array getArray(final String columnLabel) throws SQLException {
+        throw new SQLFeatureNotSupportedException("getArray");
+    }
+    
+    @Override
     public final InputStream getAsciiStream(final int columnIndex) throws SQLException {
         throw new SQLFeatureNotSupportedException("getAsciiStream");
     }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java
index 8d081f9..deadffa 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.driver.jdbc.unsupported;
 
 import java.io.Reader;
-import java.sql.Array;
 import java.sql.NClob;
 import java.sql.Ref;
 import java.sql.RowId;
@@ -182,16 +181,6 @@ public abstract class AbstractUnsupportedOperationResultSet extends AbstractUnsu
     }
     
     @Override
-    public final Array getArray(final int columnIndex) throws SQLException {
-        throw new SQLFeatureNotSupportedException("getArray");
-    }
-    
-    @Override
-    public final Array getArray(final String columnLabel) throws SQLException {
-        throw new SQLFeatureNotSupportedException("getArray");
-    }
-    
-    @Override
     public final RowId getRowId(final int columnIndex) throws SQLException {
         throw new SQLFeatureNotSupportedException("getRowId");
     }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
index 488db2b..5f92e60 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.driver.jdbc.core.resultset;
 
+import java.sql.Array;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
@@ -419,6 +420,20 @@ public final class ShardingSphereResultSetTest {
     }
     
     @Test
+    public void assertGetArrayWithColumnIndex() throws SQLException {
+        Array array = mock(Array.class);
+        when(mergeResultSet.getValue(1, Array.class)).thenReturn(array);
+        assertThat(shardingSphereResultSet.getArray(1), is(array));
+    }
+    
+    @Test
+    public void assertGetArrayWithColumnLabel() throws SQLException {
+        Array array = mock(Array.class);
+        when(mergeResultSet.getValue(1, Array.class)).thenReturn(array);
+        assertThat(shardingSphereResultSet.getArray("label"), is(array));
+    }
+    
+    @Test
     public void assertGetURLWithColumnIndex() throws SQLException, MalformedURLException {
         when(mergeResultSet.getValue(1, URL.class)).thenReturn(new URL("http://xxx.xxx"));
         assertThat(shardingSphereResultSet.getURL(1), is(new URL("http://xxx.xxx")));
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationResultSetTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationResultSetTest.java
index 83a3000..0c37ab2 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationResultSetTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationResultSetTest.java
@@ -272,21 +272,7 @@ public final class UnsupportedOperationResultSetTest extends AbstractShardingSph
             each.getRef("label");
         }
     }
-    
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetArrayForColumnIndex() throws SQLException {
-        for (ResultSet each : resultSets) {
-            each.getArray(1);
-        }
-    }
-    
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetArrayForColumnLabel() throws SQLException {
-        for (ResultSet each : resultSets) {
-            each.getArray("label");
-        }
-    }
-    
+
     @Test(expected = SQLFeatureNotSupportedException.class)
     public void assertGetRowIdForColumnIndex() throws SQLException {
         for (ResultSet each : resultSets) {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/circuit/resultset/CircuitBreakerResultSet.java b/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/circuit/resultset/CircuitBreakerResultSet.java
index c1e9877..ae31188 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/circuit/resultset/CircuitBreakerResultSet.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/circuit/resultset/CircuitBreakerResultSet.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.driver.orchestration.internal.circuit.resultset;
 
+import java.sql.Array;
 import org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationResultSet;
 
 import java.io.InputStream;
@@ -339,6 +340,16 @@ public final class CircuitBreakerResultSet extends AbstractUnsupportedOperationR
     }
     
     @Override
+    public Array getArray(final int columnIndex) {
+        return null;
+    }
+    
+    @Override
+    public Array getArray(final String columnLabel) {
+        return null;
+    }
+    
+    @Override
     public Blob getBlob(final int columnIndex) {
         return null;
     }