Repository: GoogleCloudPlatform/pgadapter
Pull request #48 (2022-02-28 18:30:53)

build: use the publicly available JDBC driver
Removes the dependency on the private snapshot version of the Cloud
Spanner JDBC driver and instead uses the publicly available JDBC driver
that supports the PostgreSQL dialect.

Also removes the usage of `/*GSQL*/` headers, as those are no longer
supported in the JDBC driver.

olavloite: > LGTM

Thanks for the quick response

Patch:
diff --git a/pom.xml b/pom.xml
index 5e4fb4e2..5623a5b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,8 +26,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.google.cloud</groupId>
   <artifactId>google-cloud-spanner-pgadapter</artifactId>
-  <version>0.1.0-pg-SNAPSHOT
-  </version><!-- {x-version-update:google-cloud-spanner:current} -->
+  <version>0.1.0-pg-SNAPSHOT</version>
   <name>Google Cloud Spanner PostgreSQL Adaptor</name>
   <packaging>jar</packaging>
   <description>
@@ -38,36 +37,6 @@
     developed for PostgreSQL to be used with Spanner.
   </description>
 
-  <!-- artifact repository -->
-  <distributionManagement>
-    <snapshotRepository>
-      <id>artifact-registry</id>
-      <url>
-        artifactregistry://us-west1-maven.pkg.dev/span-cloud-testing/spangres-artifacts
-      </url>
-    </snapshotRepository>
-    <repository>
-      <id>artifact-registry</id>
-      <url>
-        artifactregistry://us-west1-maven.pkg.dev/span-cloud-testing/spangres-artifacts
-      </url>
-    </repository>
-  </distributionManagement>
-  <repositories>
-    <repository>
-      <id>artifact-registry</id>
-      <url>
-        artifactregistry://us-west1-maven.pkg.dev/span-cloud-testing/spangres-artifacts
-      </url>
-      <releases>
-        <enabled>false</enabled>
-      </releases>
-      <snapshots>
-        <enabled>true</enabled>
-      </snapshots>
-    </repository>
-  </repositories>
-
   <dependencies>
     <dependency>
       <groupId>com.googlecode.json-simple</groupId>
@@ -77,7 +46,7 @@
     <dependency>
       <groupId>com.google.cloud</groupId>
       <artifactId>google-cloud-spanner-jdbc</artifactId>
-      <version>2.5.7-pg-SNAPSHOT</version>
+      <version>2.6.0</version>
     </dependency>
     <dependency>
       <groupId>org.postgresql</groupId>
@@ -108,7 +77,7 @@
     <dependency>
       <groupId>com.google.cloud</groupId>
       <artifactId>google-cloud-spanner</artifactId>
-      <version>6.17.4</version>
+      <version>6.20.0</version>
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/statements/CopyStatement.java b/src/main/java/com/google/cloud/spanner/pgadapter/statements/CopyStatement.java
index 1db150f7..719edec5 100644
--- a/src/main/java/com/google/cloud/spanner/pgadapter/statements/CopyStatement.java
+++ b/src/main/java/com/google/cloud/spanner/pgadapter/statements/CopyStatement.java
@@ -34,7 +34,7 @@ import org.apache.commons.csv.CSVFormat;
 public class CopyStatement extends IntermediateStatement {
 
   private static final String COLUMN_NAME = "column_name";
-  private static final String SPANNER_TYPE = "spanner_type";
+  private static final String DATA_TYPE = "data_type";
   private static final String CSV = "CSV";
 
   private CopyTreeParser.CopyOptions options = new CopyTreeParser.CopyOptions();
@@ -153,16 +153,34 @@ public class CopyStatement extends IntermediateStatement {
     this.tableColumns = tempTableColumns;
   }
 
-  private static TypeCode parseSpannerDataType(String columnType) {
-    // Eliminate size modifiers in column type (e.g. STRING(100), BYTES(50), etc.)
+  private static TypeCode parsePostgreSQLDataType(String columnType) {
+    // Eliminate size modifiers in column type (e.g. character varying(100), etc.)
     int index = columnType.indexOf("(");
     columnType = (index > 0) ? columnType.substring(0, index) : columnType;
-    TypeCode type = TypeCode.valueOf(columnType);
-    if (type == null) {
-      throw new IllegalArgumentException(
-          "Unrecognized or unsupported column data type: " + columnType);
+    switch (columnType) {
+      case "boolean":
+        return TypeCode.BOOL;
+      case "bigint":
+        return TypeCode.INT64;
+      case "float8":
+        return TypeCode.FLOAT64;
+      case "numeric":
+        return TypeCode.NUMERIC;
+      case "bytea":
+        return TypeCode.BYTES;
+      case "character varying":
+      case "text":
+        return TypeCode.STRING;
+      case "date":
+        return TypeCode.DATE;
+      case "timestamp with time zone":
+        return TypeCode.TIMESTAMP;
+      case "jsonb":
+        return TypeCode.JSON;
+      default:
+        throw new IllegalArgumentException(
+            "Unrecognized or unsupported column data type: " + columnType);
     }
-    return type;
   }
 
   private void queryInformationSchema() throws SQLException {
@@ -172,17 +190,17 @@ public class CopyStatement extends IntermediateStatement {
     // return GoogleSQL type names.
     PreparedStatement statement =
         this.connection.prepareStatement(
-            "/*GSQL*/SELECT "
+            "SELECT "
                 + COLUMN_NAME
                 + ", "
-                + SPANNER_TYPE
+                + DATA_TYPE
                 + " FROM information_schema.columns WHERE table_name = ?");
     statement.setString(1, getTableName());
     ResultSet result = statement.executeQuery();
 
     while (result.next()) {
       String columnName = result.getString(COLUMN_NAME);
-      TypeCode type = parseSpannerDataType(result.getString(SPANNER_TYPE));
+      TypeCode type = parsePostgreSQLDataType(result.getString(DATA_TYPE));
       tableColumns.put(columnName, type);
     }
 


Test patch:
diff --git a/.ci/e2e-expected/backslash-dn.txt b/.ci/e2e-expected/backslash-dn.txt
index 9dc3f990..b7baca6c 100644
--- a/.ci/e2e-expected/backslash-dn.txt
+++ b/.ci/e2e-expected/backslash-dn.txt
@@ -2,8 +2,7 @@
  catalog_name |    schema_name     | schema_owner | default_character_set_catalog | default_character_set_schema | default_character_set_name | sql_path | effective_timestamp 
 +++++++
  testdb_e2e_psql_v?? | public             |              |                               |                              |                            |          |   
- testdb_e2e_psql_v?? | pg_catalog         |              |                               |                              |                            |          |                    
  testdb_e2e_psql_v?? | information_schema |              |                               |                              |                            |          |
  testdb_e2e_psql_v?? | spanner_sys        |              |                               |                              |                            |          |                    
-(4 rows)
+(3 rows)
 
diff --git a/.ci/e2e-expected/backslash-dt.txt b/.ci/e2e-expected/backslash-dt.txt
index c0be7f63..d7e6a6df 100644
--- a/.ci/e2e-expected/backslash-dt.txt
+++ b/.ci/e2e-expected/backslash-dt.txt
@@ -2,25 +2,7 @@
  table_catalog |    table_schema    |           table_name            | table_type | self_referencing_column_name | reference_generation | user_defined_type_catalog | user_defined_type_schema | user_defined_type_name | is_insertable_into | is_typed | commit_action | parent_table_name | on_delete_action | spanner_state | interleave_type | row_deletion_policy_expression 
 ++++++++++++++++
  testdb_e2e_psql_v?? | public             | users                           | BASE TABLE |                              |                      |                           |                          |                        |                    |          |               |                   |                  | COMMITTED     |                 |
- testdb_e2e_psql_v?? | pg_catalog         | pg_am                           | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_attrdef                      | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_attribute                    | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_class                        | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_collation                    | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_database                     | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_index                        | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_indexes                      | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_inherits                     | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_namespace                    | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_policy                       | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_publication                  | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_publication_rel              | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_roles                        | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_sequence                     | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_statistic_ext                | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_tables                       | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
- testdb_e2e_psql_v?? | pg_catalog         | pg_type                         | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 |
- testdb_e2e_psql_v?? | information_schema | check_constraints               | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
+ testdb_e2e_psql_v?? | information_schema | check_constraints               | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 |
  testdb_e2e_psql_v?? | information_schema | column_column_usage             | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
  testdb_e2e_psql_v?? | information_schema | column_options                  | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
  testdb_e2e_psql_v?? | information_schema | columns                         | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
@@ -65,5 +47,5 @@
  testdb_e2e_psql_v?? | spanner_sys        | txn_stats_total_10minute        | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
  testdb_e2e_psql_v?? | spanner_sys        | txn_stats_total_hour            | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
  testdb_e2e_psql_v?? | spanner_sys        | txn_stats_total_minute          | VIEW       |                              |                      |                           |                          |                        |                    |          |               |                   |                  |               |                 | 
-(64 rows)
+(46 rows)
 
diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java
index 7bb1c705..e82913b5 100644
--- a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java
+++ b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcMockServerTest.java
@@ -129,7 +129,7 @@ public class JdbcMockServerTest extends AbstractMockServerTest {
                             .build())
                     .addFields(
                         Field.newBuilder()
-                            .setName("spanner_type")
+                            .setName("data_type")
                             .setType(Type.newBuilder().setCode(TypeCode.STRING).build())
                             .build())
                     .build())
@@ -139,17 +139,17 @@ public class JdbcMockServerTest extends AbstractMockServerTest {
             .addRows(
                 ListValue.newBuilder()
                     .addValues(Value.newBuilder().setStringValue("id").build())
-                    .addValues(Value.newBuilder().setStringValue("INT64").build())
+                    .addValues(Value.newBuilder().setStringValue("bigint").build())
                     .build())
             .addRows(
                 ListValue.newBuilder()
                     .addValues(Value.newBuilder().setStringValue("age").build())
-                    .addValues(Value.newBuilder().setStringValue("INT64").build())
+                    .addValues(Value.newBuilder().setStringValue("bigint").build())
                     .build())
             .addRows(
                 ListValue.newBuilder()
                     .addValues(Value.newBuilder().setStringValue("name").build())
-                    .addValues(Value.newBuilder().setStringValue("STRING(MAX)").build())
+                    .addValues(Value.newBuilder().setStringValue("character varying").build())
                     .build())
             .setMetadata(metadata)
             .build();
@@ -157,7 +157,7 @@ public class JdbcMockServerTest extends AbstractMockServerTest {
     mockSpanner.putStatementResult(
         StatementResult.query(
             com.google.cloud.spanner.Statement.newBuilder(
-                    "/*GSQL*/SELECT column_name, spanner_type FROM information_schema.columns WHERE table_name = @p1")
+                    "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = @p1")
                 .bind("p1")
                 .to("users")
                 .build(),
diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/ProtocolTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/ProtocolTest.java
index a09ceb63..c1d3a37f 100644
--- a/src/test/java/com/google/cloud/spanner/pgadapter/ProtocolTest.java
+++ b/src/test/java/com/google/cloud/spanner/pgadapter/ProtocolTest.java
@@ -1241,7 +1241,7 @@ public class ProtocolTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);
 
@@ -1357,7 +1357,7 @@ public class ProtocolTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);
 
@@ -1390,7 +1390,7 @@ public class ProtocolTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);
 
@@ -1428,7 +1428,7 @@ public class ProtocolTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);
 
@@ -1468,7 +1468,7 @@ public class ProtocolTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);
 
@@ -1513,7 +1513,7 @@ public class ProtocolTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);
 
diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/StatementTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/StatementTest.java
index c1f20608..77d6a77a 100644
--- a/src/test/java/com/google/cloud/spanner/pgadapter/StatementTest.java
+++ b/src/test/java/com/google/cloud/spanner/pgadapter/StatementTest.java
@@ -444,7 +444,7 @@ public class StatementTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);
 
@@ -476,7 +476,7 @@ public class StatementTest {
 
     ResultSet spannerType = Mockito.mock(ResultSet.class);
     Mockito.when(spannerType.getString("column_name")).thenReturn("key", "value");
-    Mockito.when(spannerType.getString("spanner_type")).thenReturn("INT64", "STRING");
+    Mockito.when(spannerType.getString("data_type")).thenReturn("bigint", "character varying");
     Mockito.when(spannerType.next()).thenReturn(true, true, false);
     Mockito.when(preparedStatement.executeQuery()).thenReturn(spannerType);