You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "laughingman7743 (via GitHub)" <gi...@apache.org> on 2025/02/09 06:44:47 UTC

[PR] [FLINK-37288] Add flink-connector-jdbc-spnner [flink-connector-jdbc]

laughingman7743 opened a new pull request, #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156

   https://issues.apache.org/jira/browse/FLINK-37288


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1986968037


##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -702,7 +708,7 @@ SELECT * FROM given_database.test_table2;
 
 Data Type Mapping
 ----------------
-Flink supports connect to several databases which uses dialect like MySQL, Oracle, PostgreSQL, CrateDB, Derby, SQL Server, Db2 and OceanBase. The Derby dialect usually used for testing purpose. The field data type mappings from relational databases data types to Flink SQL data types are listed in the following table, the mapping table can help define JDBC table in Flink easily.
+Flink supports connect to several databases which uses dialect like MySQL, Oracle, PostgreSQL, CrateDB, Derby, SQL Server, Db2, OceanBase and Spanner. The Derby dialect usually used for testing purpose. The field data type mappings from relational databases data types to Flink SQL data types are listed in the following table, the mapping table can help define JDBC table in Flink easily.

Review Comment:
   nits:
    connect -> the connection
   which uses dialect like -> using dialects e.g.
   The Derby dialect usually used for testing purpose. -> The Derby dialect is usually used for testing purpose.
    JDBC table -> a  JDBC table
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-2888794583

   Does this repository not have an owner? Many PRs adding dialects are being left unreviewed. Does this mean that contributions are not accepted?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-4678464287

   This PR is being marked as stale since it has not had any activity in the last 90 days. 
   If you would like to keep this PR alive, please leave a comment asking for a review. 
   If the PR has merge conflicts, update it with the latest from the base branch.
   
   If you are having difficulty finding a reviewer, please reach out to the 
   community, contact details can be found here: https://flink.apache.org/what-is-flink/community/
   
   If this PR is no longer valid or desired, please feel free to close it. 
   If no activity occurs in the next 30 days, it will be automatically closed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-4779008492

   Follow-up on the root cause above: I filed [FLINK-39975](https://issues.apache.org/jira/browse/FLINK-39975) and opened https://github.com/apache/flink-connector-jdbc/pull/200 to fix the flaky `DerbyDynamicTableSourceITCase.testLimit`.
   
   The fix makes `JdbcSourceSplitReader` recover from a connection that is closed while opening a split during source cancellation: it re-establishes the connection and retries the split-open (bounded, mirroring the retry/reconnect handling in `JdbcOutputFormat.flush()`). It is non-masking — a genuine query error on a healthy connection is rethrown immediately, and an unreachable database still fails the job after the retry budget. A deterministic regression test reproduces the exact `08003 "No current connection"` error (the test fails without the fix and passes with it).
   
   Once #200 lands on `main`, this flaky test should stop reddening unrelated PRs (including this one).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-5932783079

   @MartijnVisser I've rebased onto the latest main to resolve the conflicts. The history is still the same 5 commits. Following FLINK-40781, the Spanner module now has its own ArchUnit tests:
   
   - Added `ProductionCodeArchitectureTest`, `TestCodeArchitectureTest` and `archunit.properties`, the same as in the other modules. The store is frozen on Flink 2.1.3 with JDK 17.
   - Fixed the violations where possible. `SpannerCatalog.getSpannerOptions` no longer has `@VisibleForTesting`, since production code calls it. `SpannerDialectConverter` now gets the precision from `TimestampType`/`LocalZonedTimestampType` instead of the internal `LogicalTypeChecks.getPrecision`.
   - Only two violations remain frozen, and both follow existing patterns: the `@VisibleForTesting` catalog constructor (as in `PostgresCatalog` and `MySqlCatalog`) and `LogicalTypeUtils.toInternalConversionClass` in the array converter (as in `PostgresDialectConverter`).
   - In the core store, I updated the existing entry for the `AbstractJdbcCatalog` → `AbstractCatalog` constructor call to point to the new constructor that takes the default database resolver. It is the same violation as before, now in the new constructor.
   
   The core and Spanner tests, including ArchUnit, pass locally against both Flink 2.1.3 and 2.3.0. Could you please approve the CI run again? Thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r2553228223


##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/statement/FieldNamedPreparedStatementImpl.java:
##########
@@ -170,6 +174,18 @@ public void setObject(int fieldIndex, Object x) throws SQLException {
         }
     }
 
+    @Override
+    public void setArray(int fieldIndex, Array x) throws SQLException {
+        for (int index : indexMapping[fieldIndex]) {
+            statement.setArray(index, x);
+        }
+    }
+
+    @Override
+    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+        return connection.createArrayOf(typeName, elements);
+    }

Review Comment:
   This implementation introduces the first full ARRAY type write support in the
   flink-connector-jdbc project. Currently, PostgreSQL dialect only supports reading
   ARRAY types (throws `IllegalStateException` on write - see
   [PostgresDialectConverter.java:61-67](https://github.com/apache/flink-connector-jdbc/blob/v4.0.0/flink-connector-jdbc-postgres/src/main/java/org/apache/flink/connector/jdbc/postgres/database/dialect/PostgresDialectConverter.java#L61-L67)).
   
   If this change is merged, the implementation pattern here could serve as a reference
   for adding ARRAY write support to PostgreSQL and other dialects in the future.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-5797418837

   @MartijnVisser Thanks for approving the CI run. The Flink 2.3.0 job failed in `SpannerDynamicTableSinkITCase`, which I've fixed and force-pushed. The history is still the same 5 commits.
   
   **Cause:** Since Flink 2.3.0 (FLIP-558), writing insert-only data into a sink table with a primary key requires an `ON CONFLICT` clause. Spanner tables always have a primary key, so `testAppend`, `testReal`, `testArray` and `testTimestampLtzWithNonUtcDefaultTimeZone` hit the new validation. FLINK-40725 only adjusted the tests of other dialects, and I had only run the tests locally against the default Flink 2.1.3, so I missed this.
   
   **Fix (tests only):**
   - `JdbcDynamicTableSinkITCase` (core): made `isFlip558Enabled()` protected and added an `appendOnConflictClause()` hook that `testAppend` appends to its INSERT statement. It returns an empty string by default, so dialects whose append output table has no primary key are unaffected. Their `testAppend` already passed on Flink 2.3.0 in this CI run.
   - `SpannerDynamicTableSinkITCase`: overrides the hook to return ` ON CONFLICT DO DEDUPLICATE` on Flink >= 2.3, the same clause as FLINK-40725, and uses it in the Spanner-specific sink tests.
   
   The core, Spanner and architecture tests now pass locally against both Flink 2.1.3 and 2.3.0.
   
   The other failures in that run were not caused by this PR. The Flink 2.1.3 and 2.2.1 jobs were cancelled by fail-fast after the 2.3.0 job failed, and `backwards_compatibility_test (2.0-SNAPSHOT)` failed because Maven Central returned a transient `500 Internal Server Error` while resolving `maven-compiler-plugin`.
   
   Could you please approve the workflow run again? Thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r2459207498


##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -45,17 +45,18 @@ See how to link with it for cluster execution [here]({{< ref "docs/dev/configura
 
 A driver dependency is also required to connect to a specified database. Here are drivers currently supported:
 
-| Driver     | Group Id                   | Artifact Id            | JAR                                                                                                                               |
-|:-----------|:---------------------------|:-----------------------|:----------------------------------------------------------------------------------------------------------------------------------|
-| MySQL      | `mysql`                    | `mysql-connector-java` | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                      |
-| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`               | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                    |
-| PostgreSQL | `org.postgresql`           | `postgresql`           | [Download](https://jdbc.postgresql.org/download/)                                                                                 |
-| Derby      | `org.apache.derby`         | `derby`                | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                       |
-| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`           | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16) |
-| CrateDB    | `io.crate`                 | `crate-jdbc`           | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                   |
-| Db2        | `com.ibm.db2.jcc`          | `db2jcc`               | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                           | 
-| Trino      | `io.trino`                 | `trino-jdbc`           | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                   |
-| OceanBase  | `com.oceanbase`            | `oceanbase-client`     | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                        |
+| Driver     | Group Id                   | Artifact Id                 | JAR                                                                                                                                     |
+|:-----------|:---------------------------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------|
+| MySQL      | `mysql`                    | `mysql-connector-java`      | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                            |
+| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`                    | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                          |
+| PostgreSQL | `org.postgresql`           | `postgresql`                | [Download](https://jdbc.postgresql.org/download/)                                                                                       |
+| Derby      | `org.apache.derby`         | `derby`                     | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                             |
+| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`                | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16)       |
+| CrateDB    | `io.crate`                 | `crate-jdbc`                | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                         |
+| Db2        | `com.ibm.db2.jcc`          | `db2jcc`                    | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                                 | 
+| Trino      | `io.trino`                 | `trino-jdbc`                | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                         |
+| OceanBase  | `com.oceanbase`            | `oceanbase-client`          | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                              |
+| Spanner    | `com.google.cloud`         | `google-cloud-spanner-jdbc` | [Download](https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner-jdbc)                                            |

Review Comment:
   https://repo1.maven.org/maven2/com/google/cloud/google-cloud-spanner-jdbc/2.27.1/google-cloud-spanner-jdbc-2.27.1-single-jar-with-dependencies.jar
   It is necessary to use a single JAR file that includes dependencies.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser merged PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-5795819708

   @MartijnVisser Thanks a lot for the thorough review! I've rebased onto the latest main and addressed all comments. As requested, the history is now 5 commits, all prefixed with `[FLINK-37288][jdbc]`. The 3 core changes each have their own commit, followed by the Spanner module and the docs.
   
   Besides the review items, I bumped `google-cloud-spanner-jdbc` from 2.26.1 to 2.44.0 and the emulator image to 1.5.58. Two things were needed for the new driver:
   - Newer drivers return parameterized type names such as `ARRAY<BOOL>` from `getColumnTypeName`, so the catalog type mapper now strips the type parameters.
   - Since 2.32.0, all connections share a single multiplexed session. The emulator only supports one read-write transaction at a time, so `testUpsert` failed with parallel sink subtasks on the emulator. The Spanner ITCase now runs that test with parallelism 1. This limitation is specific to the emulator; real Spanner supports concurrent transactions on multiplexed sessions.
   
   Locally, the core, Spanner and architecture tests pass on JDK 17. Could you please approve the CI workflow when you have a chance?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r2527584940


##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/database/catalog/AbstractJdbcCatalog.java:
##########
@@ -125,21 +125,27 @@ public AbstractJdbcCatalog(
         checkNotNull(userClassLoader);
         checkArgument(!StringUtils.isNullOrWhitespaceOnly(baseUrl));
 
-        validateJdbcUrl(baseUrl);
-
         this.userClassLoader = userClassLoader;
+        this.connectionProperties = Preconditions.checkNotNull(connectionProperties);
         this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
         this.defaultUrl = getDatabaseUrl(defaultDatabase);
-        this.connectionProperties = Preconditions.checkNotNull(connectionProperties);
-        checkArgument(
-                !StringUtils.isNullOrWhitespaceOnly(connectionProperties.getProperty(USER_KEY)));
-        checkArgument(
-                !StringUtils.isNullOrWhitespaceOnly(
-                        connectionProperties.getProperty(PASSWORD_KEY)));
     }
 
     protected String getDatabaseUrl(String databaseName) {
-        return baseUrl + databaseName;
+        // Check if base-url contains query parameters
+        int questionMarkIndex = baseUrl.indexOf('?');
+
+        if (questionMarkIndex == -1) {
+            // No parameters: traditional baseUrl + databaseName
+            return baseUrl + databaseName;
+        }
+
+        // Parameters present: insert database name before '?'
+        // Example: "jdbc:postgresql://localhost:5432/?sslmode=require"
+        //       -> "jdbc:postgresql://localhost:5432/mydb?sslmode=require"
+        String urlWithoutParams = baseUrl.substring(0, questionMarkIndex);
+        String params = baseUrl.substring(questionMarkIndex);
+        return urlWithoutParams + databaseName + params;

Review Comment:
   For Spanner tests, it is necessary to configure `autoConfigEmulator` to automatically set up the emulator. This enables parameter passing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1948021405


##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/database/catalog/AbstractJdbcCatalog.java:
##########
@@ -125,17 +125,10 @@ public AbstractJdbcCatalog(
         checkNotNull(userClassLoader);
         checkArgument(!StringUtils.isNullOrWhitespaceOnly(baseUrl));
 
-        validateJdbcUrl(baseUrl);
-
         this.userClassLoader = userClassLoader;
+        this.connectionProperties = Preconditions.checkNotNull(connectionProperties);
         this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
         this.defaultUrl = getDatabaseUrl(defaultDatabase);
-        this.connectionProperties = Preconditions.checkNotNull(connectionProperties);
-        checkArgument(
-                !StringUtils.isNullOrWhitespaceOnly(connectionProperties.getProperty(USER_KEY)));
-        checkArgument(
-                !StringUtils.isNullOrWhitespaceOnly(
-                        connectionProperties.getProperty(PASSWORD_KEY)));

Review Comment:
   Spanner does not use password authentication.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-5852298046

   @MartijnVisser I've addressed the three points from your latest review (the shaded driver jar in the docs, `TIMESTAMP_LTZ(9)` for Spanner `TIMESTAMP`, and the Javadoc on the constructor-called hooks), and CI is green on c6261a5.
   
   Is there anything else you'd like me to change before this can be merged? This PR has been open since February 2025, so I'd love to see it land. Would it be possible to target the next release after 4.1.0?
   
   Thanks again for the thorough reviews!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1986988707


##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -45,17 +45,18 @@ See how to link with it for cluster execution [here]({{< ref "docs/dev/configura
 
 A driver dependency is also required to connect to a specified database. Here are drivers currently supported:
 
-| Driver     | Group Id                   | Artifact Id            | JAR                                                                                                                               |
-|:-----------|:---------------------------|:-----------------------|:----------------------------------------------------------------------------------------------------------------------------------|
-| MySQL      | `mysql`                    | `mysql-connector-java` | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                      |
-| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`               | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                    |
-| PostgreSQL | `org.postgresql`           | `postgresql`           | [Download](https://jdbc.postgresql.org/download/)                                                                                 |
-| Derby      | `org.apache.derby`         | `derby`                | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                       |
-| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`           | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16) |
-| CrateDB    | `io.crate`                 | `crate-jdbc`           | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                   |
-| Db2        | `com.ibm.db2.jcc`          | `db2jcc`               | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                           | 
-| Trino      | `io.trino`                 | `trino-jdbc`           | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                   |
-| OceanBase  | `com.oceanbase`            | `oceanbase-client`     | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                        |
+| Driver     | Group Id                   | Artifact Id                 | JAR                                                                                                                                     |
+|:-----------|:---------------------------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------|
+| MySQL      | `mysql`                    | `mysql-connector-java`      | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                            |
+| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`                    | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                          |
+| PostgreSQL | `org.postgresql`           | `postgresql`                | [Download](https://jdbc.postgresql.org/download/)                                                                                       |
+| Derby      | `org.apache.derby`         | `derby`                     | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                             |
+| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`                | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16)       |
+| CrateDB    | `io.crate`                 | `crate-jdbc`                | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                         |
+| Db2        | `com.ibm.db2.jcc`          | `db2jcc`                    | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                                 | 
+| Trino      | `io.trino`                 | `trino-jdbc`                | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                         |
+| OceanBase  | `com.oceanbase`            | `oceanbase-client`          | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                              |
+| Spanner    | `com.google.cloud`         | `google-cloud-spanner-jdbc` | [Download](https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner-jdbc)                                            |

Review Comment:
   I have written the same URL as the official document.
   - https://cloud.google.com/spanner/docs/jdbc-drivers
   
   The Jar files can be downloaded from the following.
   - https://repo1.maven.org/maven2/com/google/cloud/google-cloud-spanner-jdbc/2.27.1/
   - https://repo1.maven.org/maven2/com/google/cloud/google-cloud-spanner-jdbc/2.27.1/google-cloud-spanner-jdbc-2.27.1-single-jar-with-dependencies.jar
   - https://repo1.maven.org/maven2/com/google/cloud/google-cloud-spanner-jdbc/2.27.1/google-cloud-spanner-jdbc-2.27.1.jar
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1948022033


##########
flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/testutils/tables/TableBase.java:
##########
@@ -120,7 +122,7 @@ public int[] getTableTypes() {
                 .toArray();
     }
 
-    public Schema getTableSchema() {
+    public Schema getTableSchema(String pkConstraintName) {

Review Comment:
   In the case of Spanner, the contract name of the primary key is different, so it is possible to specify the contract name of the primary key.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-4774360513

   Hi @RocMarshal, thanks for taking a look!
   
   I've run `mvn spotless:apply` and pushed the fix (the violation was a comment line in `SpannerCatalog.java` exceeding the line-length limit). I also rebased the branch onto the latest main. `spotless:check` now passes for all modules locally.
   
   It looks like the CI needs maintainer approval to run — could you kindly approve the workflow when you have a chance? Thanks again for the review! 🙏


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r4083013616


##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/dialect/SpannerDialectConverter.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialectConverter;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils;
+
+import java.lang.reflect.Array;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.LocalDateTime;
+
+/**
+ * Runtime converter that responsible to convert between JDBC object and Flink internal object for
+ * Spanner.
+ */
+@Internal
+public class SpannerDialectConverter extends AbstractDialectConverter {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public String converterName() {
+        return "Spanner";
+    }
+
+    public SpannerDialectConverter(RowType rowType) {
+        super(rowType);
+    }
+
+    @Override
+    protected JdbcDeserializationConverter createInternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            return createSpannerArrayConverter(arrayType);
+        } else if (root == LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
+            // Spanner has a single TIMESTAMP type (an absolute instant); treat TIMESTAMP_LTZ as a
+            // plain timestamp value, mirroring how TIMESTAMP_WITHOUT_TIME_ZONE is handled.
+            return val ->
+                    val instanceof LocalDateTime
+                            ? TimestampData.fromLocalDateTime((LocalDateTime) val)
+                            : TimestampData.fromTimestamp((Timestamp) val);
+        } else {
+            return super.createInternalConverter(type);
+        }
+    }
+
+    @Override
+    protected JdbcSerializationConverter createNullableExternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+        if (root == LogicalTypeRoot.ARRAY) {

Review Comment:
   Good catch. Arrays are now handled in `createExternalConverter`, so the parent's nullable wrapper takes care of NULL arrays. Added a row with NULL arrays to `SpannerDynamicTableSinkITCase#testArray`.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/dialect/SpannerDialectConverter.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialectConverter;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils;
+
+import java.lang.reflect.Array;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.LocalDateTime;
+
+/**
+ * Runtime converter that responsible to convert between JDBC object and Flink internal object for
+ * Spanner.
+ */
+@Internal
+public class SpannerDialectConverter extends AbstractDialectConverter {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public String converterName() {
+        return "Spanner";
+    }
+
+    public SpannerDialectConverter(RowType rowType) {
+        super(rowType);
+    }
+
+    @Override
+    protected JdbcDeserializationConverter createInternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            return createSpannerArrayConverter(arrayType);
+        } else if (root == LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
+            // Spanner has a single TIMESTAMP type (an absolute instant); treat TIMESTAMP_LTZ as a
+            // plain timestamp value, mirroring how TIMESTAMP_WITHOUT_TIME_ZONE is handled.
+            return val ->
+                    val instanceof LocalDateTime
+                            ? TimestampData.fromLocalDateTime((LocalDateTime) val)
+                            : TimestampData.fromTimestamp((Timestamp) val);
+        } else {
+            return super.createInternalConverter(type);
+        }
+    }
+
+    @Override
+    protected JdbcSerializationConverter createNullableExternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            LogicalType elementType = arrayType.getElementType();
+            String typeName = getSpannerArrayTypeName(elementType);
+
+            return (val, index, statement) -> {
+                ArrayData arrayData = val.getArray(index);
+                int size = arrayData.size();
+                Object[] elements = new Object[size];
+
+                // Convert each element
+                for (int i = 0; i < size; i++) {
+                    elements[i] = extractArrayElement(arrayData, i, elementType);
+                }
+
+                // Create JDBC Array and set it
+                java.sql.Array jdbcArray = statement.createArrayOf(typeName, elements);
+                statement.setArray(index, jdbcArray);
+            };
+        } else if (root == LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
+            // Spanner stores TIMESTAMP as an absolute instant; write TIMESTAMP_LTZ like a plain
+            // timestamp. JdbcTypeUtil has no mapping for TIMESTAMP_LTZ, so the null branch is
+            // handled here with Types.TIMESTAMP instead of the parent's nullable wrapper.
+            final int precision = LogicalTypeChecks.getPrecision(type);
+            return (val, index, statement) -> {
+                if (val == null || val.isNullAt(index)) {
+                    statement.setNull(index, Types.TIMESTAMP);
+                } else {
+                    statement.setTimestamp(index, val.getTimestamp(index, precision).toTimestamp());

Review Comment:
   Thanks, reproduced exactly as described (stored as `1969-12-31T15:00:00Z` under `Asia/Tokyo`). TIMESTAMP_LTZ is now written with `Timestamp.from(toInstant())` and read with `TimestampData.fromInstant`, including array elements. Added `testTimestampLtzWithNonUtcDefaultTimeZone`, which fails without the fix.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/dialect/SpannerDialect.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialect;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/** JDBC dialect for Spanner. */
+@Internal
+public class SpannerDialect extends AbstractDialect {
+
+    private static final long serialVersionUID = 1L;
+
+    // Define MAX/MIN precision of TIMESTAMP type according to Spanner docs:
+    // https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#timestamp_type
+    private static final int MAX_TIMESTAMP_PRECISION = 9;
+    private static final int MIN_TIMESTAMP_PRECISION = 0;
+
+    // Define MAX/MIN precision of DECIMAL type according to Spanner docs:
+    // https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#decimal_types
+    private static final int MAX_DECIMAL_PRECISION = 38;
+    private static final int MIN_DECIMAL_PRECISION = 0;
+
+    @Override
+    public SpannerDialectConverter getRowConverter(RowType rowType) {
+        return new SpannerDialectConverter(rowType);
+    }
+
+    @Override
+    public Optional<String> defaultDriverName() {
+        return Optional.of("com.google.cloud.spanner.jdbc.JdbcDriver");
+    }
+
+    @Override
+    public String dialectName() {
+        return "Spanner";
+    }
+
+    @Override
+    public String getLimitClause(long limit) {
+        return "LIMIT " + limit;
+    }
+
+    /** Spanner upsert query using INSERT OR UPDATE INTO syntax. */
+    @Override
+    public Optional<String> getUpsertStatement(
+            String tableName, String[] fieldNames, String[] uniqueKeyFields) {
+        String columns =
+                Arrays.stream(fieldNames)
+                        .map(this::quoteIdentifier)
+                        .collect(Collectors.joining(", "));
+        String placeholders =
+                Arrays.stream(fieldNames).map(f -> ":" + f).collect(Collectors.joining(", "));
+        return Optional.of(
+                "INSERT OR UPDATE INTO "
+                        + quoteIdentifier(tableName)
+                        + "("
+                        + columns
+                        + ")"
+                        + " VALUES ("
+                        + placeholders
+                        + ")");
+    }
+
+    @Override
+    public String quoteIdentifier(String identifier) {
+        // Spanner (GoogleSQL) quotes identifiers with backticks. Quote each dot-separated component
+        // so schema-qualified names (e.g. "my_schema.my_table") stay valid.
+        return Arrays.stream(identifier.split("\\."))
+                .map(part -> "`" + part + "`")
+                .collect(Collectors.joining("."));
+    }
+
+    @Override
+    public Optional<Range> decimalPrecisionRange() {
+        return Optional.of(Range.of(MIN_DECIMAL_PRECISION, MAX_DECIMAL_PRECISION));
+    }
+
+    @Override
+    public Optional<Range> timestampPrecisionRange() {
+        return Optional.of(Range.of(MIN_TIMESTAMP_PRECISION, MAX_TIMESTAMP_PRECISION));
+    }
+
+    @Override
+    public Set<LogicalTypeRoot> supportedTypes() {
+        // The data types used in Spanner are list at:
+        // https://cloud.google.com/spanner/docs/reference/standard-sql/data-types
+
+        // TODO: We can't convert BINARY data type to
+        //  PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO in
+        // LegacyTypeInfoDataTypeConverter.
+
+        return EnumSet.of(
+                LogicalTypeRoot.CHAR,
+                LogicalTypeRoot.VARCHAR,
+                LogicalTypeRoot.BOOLEAN,
+                LogicalTypeRoot.VARBINARY,
+                LogicalTypeRoot.DECIMAL,
+                LogicalTypeRoot.TINYINT,

Review Comment:
   Went with narrowing in `createInternalConverter`: TINYINT/SMALLINT/INTEGER values are narrowed from the INT64 `Long`, and out-of-range values fail with an `ArithmeticException` instead of being silently truncated. The source ITCase now reads INT/SMALLINT/TINYINT columns with their min/max values.



##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/statement/FieldNamedPreparedStatement.java:
##########
@@ -254,6 +255,21 @@ static FieldNamedPreparedStatement prepareStatement(
      */
     void setObject(int fieldIndex, Object x) throws SQLException;
 
+    /**
+     * Sets the designated parameter to the given <code>java.sql.Array</code> object. The driver
+     * converts this to an SQL <code>ARRAY</code> value when it sends it to the database.
+     *
+     * @see PreparedStatement#setArray(int, Array)
+     */
+    void setArray(int fieldIndex, Array x) throws SQLException;

Review Comment:
   Both are now default methods throwing `SQLFeatureNotSupportedException`, so existing implementors are unaffected. `FieldNamedPreparedStatementImpl` implements them, and `createArrayOf` goes through `statement.getConnection()`; the extra connection field is gone.



##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/database/catalog/AbstractJdbcCatalog.java:
##########
@@ -130,7 +130,30 @@ public AbstractJdbcCatalog(
             String defaultDatabase,
             String baseUrl,
             Properties connectionProperties) {
-        super(catalogName, validateJdbcUrl(baseUrl, defaultDatabase));
+        this(
+                userClassLoader,
+                catalogName,
+                validateJdbcUrl(baseUrl, defaultDatabase),
+                baseUrl,
+                connectionProperties,
+                false);
+    }
+
+    /**
+     * Protected constructor that allows subclasses to skip URL validation. Subclasses with
+     * non-standard JDBC URL formats (e.g., Spanner's deep path structure) can use this constructor
+     * to provide the default database directly without going through {@link #validateJdbcUrl}.
+     *
+     * @param skipUrlValidation unused, exists only to differentiate the constructor signature
+     */
+    protected AbstractJdbcCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String defaultDatabase,
+            String baseUrl,
+            Properties connectionProperties,
+            boolean skipUrlValidation) {

Review Comment:
   Replaced the flag with a protected constructor that takes a `BiFunction<String, String, String>` default database resolver. Since `AbstractCatalog` validates the default database in its constructor, the resolution has to happen before `super(...)`, so an overridable instance method was not an option. The public constructors pass `AbstractJdbcCatalog::validateJdbcUrl`, and `SpannerCatalog` passes its own static resolver.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/catalog/SpannerCatalog.java:
##########
@@ -0,0 +1,345 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.catalog;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.connector.jdbc.core.database.catalog.AbstractJdbcCatalog;
+import org.apache.flink.connector.jdbc.core.database.catalog.JdbcCatalogTypeMapper;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.UniqueConstraint;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.StringUtils;
+
+import com.google.cloud.spanner.Spanner;
+import com.google.cloud.spanner.SpannerOptions;
+import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
+import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPage;
+import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse;
+import com.google.cloud.spanner.connection.ConnectionOptions;
+import com.google.spanner.admin.database.v1.Database;
+import com.google.spanner.admin.database.v1.InstanceName;
+import org.apache.commons.compress.utils.Lists;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+import java.util.function.Function;
+
+import static org.apache.flink.connector.jdbc.JdbcConnectionOptions.getBriefAuthProperties;
+
+/** Catalog for Spanner. */
+@Internal
+public class SpannerCatalog extends AbstractJdbcCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SpannerCatalog.class);
+
+    private static final Set<String> builtinSchemas =
+            new HashSet<String>() {
+                {
+                    add("INFORMATION_SCHEMA");
+                    add("SPANNER_SYS");
+                }
+            };
+
+    private final JdbcCatalogTypeMapper dialectTypeMapper;
+
+    @VisibleForTesting
+    public SpannerCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String defaultDatabase,
+            String username,
+            String pwd,
+            String baseUrl) {
+        this(
+                userClassLoader,
+                catalogName,
+                defaultDatabase,
+                baseUrl,
+                getBriefAuthProperties(username, pwd));
+    }
+
+    public SpannerCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String defaultDatabase,
+            String baseUrl,
+            Properties connectProperties) {
+        // Use the protected constructor to skip validateJdbcUrl, which does not support
+        // Spanner's deep path URL structure (e.g., /projects/.../databases/).
+        super(userClassLoader, catalogName, defaultDatabase, baseUrl, connectProperties, true);
+        this.dialectTypeMapper = new SpannerTypeMapper();
+    }
+
+    @Override
+    protected Function<String, String> calculateUrlFunction(String url) {
+        // Spanner JDBC URLs use semicolons for parameters instead of question marks.
+        // Example: "jdbc:cloudspanner://host/.../databases/;autoConfigEmulator=true"
+        //       -> urlFunction("mydb") ->
+        // "jdbc:cloudspanner://host/.../databases/mydb;autoConfigEmulator=true"
+        int semiColonIndex = url.indexOf(';');
+        if (semiColonIndex == -1) {
+            // No semicolon params
+            String trimmed = url.trim();
+            String prefix = trimmed.endsWith("/") ? trimmed : trimmed + "/";
+            return dbName -> prefix + dbName;
+        }
+        // Has semicolon params: split into prefix and params
+        String urlWithoutParams = url.substring(0, semiColonIndex);
+        String params = url.substring(semiColonIndex);
+        String prefix = urlWithoutParams.endsWith("/") ? urlWithoutParams : urlWithoutParams + "/";
+        return dbName -> prefix + dbName + params;
+    }
+
+    @Override
+    protected void validateConnectionProperties(Properties connectionProperties) {
+        // Spanner uses Google Cloud credentials, not traditional username/password.
+        // Skip the parent's USER_KEY/PASSWORD_KEY validation.
+    }
+
+    private ConnectionOptions getConnectionOptions() {
+        return ConnectionOptions.newBuilder().setUri(defaultUrl.replace("jdbc:", "")).build();
+    }
+
+    private SpannerOptions getSpannerOptions(ConnectionOptions options) {
+        SpannerOptions.Builder builder =
+                SpannerOptions.newBuilder().setProjectId(options.getProjectId());

Review Comment:
   `getSpannerOptions` now sets `options.getCredentials()`, so the admin client uses the same credentials as the JDBC connections (the application default credentials when none are configured, `NoCredentials` for the emulator). Added unit tests for `;credentials=<key file>` and `;oauthToken=...`.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/lineage/SpannerLocationExtractorFactory.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.lineage;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.lineage.JdbcLocationExtractorFactory;
+
+import io.openlineage.client.utils.jdbc.JdbcExtractor;
+import io.openlineage.client.utils.jdbc.OverridingJdbcExtractor;
+
+/** Implementation of {@link JdbcLocationExtractorFactory} for Spanner. */
+@Internal
+public class SpannerLocationExtractorFactory implements JdbcLocationExtractorFactory {
+
+    @Override
+    public JdbcExtractor createExtractor() {
+        // TODO: Replace with SpannerJdbcExtractor when OpenLineage adds native Spanner support
+        return new OverridingJdbcExtractor("cloudspanner", "9010");

Review Comment:
   Replaced `OverridingJdbcExtractor` with a `SpannerJdbcExtractor`. It follows the OpenLineage naming convention `spanner://{projectId}:{instanceId}` and appends the database, e.g. `spanner://my-project:my-instance/my-db`, since the connector only uses the table name as the dataset name. Added `SpannerJdbcExtractorTest` covering the default host, `spanner.googleapis.com`, the emulator, and a base-url without a database.



##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -481,7 +486,8 @@ The JDBC catalog supports the following options:
 - `base-url`: required (should not contain the database name)
   - for Postgres Catalog this should be `"jdbc:postgresql://<ip>:<port>"`
   - for MySQL Catalog this should be `"jdbc:mysql://<ip>:<port>"`
-  - for OceanBase Catalog this should be `jdbc:oceanbase://<ip>:<port>`
+  - for OceanBase Catalog this should be `"jdbc:oceanbase://<ip>:<port>"`
+  - for Spanner Catalog this should be `"jdbc:cloudspanner:/projects/<project>/instances/<instance>/databases/<database>"`

Review Comment:
   Fixed in both en and zh: the base-url now ends with `/databases/`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-2646358956

   I have applied code formatting using Spotless and updated the documentation. It is ready for review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1986996966


##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -702,7 +708,7 @@ SELECT * FROM given_database.test_table2;
 
 Data Type Mapping
 ----------------
-Flink supports connect to several databases which uses dialect like MySQL, Oracle, PostgreSQL, CrateDB, Derby, SQL Server, Db2 and OceanBase. The Derby dialect usually used for testing purpose. The field data type mappings from relational databases data types to Flink SQL data types are listed in the following table, the mapping table can help define JDBC table in Flink easily.
+Flink supports connect to several databases which uses dialect like MySQL, Oracle, PostgreSQL, CrateDB, Derby, SQL Server, Db2, OceanBase and Spanner. The Derby dialect usually used for testing purpose. The field data type mappings from relational databases data types to Flink SQL data types are listed in the following table, the mapping table can help define JDBC table in Flink easily.

Review Comment:
   Fixed: https://github.com/apache/flink-connector-jdbc/pull/156/commits/3c7d2258ab0fe8bf56a60722de09b6c7e00c5350



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r2529393874


##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/statement/FieldNamedPreparedStatementImpl.java:
##########
@@ -170,6 +174,18 @@ public void setObject(int fieldIndex, Object x) throws SQLException {
         }
     }
 
+    @Override
+    public void setArray(int fieldIndex, Array x) throws SQLException {
+        for (int index : indexMapping[fieldIndex]) {
+            statement.setArray(index, x);
+        }
+    }
+
+    @Override
+    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+        return connection.createArrayOf(typeName, elements);
+    }

Review Comment:
   These implementations are necessary to support writing to Array types.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-4678547153

   Rebased onto the latest main to resolve the stale status. This PR is still active and awaiting review. Any feedback would be greatly appreciated.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r4083015939


##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -887,6 +902,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
         <code>TINYINT(1)</code></td>
       <td></td>
       <td><code>BOOLEAN</code></td>
+      <td><code>BOOLEAN</code></td>

Review Comment:
   Fixed in both en and zh. While checking the table, I also found that the TIMESTAMP WITH TIMEZONE row was missing its Spanner cell, so I added it. I also removed the incorrect `NUMERIC` entry for BIGINT UNSIGNED and changed `TIMESTAMP [(p)]` to `TIMESTAMP`. Every row now has 11 cells.



##########
flink-connector-jdbc-spanner/pom.xml:
##########
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>

Review Comment:
   Added the ASF headers to `pom.xml` and `SpannerTableRow.java`, and switched to `testcontainers-jdbc`. The gcloud module turned out to be unused (the tests use their own `SpannerEmulatorJdbcContainer`), so I dropped it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add flink-connector-jdbc-spnner [flink-connector-jdbc]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-2646096018

   Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1986961532


##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -45,17 +45,18 @@ See how to link with it for cluster execution [here]({{< ref "docs/dev/configura
 
 A driver dependency is also required to connect to a specified database. Here are drivers currently supported:
 
-| Driver     | Group Id                   | Artifact Id            | JAR                                                                                                                               |
-|:-----------|:---------------------------|:-----------------------|:----------------------------------------------------------------------------------------------------------------------------------|
-| MySQL      | `mysql`                    | `mysql-connector-java` | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                      |
-| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`               | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                    |
-| PostgreSQL | `org.postgresql`           | `postgresql`           | [Download](https://jdbc.postgresql.org/download/)                                                                                 |
-| Derby      | `org.apache.derby`         | `derby`                | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                       |
-| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`           | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16) |
-| CrateDB    | `io.crate`                 | `crate-jdbc`           | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                   |
-| Db2        | `com.ibm.db2.jcc`          | `db2jcc`               | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                           | 
-| Trino      | `io.trino`                 | `trino-jdbc`           | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                   |
-| OceanBase  | `com.oceanbase`            | `oceanbase-client`     | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                        |
+| Driver     | Group Id                   | Artifact Id                 | JAR                                                                                                                                     |
+|:-----------|:---------------------------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------|
+| MySQL      | `mysql`                    | `mysql-connector-java`      | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                            |
+| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`                    | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                          |
+| PostgreSQL | `org.postgresql`           | `postgresql`                | [Download](https://jdbc.postgresql.org/download/)                                                                                       |
+| Derby      | `org.apache.derby`         | `derby`                     | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                             |
+| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`                | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16)       |
+| CrateDB    | `io.crate`                 | `crate-jdbc`                | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                         |
+| Db2        | `com.ibm.db2.jcc`          | `db2jcc`                    | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                                 | 
+| Trino      | `io.trino`                 | `trino-jdbc`                | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                         |
+| OceanBase  | `com.oceanbase`            | `oceanbase-client`          | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                              |
+| Spanner    | `com.google.cloud`         | `google-cloud-spanner-jdbc` | [Download](https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner-jdbc)                                            |

Review Comment:
   I see the download url points to Maven like the spanner doc. How do I get the jar file?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "RocMarshal (via GitHub)" <gi...@apache.org>.
RocMarshal commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-4781423069

   Hi, @davidradl @eskabetxe 
   Could you help take a look if you had the free time ? thx
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r4087099737


##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -45,17 +45,18 @@ See how to link with it for cluster execution [here]({{< ref "docs/dev/configura
 
 A driver dependency is also required to connect to a specified database. Here are drivers currently supported:
 
-| Driver     | Group Id                   | Artifact Id            | JAR                                                                                                                               |
-|:-----------|:---------------------------|:-----------------------|:----------------------------------------------------------------------------------------------------------------------------------|
-| MySQL      | `mysql`                    | `mysql-connector-java` | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                      |
-| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`               | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                    |
-| PostgreSQL | `org.postgresql`           | `postgresql`           | [Download](https://jdbc.postgresql.org/download/)                                                                                 |
-| Derby      | `org.apache.derby`         | `derby`                | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                       |
-| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`           | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16) |
-| CrateDB    | `io.crate`                 | `crate-jdbc`           | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                   |
-| Db2        | `com.ibm.db2.jcc`          | `db2jcc`               | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                           | 
-| Trino      | `io.trino`                 | `trino-jdbc`           | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                   |
-| OceanBase  | `com.oceanbase`            | `oceanbase-client`     | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                        |
+| Driver     | Group Id                   | Artifact Id                 | JAR                                                                                                                                     |
+|:-----------|:---------------------------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------|
+| MySQL      | `mysql`                    | `mysql-connector-java`      | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                            |
+| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`                    | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                          |
+| PostgreSQL | `org.postgresql`           | `postgresql`                | [Download](https://jdbc.postgresql.org/download/)                                                                                       |
+| Derby      | `org.apache.derby`         | `derby`                     | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                             |
+| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`                | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16)       |
+| CrateDB    | `io.crate`                 | `crate-jdbc`                | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                         |
+| Db2        | `com.ibm.db2.jcc`          | `db2jcc`                    | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                                 | 
+| Trino      | `io.trino`                 | `trino-jdbc`                | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                         |
+| OceanBase  | `com.oceanbase`            | `oceanbase-client`          | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                              |
+| Spanner    | `com.google.cloud`         | `google-cloud-spanner-jdbc` | [Download](https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner-jdbc)                                            |

Review Comment:
   Good point, the catalog needs `SpannerOptions` and `ConnectionOptions`, which are only bundled in the shaded jar. The driver table now names `google-cloud-spanner-jdbc` with the `single-jar-with-dependencies` classifier and links to the Maven Central directory, in both en and zh.
   



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/catalog/SpannerTypeMapper.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.catalog;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.catalog.JdbcCatalogTypeMapper;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.types.DataType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+/** SpannerTypeMapper util class. */
+@Internal
+public class SpannerTypeMapper implements JdbcCatalogTypeMapper {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SpannerTypeMapper.class);
+
+    private static final String SPANNER_BOOL = "BOOL";
+    private static final String SPANNER_INT64 = "INT64";
+    private static final String SPANNER_NUMERIC = "NUMERIC";
+    private static final String SPANNER_FLOAT64 = "FLOAT64";
+    private static final String SPANNER_FLOAT32 = "FLOAT32";
+    private static final String SPANNER_STRING = "STRING";
+    private static final String SPANNER_JSON = "JSON";
+    private static final String SPANNER_PROTO = "PROTO";
+    private static final String SPANNER_ENUM = "ENUM";
+    private static final String SPANNER_BYTES = "BYTES";
+    private static final String SPANNER_TIMESTAMP = "TIMESTAMP";
+    private static final String SPANNER_DATE = "DATE";
+    private static final String SPANNER_ARRAY = "ARRAY";
+    private static final String SPANNER_STRUCT = "STRUCT";
+
+    private static final String SPANNER_ARRAY_BOOL =
+            "[Ljava.lang.Boolean;"; // Boolean[].class.getName()
+    private static final String SPANNER_ARRAY_BYTES = "[[B"; // byte[][].class.getName()
+    // private static final String SPANNER_ARRAY_PROTO = "[[B";
+    private static final String SPANNER_ARRAY_DATE = "[Ljava.sql.Date;"; // Date[].class.getName()
+    private static final String SPANNER_ARRAY_FLOAT32 =
+            "[Ljava.lang.Float;"; // Float[].class.getName()
+    private static final String SPANNER_ARRAY_FLOAT64 =
+            "[Ljava.lang.Double;"; // Double[].class.getName()
+    private static final String SPANNER_ARRAY_INT64 = "[Ljava.lang.Long;"; // Long[].class.getName()
+    // private static final String SPANNER_ARRAY_ENUM = "[Ljava.lang.Long;";
+    private static final String SPANNER_ARRAY_NUMERIC =
+            "[Ljava.math.BigDecimal;"; // BigDecimal[].class.getName()
+    private static final String SPANNER_ARRAY_STRING =
+            "[Ljava.lang.String;"; // String[].class.getName()
+    // private static final String SPANNER_ARRAY_JSON = "[Ljava.lang.String;";
+    private static final String SPANNER_ARRAY_TIMESTAMP =
+            "[Ljava.sql.Timestamp;"; // Timestamp[].class.getName()
+
+    @Override
+    public DataType mapping(ObjectPath tablePath, ResultSetMetaData metadata, int colIndex)
+            throws SQLException {
+        final String spannerType = normalizeTypeName(metadata.getColumnTypeName(colIndex));
+        final String spannerClassName = metadata.getColumnClassName(colIndex);
+        final int precision = metadata.getPrecision(colIndex);
+        final int scale = metadata.getScale(colIndex);
+        return getMapping(spannerType, spannerClassName, precision, scale);
+    }
+
+    /**
+     * Newer versions of the Spanner JDBC driver return the full type name (e.g. {@code ARRAY<BOOL>}
+     * or {@code STRUCT<...>}) instead of only the type code. Strip the type parameters so that the
+     * mapping only depends on the type code.
+     */
+    private static String normalizeTypeName(String spannerType) {
+        final int index = spannerType.indexOf('<');
+        return index == -1 ? spannerType : spannerType.substring(0, index);
+    }
+
+    private DataType getMapping(
+            String spannerType, String spannerClassName, int precision, int scale) {
+        switch (spannerType) {
+            case SPANNER_BOOL:
+                return DataTypes.BOOLEAN();
+            case SPANNER_BYTES:
+            case SPANNER_PROTO:
+                // The default column display size is returned for precision,
+                // so it is handled as a BYTES type, not a VARBINARY type.
+                // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L157
+                return DataTypes.BYTES();
+            case SPANNER_DATE:
+                return DataTypes.DATE();
+            case SPANNER_FLOAT32:
+                return DataTypes.FLOAT();
+            case SPANNER_FLOAT64:
+                return DataTypes.DOUBLE();
+            case SPANNER_INT64:
+            case SPANNER_ENUM:
+                return DataTypes.BIGINT();
+            case SPANNER_NUMERIC:
+                // The precision for the numeric type is 14 and the scale is 15, both of which are
+                // fixed values.
+                // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L149
+                // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L168
+                // But the document describes it as follows.
+                // The GoogleSQL NUMERIC is an exact numeric data type capable of representing an
+                // exact numeric value
+                // with a precision of 38 and scale of 9.
+                // https://cloud.google.com/spanner/docs/working-with-numerics
+                return DataTypes.DECIMAL(38, 9);
+            case SPANNER_STRING:
+            // The default column display size is returned for precision,
+            // so it is handled as a STRING type, not a VARCHAR type.
+            // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L157
+            case SPANNER_JSON:
+            case SPANNER_STRUCT:
+                return DataTypes.STRING();
+            case SPANNER_TIMESTAMP:
+                return DataTypes.TIMESTAMP();

Review Comment:
   Agreed. The catalog now maps Spanner `TIMESTAMP` to `TIMESTAMP_LTZ(9)` and `ARRAY<TIMESTAMP>` to `ARRAY<TIMESTAMP_LTZ(9)>`, like Postgres `timestamptz`. The read path already converts through `Instant` since the previous fix. `SpannerCatalogITCase` now uses nanosecond test data and expects `Instant` values. I also added `testTimestampIsIndependentOfDefaultTimeZone`, which reads through the catalog with the JVM in `Asia/Tokyo`. With the old mapping, the catalog tests failed with `2025-01-01T09:00:00.123456789`. The docs type table now lists Spanner `TIMESTAMP` in the `TIMESTAMP WITH TIMEZONE` row.
   



##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/database/catalog/AbstractJdbcCatalog.java:
##########
@@ -141,6 +167,10 @@ public AbstractJdbcCatalog(
         this.connectionProperties = Preconditions.checkNotNull(connectionProperties);
         this.defaultUrl = this.urlFunction.apply(defaultDatabase);
 
+        validateConnectionProperties(connectionProperties);
+    }
+
+    protected void validateConnectionProperties(Properties connectionProperties) {

Review Comment:
   Added Javadoc to both `validateConnectionProperties` and `calculateUrlFunction`. It describes what each hook is for and notes that it is called from the constructor before subclass fields are initialized, so implementations must only depend on the given argument.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r4086053244


##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/catalog/SpannerTypeMapper.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.catalog;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.catalog.JdbcCatalogTypeMapper;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.types.DataType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+/** SpannerTypeMapper util class. */
+@Internal
+public class SpannerTypeMapper implements JdbcCatalogTypeMapper {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SpannerTypeMapper.class);
+
+    private static final String SPANNER_BOOL = "BOOL";
+    private static final String SPANNER_INT64 = "INT64";
+    private static final String SPANNER_NUMERIC = "NUMERIC";
+    private static final String SPANNER_FLOAT64 = "FLOAT64";
+    private static final String SPANNER_FLOAT32 = "FLOAT32";
+    private static final String SPANNER_STRING = "STRING";
+    private static final String SPANNER_JSON = "JSON";
+    private static final String SPANNER_PROTO = "PROTO";
+    private static final String SPANNER_ENUM = "ENUM";
+    private static final String SPANNER_BYTES = "BYTES";
+    private static final String SPANNER_TIMESTAMP = "TIMESTAMP";
+    private static final String SPANNER_DATE = "DATE";
+    private static final String SPANNER_ARRAY = "ARRAY";
+    private static final String SPANNER_STRUCT = "STRUCT";
+
+    private static final String SPANNER_ARRAY_BOOL =
+            "[Ljava.lang.Boolean;"; // Boolean[].class.getName()
+    private static final String SPANNER_ARRAY_BYTES = "[[B"; // byte[][].class.getName()
+    // private static final String SPANNER_ARRAY_PROTO = "[[B";
+    private static final String SPANNER_ARRAY_DATE = "[Ljava.sql.Date;"; // Date[].class.getName()
+    private static final String SPANNER_ARRAY_FLOAT32 =
+            "[Ljava.lang.Float;"; // Float[].class.getName()
+    private static final String SPANNER_ARRAY_FLOAT64 =
+            "[Ljava.lang.Double;"; // Double[].class.getName()
+    private static final String SPANNER_ARRAY_INT64 = "[Ljava.lang.Long;"; // Long[].class.getName()
+    // private static final String SPANNER_ARRAY_ENUM = "[Ljava.lang.Long;";
+    private static final String SPANNER_ARRAY_NUMERIC =
+            "[Ljava.math.BigDecimal;"; // BigDecimal[].class.getName()
+    private static final String SPANNER_ARRAY_STRING =
+            "[Ljava.lang.String;"; // String[].class.getName()
+    // private static final String SPANNER_ARRAY_JSON = "[Ljava.lang.String;";
+    private static final String SPANNER_ARRAY_TIMESTAMP =
+            "[Ljava.sql.Timestamp;"; // Timestamp[].class.getName()
+
+    @Override
+    public DataType mapping(ObjectPath tablePath, ResultSetMetaData metadata, int colIndex)
+            throws SQLException {
+        final String spannerType = normalizeTypeName(metadata.getColumnTypeName(colIndex));
+        final String spannerClassName = metadata.getColumnClassName(colIndex);
+        final int precision = metadata.getPrecision(colIndex);
+        final int scale = metadata.getScale(colIndex);
+        return getMapping(spannerType, spannerClassName, precision, scale);
+    }
+
+    /**
+     * Newer versions of the Spanner JDBC driver return the full type name (e.g. {@code ARRAY<BOOL>}
+     * or {@code STRUCT<...>}) instead of only the type code. Strip the type parameters so that the
+     * mapping only depends on the type code.
+     */
+    private static String normalizeTypeName(String spannerType) {
+        final int index = spannerType.indexOf('<');
+        return index == -1 ? spannerType : spannerType.substring(0, index);
+    }
+
+    private DataType getMapping(
+            String spannerType, String spannerClassName, int precision, int scale) {
+        switch (spannerType) {
+            case SPANNER_BOOL:
+                return DataTypes.BOOLEAN();
+            case SPANNER_BYTES:
+            case SPANNER_PROTO:
+                // The default column display size is returned for precision,
+                // so it is handled as a BYTES type, not a VARBINARY type.
+                // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L157
+                return DataTypes.BYTES();
+            case SPANNER_DATE:
+                return DataTypes.DATE();
+            case SPANNER_FLOAT32:
+                return DataTypes.FLOAT();
+            case SPANNER_FLOAT64:
+                return DataTypes.DOUBLE();
+            case SPANNER_INT64:
+            case SPANNER_ENUM:
+                return DataTypes.BIGINT();
+            case SPANNER_NUMERIC:
+                // The precision for the numeric type is 14 and the scale is 15, both of which are
+                // fixed values.
+                // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L149
+                // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L168
+                // But the document describes it as follows.
+                // The GoogleSQL NUMERIC is an exact numeric data type capable of representing an
+                // exact numeric value
+                // with a precision of 38 and scale of 9.
+                // https://cloud.google.com/spanner/docs/working-with-numerics
+                return DataTypes.DECIMAL(38, 9);
+            case SPANNER_STRING:
+            // The default column display size is returned for precision,
+            // so it is handled as a STRING type, not a VARCHAR type.
+            // https://github.com/googleapis/java-spanner-jdbc/blob/v2.26.1/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java#L157
+            case SPANNER_JSON:
+            case SPANNER_STRUCT:
+                return DataTypes.STRING();
+            case SPANNER_TIMESTAMP:
+                return DataTypes.TIMESTAMP();

Review Comment:
   Spanner TIMESTAMP is an instant with nanoseconds. Through the catalog, `1970-01-01T00:00:00.123456789Z` reads as `1970-01-01 09:00:00.123456` with the JVM in Asia/Tokyo. I think it should be `TIMESTAMP_LTZ(9)`, as Postgres does for `timestamptz`, arrays included.



##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/database/catalog/AbstractJdbcCatalog.java:
##########
@@ -141,6 +167,10 @@ public AbstractJdbcCatalog(
         this.connectionProperties = Preconditions.checkNotNull(connectionProperties);
         this.defaultUrl = this.urlFunction.apply(defaultDatabase);
 
+        validateConnectionProperties(connectionProperties);
+    }
+
+    protected void validateConnectionProperties(Properties connectionProperties) {

Review Comment:
   This and `calculateUrlFunction` are now protected API on a `@PublicEvolving` class and run from the constructor, before subclass fields are set. That's worth a Javadoc.



##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -45,17 +45,18 @@ See how to link with it for cluster execution [here]({{< ref "docs/dev/configura
 
 A driver dependency is also required to connect to a specified database. Here are drivers currently supported:
 
-| Driver     | Group Id                   | Artifact Id            | JAR                                                                                                                               |
-|:-----------|:---------------------------|:-----------------------|:----------------------------------------------------------------------------------------------------------------------------------|
-| MySQL      | `mysql`                    | `mysql-connector-java` | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                      |
-| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`               | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                    |
-| PostgreSQL | `org.postgresql`           | `postgresql`           | [Download](https://jdbc.postgresql.org/download/)                                                                                 |
-| Derby      | `org.apache.derby`         | `derby`                | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                       |
-| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`           | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16) |
-| CrateDB    | `io.crate`                 | `crate-jdbc`           | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                   |
-| Db2        | `com.ibm.db2.jcc`          | `db2jcc`               | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                           | 
-| Trino      | `io.trino`                 | `trino-jdbc`           | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                   |
-| OceanBase  | `com.oceanbase`            | `oceanbase-client`     | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                        |
+| Driver     | Group Id                   | Artifact Id                 | JAR                                                                                                                                     |
+|:-----------|:---------------------------|:----------------------------|:----------------------------------------------------------------------------------------------------------------------------------------|
+| MySQL      | `mysql`                    | `mysql-connector-java`      | [Download](https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/)                                                            |
+| Oracle     | `com.oracle.database.jdbc` | `ojdbc8`                    | [Download](https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8)                                                          |
+| PostgreSQL | `org.postgresql`           | `postgresql`                | [Download](https://jdbc.postgresql.org/download/)                                                                                       |
+| Derby      | `org.apache.derby`         | `derby`                     | [Download](http://db.apache.org/derby/derby_downloads.html)                                                                             |
+| SQL Server | `com.microsoft.sqlserver`  | `mssql-jdbc`                | [Download](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16)       |
+| CrateDB    | `io.crate`                 | `crate-jdbc`                | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/)                                                                         |
+| Db2        | `com.ibm.db2.jcc`          | `db2jcc`                    | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows)                                 | 
+| Trino      | `io.trino`                 | `trino-jdbc`                | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/)                                                                         |
+| OceanBase  | `com.oceanbase`            | `oceanbase-client`          | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/)                                                              |
+| Spanner    | `com.google.cloud`         | `google-cloud-spanner-jdbc` | [Download](https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner-jdbc)                                            |

Review Comment:
   The table still points at the plain `google-cloud-spanner-jdbc` jar, which doesn't contain `SpannerOptions` or `ConnectionOptions`. Can it name the `single-jar-with-dependencies` classifier? Same in zh.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r4081196493


##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/dialect/SpannerDialectConverter.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialectConverter;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils;
+
+import java.lang.reflect.Array;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.LocalDateTime;
+
+/**
+ * Runtime converter that responsible to convert between JDBC object and Flink internal object for
+ * Spanner.
+ */
+@Internal
+public class SpannerDialectConverter extends AbstractDialectConverter {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public String converterName() {
+        return "Spanner";
+    }
+
+    public SpannerDialectConverter(RowType rowType) {
+        super(rowType);
+    }
+
+    @Override
+    protected JdbcDeserializationConverter createInternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            return createSpannerArrayConverter(arrayType);
+        } else if (root == LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
+            // Spanner has a single TIMESTAMP type (an absolute instant); treat TIMESTAMP_LTZ as a
+            // plain timestamp value, mirroring how TIMESTAMP_WITHOUT_TIME_ZONE is handled.
+            return val ->
+                    val instanceof LocalDateTime
+                            ? TimestampData.fromLocalDateTime((LocalDateTime) val)
+                            : TimestampData.fromTimestamp((Timestamp) val);
+        } else {
+            return super.createInternalConverter(type);
+        }
+    }
+
+    @Override
+    protected JdbcSerializationConverter createNullableExternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+        if (root == LogicalTypeRoot.ARRAY) {

Review Comment:
   Overriding `createNullableExternalConverter` drops the null check, so a NULL array fails with an NPE on `arrayData.size()`. Overriding `createExternalConverter` keeps the parent wrapper.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/dialect/SpannerDialectConverter.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialectConverter;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils;
+
+import java.lang.reflect.Array;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.LocalDateTime;
+
+/**
+ * Runtime converter that responsible to convert between JDBC object and Flink internal object for
+ * Spanner.
+ */
+@Internal
+public class SpannerDialectConverter extends AbstractDialectConverter {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public String converterName() {
+        return "Spanner";
+    }
+
+    public SpannerDialectConverter(RowType rowType) {
+        super(rowType);
+    }
+
+    @Override
+    protected JdbcDeserializationConverter createInternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            return createSpannerArrayConverter(arrayType);
+        } else if (root == LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
+            // Spanner has a single TIMESTAMP type (an absolute instant); treat TIMESTAMP_LTZ as a
+            // plain timestamp value, mirroring how TIMESTAMP_WITHOUT_TIME_ZONE is handled.
+            return val ->
+                    val instanceof LocalDateTime
+                            ? TimestampData.fromLocalDateTime((LocalDateTime) val)
+                            : TimestampData.fromTimestamp((Timestamp) val);
+        } else {
+            return super.createInternalConverter(type);
+        }
+    }
+
+    @Override
+    protected JdbcSerializationConverter createNullableExternalConverter(LogicalType type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            LogicalType elementType = arrayType.getElementType();
+            String typeName = getSpannerArrayTypeName(elementType);
+
+            return (val, index, statement) -> {
+                ArrayData arrayData = val.getArray(index);
+                int size = arrayData.size();
+                Object[] elements = new Object[size];
+
+                // Convert each element
+                for (int i = 0; i < size; i++) {
+                    elements[i] = extractArrayElement(arrayData, i, elementType);
+                }
+
+                // Create JDBC Array and set it
+                java.sql.Array jdbcArray = statement.createArrayOf(typeName, elements);
+                statement.setArray(index, jdbcArray);
+            };
+        } else if (root == LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
+            // Spanner stores TIMESTAMP as an absolute instant; write TIMESTAMP_LTZ like a plain
+            // timestamp. JdbcTypeUtil has no mapping for TIMESTAMP_LTZ, so the null branch is
+            // handled here with Types.TIMESTAMP instead of the parent's nullable wrapper.
+            final int precision = LogicalTypeChecks.getPrecision(type);
+            return (val, index, statement) -> {
+                if (val == null || val.isNullAt(index)) {
+                    statement.setNull(index, Types.TIMESTAMP);
+                } else {
+                    statement.setTimestamp(index, val.getTimestamp(index, precision).toTimestamp());

Review Comment:
   With `-Duser.timezone=Asia/Tokyo`, `TO_TIMESTAMP_LTZ(0, 3)` is stored as 1969-12-31T15:00:00Z; reading shifts it back. I think this wants `toInstant()` here and `fromInstant` on read.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/lineage/SpannerLocationExtractorFactory.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.lineage;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.lineage.JdbcLocationExtractorFactory;
+
+import io.openlineage.client.utils.jdbc.JdbcExtractor;
+import io.openlineage.client.utils.jdbc.OverridingJdbcExtractor;
+
+/** Implementation of {@link JdbcLocationExtractorFactory} for Spanner. */
+@Internal
+public class SpannerLocationExtractorFactory implements JdbcLocationExtractorFactory {
+
+    @Override
+    public JdbcExtractor createExtractor() {
+        // TODO: Replace with SpannerJdbcExtractor when OpenLineage adds native Spanner support
+        return new OverridingJdbcExtractor("cloudspanner", "9010");

Review Comment:
   9010 is the emulator port, and every `spanner.googleapis.com` database gets the namespace `cloudspanner://spanner.googleapis.com:9010`. Could this include project, instance and database, with a test?



##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -887,6 +902,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
         <code>TINYINT(1)</code></td>
       <td></td>
       <td><code>BOOLEAN</code></td>
+      <td><code>BOOLEAN</code></td>

Review Comment:
   Spanner calls this `BOOL`, and the cell lands after the Flink SQL column. Same in the DATE row.



##########
docs/content/docs/connectors/table/jdbc.md:
##########
@@ -481,7 +486,8 @@ The JDBC catalog supports the following options:
 - `base-url`: required (should not contain the database name)
   - for Postgres Catalog this should be `"jdbc:postgresql://<ip>:<port>"`
   - for MySQL Catalog this should be `"jdbc:mysql://<ip>:<port>"`
-  - for OceanBase Catalog this should be `jdbc:oceanbase://<ip>:<port>`
+  - for OceanBase Catalog this should be `"jdbc:oceanbase://<ip>:<port>"`
+  - for Spanner Catalog this should be `"jdbc:cloudspanner:/projects/<project>/instances/<instance>/databases/<database>"`

Review Comment:
   The catalog appends the database here, giving `.../databases/<database>/<db>`; the tests end base-url in `/databases/`. Same in zh.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/dialect/SpannerDialect.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialect;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/** JDBC dialect for Spanner. */
+@Internal
+public class SpannerDialect extends AbstractDialect {
+
+    private static final long serialVersionUID = 1L;
+
+    // Define MAX/MIN precision of TIMESTAMP type according to Spanner docs:
+    // https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#timestamp_type
+    private static final int MAX_TIMESTAMP_PRECISION = 9;
+    private static final int MIN_TIMESTAMP_PRECISION = 0;
+
+    // Define MAX/MIN precision of DECIMAL type according to Spanner docs:
+    // https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#decimal_types
+    private static final int MAX_DECIMAL_PRECISION = 38;
+    private static final int MIN_DECIMAL_PRECISION = 0;
+
+    @Override
+    public SpannerDialectConverter getRowConverter(RowType rowType) {
+        return new SpannerDialectConverter(rowType);
+    }
+
+    @Override
+    public Optional<String> defaultDriverName() {
+        return Optional.of("com.google.cloud.spanner.jdbc.JdbcDriver");
+    }
+
+    @Override
+    public String dialectName() {
+        return "Spanner";
+    }
+
+    @Override
+    public String getLimitClause(long limit) {
+        return "LIMIT " + limit;
+    }
+
+    /** Spanner upsert query using INSERT OR UPDATE INTO syntax. */
+    @Override
+    public Optional<String> getUpsertStatement(
+            String tableName, String[] fieldNames, String[] uniqueKeyFields) {
+        String columns =
+                Arrays.stream(fieldNames)
+                        .map(this::quoteIdentifier)
+                        .collect(Collectors.joining(", "));
+        String placeholders =
+                Arrays.stream(fieldNames).map(f -> ":" + f).collect(Collectors.joining(", "));
+        return Optional.of(
+                "INSERT OR UPDATE INTO "
+                        + quoteIdentifier(tableName)
+                        + "("
+                        + columns
+                        + ")"
+                        + " VALUES ("
+                        + placeholders
+                        + ")");
+    }
+
+    @Override
+    public String quoteIdentifier(String identifier) {
+        // Spanner (GoogleSQL) quotes identifiers with backticks. Quote each dot-separated component
+        // so schema-qualified names (e.g. "my_schema.my_table") stay valid.
+        return Arrays.stream(identifier.split("\\."))
+                .map(part -> "`" + part + "`")
+                .collect(Collectors.joining("."));
+    }
+
+    @Override
+    public Optional<Range> decimalPrecisionRange() {
+        return Optional.of(Range.of(MIN_DECIMAL_PRECISION, MAX_DECIMAL_PRECISION));
+    }
+
+    @Override
+    public Optional<Range> timestampPrecisionRange() {
+        return Optional.of(Range.of(MIN_TIMESTAMP_PRECISION, MAX_TIMESTAMP_PRECISION));
+    }
+
+    @Override
+    public Set<LogicalTypeRoot> supportedTypes() {
+        // The data types used in Spanner are list at:
+        // https://cloud.google.com/spanner/docs/reference/standard-sql/data-types
+
+        // TODO: We can't convert BINARY data type to
+        //  PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO in
+        // LegacyTypeInfoDataTypeConverter.
+
+        return EnumSet.of(
+                LogicalTypeRoot.CHAR,
+                LogicalTypeRoot.VARCHAR,
+                LogicalTypeRoot.BOOLEAN,
+                LogicalTypeRoot.VARBINARY,
+                LogicalTypeRoot.DECIMAL,
+                LogicalTypeRoot.TINYINT,

Review Comment:
   Spanner only returns INT64, so an INT column fails on read with a ClassCastException. Narrow in `createInternalConverter` or drop the smaller integer types here.



##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/statement/FieldNamedPreparedStatement.java:
##########
@@ -254,6 +255,21 @@ static FieldNamedPreparedStatement prepareStatement(
      */
     void setObject(int fieldIndex, Object x) throws SQLException;
 
+    /**
+     * Sets the designated parameter to the given <code>java.sql.Array</code> object. The driver
+     * converts this to an SQL <code>ARRAY</code> value when it sends it to the database.
+     *
+     * @see PreparedStatement#setArray(int, Array)
+     */
+    void setArray(int fieldIndex, Array x) throws SQLException;

Review Comment:
   This interface is @PublicEvolving, so new abstract methods break external implementors. Could these be default methods, with `createArrayOf` going through `statement.getConnection()`?



##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/database/catalog/AbstractJdbcCatalog.java:
##########
@@ -130,7 +130,30 @@ public AbstractJdbcCatalog(
             String defaultDatabase,
             String baseUrl,
             Properties connectionProperties) {
-        super(catalogName, validateJdbcUrl(baseUrl, defaultDatabase));
+        this(
+                userClassLoader,
+                catalogName,
+                validateJdbcUrl(baseUrl, defaultDatabase),
+                baseUrl,
+                connectionProperties,
+                false);
+    }
+
+    /**
+     * Protected constructor that allows subclasses to skip URL validation. Subclasses with
+     * non-standard JDBC URL formats (e.g., Spanner's deep path structure) can use this constructor
+     * to provide the default database directly without going through {@link #validateJdbcUrl}.
+     *
+     * @param skipUrlValidation unused, exists only to differentiate the constructor signature
+     */
+    protected AbstractJdbcCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String defaultDatabase,
+            String baseUrl,
+            Properties connectionProperties,
+            boolean skipUrlValidation) {

Review Comment:
   An ignored flag that only changes the signature is hard to keep on a @PublicEvolving class. I think a protected hook resolving the default database reads better.



##########
flink-connector-jdbc-spanner/pom.xml:
##########
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>

Review Comment:
   Needs the ASF header, as does `SpannerTableRow.java` (`apache-rat:check`). On main the testcontainers artifacts are `testcontainers-gcloud` and `testcontainers-jdbc`.



##########
flink-connector-jdbc-spanner/src/main/java/org/apache/flink/connector/jdbc/spanner/database/catalog/SpannerCatalog.java:
##########
@@ -0,0 +1,345 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.spanner.database.catalog;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.connector.jdbc.core.database.catalog.AbstractJdbcCatalog;
+import org.apache.flink.connector.jdbc.core.database.catalog.JdbcCatalogTypeMapper;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.UniqueConstraint;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.StringUtils;
+
+import com.google.cloud.spanner.Spanner;
+import com.google.cloud.spanner.SpannerOptions;
+import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
+import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPage;
+import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse;
+import com.google.cloud.spanner.connection.ConnectionOptions;
+import com.google.spanner.admin.database.v1.Database;
+import com.google.spanner.admin.database.v1.InstanceName;
+import org.apache.commons.compress.utils.Lists;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+import java.util.function.Function;
+
+import static org.apache.flink.connector.jdbc.JdbcConnectionOptions.getBriefAuthProperties;
+
+/** Catalog for Spanner. */
+@Internal
+public class SpannerCatalog extends AbstractJdbcCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SpannerCatalog.class);
+
+    private static final Set<String> builtinSchemas =
+            new HashSet<String>() {
+                {
+                    add("INFORMATION_SCHEMA");
+                    add("SPANNER_SYS");
+                }
+            };
+
+    private final JdbcCatalogTypeMapper dialectTypeMapper;
+
+    @VisibleForTesting
+    public SpannerCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String defaultDatabase,
+            String username,
+            String pwd,
+            String baseUrl) {
+        this(
+                userClassLoader,
+                catalogName,
+                defaultDatabase,
+                baseUrl,
+                getBriefAuthProperties(username, pwd));
+    }
+
+    public SpannerCatalog(
+            ClassLoader userClassLoader,
+            String catalogName,
+            String defaultDatabase,
+            String baseUrl,
+            Properties connectProperties) {
+        // Use the protected constructor to skip validateJdbcUrl, which does not support
+        // Spanner's deep path URL structure (e.g., /projects/.../databases/).
+        super(userClassLoader, catalogName, defaultDatabase, baseUrl, connectProperties, true);
+        this.dialectTypeMapper = new SpannerTypeMapper();
+    }
+
+    @Override
+    protected Function<String, String> calculateUrlFunction(String url) {
+        // Spanner JDBC URLs use semicolons for parameters instead of question marks.
+        // Example: "jdbc:cloudspanner://host/.../databases/;autoConfigEmulator=true"
+        //       -> urlFunction("mydb") ->
+        // "jdbc:cloudspanner://host/.../databases/mydb;autoConfigEmulator=true"
+        int semiColonIndex = url.indexOf(';');
+        if (semiColonIndex == -1) {
+            // No semicolon params
+            String trimmed = url.trim();
+            String prefix = trimmed.endsWith("/") ? trimmed : trimmed + "/";
+            return dbName -> prefix + dbName;
+        }
+        // Has semicolon params: split into prefix and params
+        String urlWithoutParams = url.substring(0, semiColonIndex);
+        String params = url.substring(semiColonIndex);
+        String prefix = urlWithoutParams.endsWith("/") ? urlWithoutParams : urlWithoutParams + "/";
+        return dbName -> prefix + dbName + params;
+    }
+
+    @Override
+    protected void validateConnectionProperties(Properties connectionProperties) {
+        // Spanner uses Google Cloud credentials, not traditional username/password.
+        // Skip the parent's USER_KEY/PASSWORD_KEY validation.
+    }
+
+    private ConnectionOptions getConnectionOptions() {
+        return ConnectionOptions.newBuilder().setUri(defaultUrl.replace("jdbc:", "")).build();
+    }
+
+    private SpannerOptions getSpannerOptions(ConnectionOptions options) {
+        SpannerOptions.Builder builder =
+                SpannerOptions.newBuilder().setProjectId(options.getProjectId());

Review Comment:
   This drops the base-url credentials, so `listDatabases` (and thus `databaseExists`, `tableExists`) uses default credentials. Passing `options.getCredentials()` should keep them aligned.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1948021540


##########
flink-connector-jdbc-spanner/src/test/java/org/apache/flink/connector/jdbc/spanner/SpannerTestBase.java:
##########
@@ -16,27 +16,19 @@
  * limitations under the License.
  */
 
-package org.apache.flink.connector.jdbc.core.database.catalog;
+package org.apache.flink.connector.jdbc.spanner;
 
-import org.junit.jupiter.api.Test;
+import org.apache.flink.connector.jdbc.spanner.testutils.SpannerDatabase;
+import org.apache.flink.connector.jdbc.testutils.DatabaseMetadata;
+import org.apache.flink.connector.jdbc.testutils.DatabaseTest;
+import org.junit.jupiter.api.extension.ExtendWith;
 
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+/** Base class for Spanner testing. */
+@ExtendWith(SpannerDatabase.class)
+public interface SpannerTestBase extends DatabaseTest {
 
-/** Test for {@link AbstractJdbcCatalog}. */
-class AbstractJdbcCatalogTest {

Review Comment:
   This class is no longer needed because URL validation has been removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on code in PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#discussion_r1948021458


##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/database/catalog/AbstractJdbcCatalog.java:
##########
@@ -576,16 +569,6 @@ protected String getSchemaTableName(ObjectPath tablePath) {
         throw new UnsupportedOperationException();
     }
 
-    /**
-     * URL has to be without database, like "jdbc:dialect://localhost:1234/" or
-     * "jdbc:dialect://localhost:1234" rather than "jdbc:dialect://localhost:1234/db".
-     */
-    protected static void validateJdbcUrl(String url) {
-        String[] parts = url.trim().split("\\/+");
-
-        checkArgument(parts.length == 2);
-    }
-

Review Comment:
   In the case of Spanner, the URL is as follows, so I have deleted this validation.
   ```
   jdbc:cloudspanner://hostname/projects/gcp_project_id/instances/instance_id/databases/database_id
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-3838732311

   @davidradl Could you take another look when you have time? I've addressed the previous feedback and added some fixes for the test issues.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-3566844266

   ## CI Failure Investigation
   
   I investigated the CI failure in the `compile_and_test (2.1.1, 17)` job and found the following:
   
   ### Error Details
   
   **Failed Test:** `JdbcSourceITCase.testReadWithoutParallelismWithParamsProvider`
   
   **Root Cause Exception:**
   ```
   java.sql.SQLNonTransientConnectionException: No current connection.
     at org.apache.flink.connector.jdbc.core.datastream.source.reader.JdbcSourceSplitReader.openResultSetForSplitWhenAtLeastOnce
     at org.apache.flink.connector.jdbc.core.datastream.source.reader.JdbcSourceSplitReader.openResultSetForSplitWhenAtMostOnce
     at org.apache.flink.connector.jdbc.core.datastream.source.reader.JdbcSourceSplitReader.openResultSetForSplit
   ```
   
   ### Analysis
   
   1. **Not Spanner-specific**: This failure occurs in the `flink-connector-jdbc-core` module's test, not in Spanner-specific code.
   
   2. **Derby JDBC Connection Issue**: The Derby JDBC connection is being closed unexpectedly during ResultSet processing.
   
   3. **Branch Status**: This branch is already up-to-date with the latest main branch (commit 669314d), including recent hotfixes:
      - 669314d: Apply the correct version matrix in weekly CI
      - 45cbf78: Change Flink matrix to resolve Flink correctly (#179)
   
   4. **Recent main branch CI**: The main branch CI has been passing after these hotfixes.
   
   ### Local Test Results
   
   I ran the same test locally with both Flink versions:
   
   **Flink 2.1.1:**
   ```
   [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.255 s
   [INFO] BUILD SUCCESS
   ```
   
   **Flink 2.0.1:**
   ```
   [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.325 s
   [INFO] BUILD SUCCESS
   ```
   
   Both tests passed successfully in the local environment.
   
   ### Conclusion
   
   This appears to be a **CI environment-specific issue** rather than a code problem:
   - The test passes locally with both Flink 2.1.1 and 2.0.1
   - The issue is in `flink-connector-jdbc-core`, not Spanner-specific code
   - May be related to timing, resource constraints, or containerization in the CI environment
   
   ### Recommendation
   
   - Re-run the CI to see if it's a transient issue
   - This failure should not block the Spanner dialect PR as it's unrelated to the Spanner implementation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "RocMarshal (via GitHub)" <gi...@apache.org>.
RocMarshal commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-4770434132

   Hi, @laughingman7743 Could you help Run 'mvn spotless:apply' before the next review?
   Thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37288] Add Google Cloud Spanner dialect and catalog [flink-connector-jdbc]

Posted by "laughingman7743 (via GitHub)" <gi...@apache.org>.
laughingman7743 commented on PR #156:
URL: https://github.com/apache/flink-connector-jdbc/pull/156#issuecomment-4775237639

   ### CI failure is a pre-existing flaky test on `main`, not caused by this PR
   
   The red job (https://github.com/apache/flink-connector-jdbc/actions/runs/27995114250/job/82864660173) fails in `DerbyDynamicTableSourceITCase.testLimit`:
   
   ```
   Caused by: java.sql.SQLNonTransientConnectionException: No current connection.  (ERROR 08003)
     at ...EmbedPreparedStatement.executeQuery(...)
   ```
   
   **This is not introduced by this PR:**
   - This branch is rebased on `af994651`. CI for that exact commit on `main` (https://github.com/apache/flink-connector-jdbc/actions/runs/27738188350) fails in the **same `DerbyDynamicTableSourceITCase` class with the same `ERROR 08003: No current connection`**, only a different method (`testProject`).
   - The latest `main` (https://github.com/apache/flink-connector-jdbc/actions/runs/27966883251) also fails CI on another flaky core ITCase (`JdbcSourceStreamRelatedITCase.testAtLeastOnceWithFailure`, 30s `TimeoutException`).
   - None of the failing test files are touched by this PR; changes are isolated to the new `flink-connector-jdbc-spanner` module plus catalog/dialect/lineage in core.
   
   ### Root cause of the flaky `testLimit`
   
   `testLimit` runs `SELECT * FROM t LIMIT 1` over a source split into **2 partitions** (`scan.partition.num=2`). With `LIMIT 1` the job completes after the first row and cancels the source while the split-fetcher thread is still opening the **second** split. Cancellation tears the JDBC connection down, so the in-flight `JdbcSourceSplitReader.openResultSetForSplitWhenAtLeastOnce()` -> `statement.executeQuery()` runs against an already-closed connection -> `08003: No current connection`.
   
   Two gaps in `JdbcSourceSplitReader` make this fatal and racy:
   - `wakeUp()` is a no-op (https://github.com/apache/flink-connector-jdbc/blob/main/flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/source/reader/JdbcSourceSplitReader.java), so there is no cooperative cancellation — the reader keeps opening the next split during shutdown.
   - `fetch()` rethrows any `SQLException` as a fatal `RuntimeException`, so a benign shutdown-time "connection closed" error fails the whole job.
   
   ### How the fix differs from the closed PR https://github.com/apache/flink-connector-jdbc/pull/191
   
   That PR guarded only `resultSet.isClosed()` before `extract()` / `resultSet.next()` inside the record loop. But per the stack trace the failure is at `executeQuery()` when **opening the next split**, which that PR does not touch — so it would not reliably fix this. It was closed without merge.
   
   The fix I'd propose is different and targets the actual cause — cooperative cancellation:
   1. `wakeUp()` / `close()` set a `volatile boolean wakeup` flag.
   2. `checkSplitOrStartNext()` checks the flag before opening a new split (the `executeQuery()` path) and returns "no more records" instead of starting a query during shutdown.
   3. In `fetch()`, if a `SQLException` occurs while the reader is shutting down (flag set / thread interrupted), treat it as a graceful end-of-split instead of rethrowing — this closes the residual race window where cancellation lands during the Derby call.
   
   This covers the `executeQuery()` failure point that #191 missed, and removes the "shutdown error -> job failure" behavior. I'm happy to open a separate, focused PR + JIRA for this so both this PR and `main` go green.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org