Repository: googleapis/java-spanner-jdbc
Pull request #2036 (2025-05-01 13:50:27)

feat: add UUID data type
Adds metadata for the new UUID data type.

cc @gagangupt16


Patch:
diff --git a/samples/spring-data-mybatis/googlesql/pom.xml b/samples/spring-data-mybatis/googlesql/pom.xml
index b4cc9e0..d57e413 100644
--- a/samples/spring-data-mybatis/googlesql/pom.xml
+++ b/samples/spring-data-mybatis/googlesql/pom.xml
@@ -94,7 +94,7 @@
     <dependency>
       <groupId>com.google.cloud</groupId>
       <artifactId>google-cloud-spanner</artifactId>
-      <version>6.91.1</version>
+      <version>6.92.0</version>
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
index b7fe951..67c6976 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
@@ -1290,6 +1290,44 @@ class JdbcDatabaseMetaData extends AbstractJdbcWrapper implements DatabaseMetaDa
                     .set("NUM_PREC_RADIX")
                     .to(10)
                     .build(),
+                Struct.newBuilder()
+                    .set("TYPE_NAME")
+                    .to("UUID")
+                    .set("DATA_TYPE")
+                    .to(Types.OTHER) // There's no JDBC-specific type code for UUID.
+                    .set("PRECISION")
+                    .to((Long) null)
+                    .set("LITERAL_PREFIX")
+                    .to("UUID ")
+                    .set("LITERAL_SUFFIX")
+                    .to((String) null)
+                    .set("CREATE_PARAMS")
+                    .to((String) null)
+                    .set("NULLABLE")
+                    .to(DatabaseMetaData.typeNullable)
+                    .set("CASE_SENSITIVE")
+                    .to(false)
+                    .set("SEARCHABLE")
+                    .to(DatabaseMetaData.typeSearchable)
+                    .set("UNSIGNED_ATTRIBUTE")
+                    .to(true)
+                    .set("FIXED_PREC_SCALE")
+                    .to(false)
+                    .set("AUTO_INCREMENT")
+                    .to(false)
+                    .set("LOCAL_TYPE_NAME")
+                    .to("UUID")
+                    .set("MINIMUM_SCALE")
+                    .to(0)
+                    .set("MAXIMUM_SCALE")
+                    .to(0)
+                    .set("SQL_DATA_TYPE")
+                    .to((Long) null)
+                    .set("SQL_DATETIME_SUB")
+                    .to((Long) null)
+                    .set("NUM_PREC_RADIX")
+                    .to((Long) null)
+                    .build(),
                 getJsonType(connection.getDialect()))),
         // Allow column 2 to be cast to short without any range checks.
         ImmutableSet.of(2));
diff --git a/src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetColumns.sql b/src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetColumns.sql
index 8509ee0..818b45a 100644
--- a/src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetColumns.sql
+++ b/src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetColumns.sql
@@ -27,6 +27,8 @@ SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME, COLU
     WHEN SPANNER_TYPE LIKE 'STRING%' THEN -9
     WHEN SPANNER_TYPE = 'JSON' THEN -9
     WHEN SPANNER_TYPE = 'TIMESTAMP' THEN 93
+    WHEN SPANNER_TYPE = 'UUID' THEN 1111
+    ELSE 1111
   END AS DATA_TYPE,
   SPANNER_TYPE AS TYPE_NAME,
   CASE


Test patch:
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java
index c8970fd..7dc4667 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java
@@ -510,6 +510,10 @@ public class JdbcDatabaseMetaDataTest {
         assertEquals(Types.NUMERIC, rs.getInt("DATA_TYPE"));
         assertEquals(Types.NUMERIC, rs.getShort("DATA_TYPE"));
         assertTrue(rs.next());
+        assertEquals("UUID", rs.getString("TYPE_NAME"));
+        assertEquals(Types.OTHER, rs.getInt("DATA_TYPE"));
+        assertEquals(Types.OTHER, rs.getShort("DATA_TYPE"));
+        assertTrue(rs.next());
         if (dialect == Dialect.POSTGRESQL) {
           assertEquals("JSONB", rs.getString("TYPE_NAME"));
           assertEquals(PgJsonbType.VENDOR_TYPE_NUMBER, rs.getInt("DATA_TYPE"));