Repository: googleapis/java-spanner-jdbc
Pull request #1525 (2024-03-05 09:35:22)

chore: remove custom type name implementation
Remove the custom type name implementation in the JDBC driver and rely on the implementation in the Java client library.



Patch:
diff --git a/pom.xml b/pom.xml
index f2e14a6..9b9a6fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,7 +62,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>google-cloud-spanner-bom</artifactId>
-        <version>6.60.1</version>
+        <version>6.61.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java
index b56aed0..86281af 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java
@@ -71,65 +71,7 @@ abstract class AbstractJdbcWrapper implements Wrapper {
   }
 
   static String getSpannerTypeName(Type type, Dialect dialect) {
-    // TODO: Use com.google.cloud.spanner.Type#getSpannerTypeName() when available.
-    Preconditions.checkNotNull(type);
-    switch (type.getCode()) {
-      case BOOL:
-        return dialect == Dialect.POSTGRESQL ? "boolean" : "BOOL";
-      case BYTES:
-        return dialect == Dialect.POSTGRESQL ? "bytea" : "BYTES";
-      case DATE:
-        return dialect == Dialect.POSTGRESQL ? "date" : "DATE";
-      case FLOAT64:
-        return dialect == Dialect.POSTGRESQL ? "double precision" : "FLOAT64";
-      case INT64:
-        return dialect == Dialect.POSTGRESQL ? "bigint" : "INT64";
-      case NUMERIC:
-        return "NUMERIC";
-      case PG_NUMERIC:
-        return "numeric";
-      case STRING:
-        return dialect == Dialect.POSTGRESQL ? "character varying" : "STRING";
-      case JSON:
-        return "JSON";
-      case PG_JSONB:
-        return "jsonb";
-      case TIMESTAMP:
-        return dialect == Dialect.POSTGRESQL ? "timestamp with time zone" : "TIMESTAMP";
-      case STRUCT:
-        return "STRUCT";
-      case ARRAY:
-        switch (type.getArrayElementType().getCode()) {
-          case BOOL:
-            return dialect == Dialect.POSTGRESQL ? "boolean[]" : "ARRAY<BOOL>";
-          case BYTES:
-            return dialect == Dialect.POSTGRESQL ? "bytea[]" : "ARRAY<BYTES>";
-          case DATE:
-            return dialect == Dialect.POSTGRESQL ? "date[]" : "ARRAY<DATE>";
-          case FLOAT64:
-            return dialect == Dialect.POSTGRESQL ? "double precision[]" : "ARRAY<FLOAT64>";
-          case INT64:
-            return dialect == Dialect.POSTGRESQL ? "bigint[]" : "ARRAY<INT64>";
-          case NUMERIC:
-            return "ARRAY<NUMERIC>";
-          case PG_NUMERIC:
-            return "numeric[]";
-          case STRING:
-            return dialect == Dialect.POSTGRESQL ? "character varying[]" : "ARRAY<STRING>";
-          case JSON:
-            return "ARRAY<JSON>";
-          case PG_JSONB:
-            return "jsonb[]";
-          case TIMESTAMP:
-            return dialect == Dialect.POSTGRESQL
-                ? "timestamp with time zone[]"
-                : "ARRAY<TIMESTAMP>";
-          case STRUCT:
-            return "ARRAY<STRUCT>";
-        }
-      default:
-        return null;
-    }
+    return Preconditions.checkNotNull(type).getSpannerTypeName(dialect);
   }
 
   /**


Test patch:
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/PartitionedQueryMockServerTest.java b/src/test/java/com/google/cloud/spanner/jdbc/PartitionedQueryMockServerTest.java
index 7144bfa..be5087f 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/PartitionedQueryMockServerTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/PartitionedQueryMockServerTest.java
@@ -158,7 +158,7 @@ public class PartitionedQueryMockServerTest extends AbstractMockServerTest {
         partitionStatement.setBoolean(1, true);
         try (ResultSet results = partitionStatement.executeQuery()) {
           assertNotNull(results.getMetaData());
-          assertEquals(22, results.getMetaData().getColumnCount());
+          assertEquals(24, results.getMetaData().getColumnCount());
           int rowCount = 0;
           while (results.next()) {
             rowCount++;
@@ -376,7 +376,7 @@ public class PartitionedQueryMockServerTest extends AbstractMockServerTest {
       try (ResultSet results =
           connection.createStatement().executeQuery("select * from my_table where active=true")) {
         assertNotNull(results.getMetaData());
-        assertEquals(22, results.getMetaData().getColumnCount());
+        assertEquals(24, results.getMetaData().getColumnCount());
         int rowCount = 0;
         while (results.next()) {
           rowCount++;
@@ -482,7 +482,7 @@ public class PartitionedQueryMockServerTest extends AbstractMockServerTest {
       try (ResultSet results =
           connection.createStatement().executeQuery("select * from my_table where active=true")) {
         assertNotNull(results.getMetaData());
-        assertEquals(22, results.getMetaData().getColumnCount());
+        assertEquals(24, results.getMetaData().getColumnCount());
         int rowCount = 0;
         while (results.next()) {
           rowCount++;