[FLINK-37288] Add Google Cloud Spanner dialect and catalog#156
[FLINK-37288] Add Google Cloud Spanner dialect and catalog#156laughingman7743 wants to merge 8 commits into
Conversation
|
Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html) |
| this.connectionProperties = Preconditions.checkNotNull(connectionProperties); | ||
| checkArgument( | ||
| !StringUtils.isNullOrWhitespaceOnly(connectionProperties.getProperty(USER_KEY))); | ||
| checkArgument( | ||
| !StringUtils.isNullOrWhitespaceOnly( | ||
| connectionProperties.getProperty(PASSWORD_KEY))); |
There was a problem hiding this comment.
Spanner does not use password authentication.
| /** | ||
| * 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); | ||
| } | ||
|
|
There was a problem hiding this 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
|
|
||
| /** Test for {@link AbstractJdbcCatalog}. */ | ||
| class AbstractJdbcCatalogTest { |
There was a problem hiding this comment.
This class is no longer needed because URL validation has been removed.
| } | ||
|
|
||
| public Schema getTableSchema() { | ||
| public Schema getTableSchema(String pkConstraintName) { |
There was a problem hiding this 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.
c7f0a5a to
3a73e0b
Compare
3a73e0b to
be60494
Compare
|
I have applied code formatting using Spotless and updated the documentation. It is ready for review. |
e4559c9 to
4ec422d
Compare
4ec422d to
520db3b
Compare
| | 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) | |
There was a problem hiding this comment.
I see the download url points to Maven like the spanner doc. How do I get the jar file?
There was a problem hiding this comment.
I have written the same URL as the official document.
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
There was a problem hiding this 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.
| 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. |
There was a problem hiding this 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
|
Does this repository not have an owner? Many PRs adding dialects are being left unreviewed. Does this mean that contributions are not accepted? |
84e20b0 to
939af62
Compare
| // 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; |
There was a problem hiding this comment.
For Spanner tests, it is necessary to configure autoConfigEmulator to automatically set up the emulator. This enables parameter passing.
| @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); | ||
| } |
There was a problem hiding this comment.
These implementations are necessary to support writing to Array types.
There was a problem hiding this 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).
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.
ecba519 to
854b846
Compare
|
@davidradl Could you take another look when you have time? I've addressed the previous feedback and added some fixes for the test issues. |
5e0d135 to
a87161a
Compare
a87161a to
0599b0c
Compare
fb7917c to
053359f
Compare
|
This PR is being marked as stale since it has not had any activity in the last 90 days. If you are having difficulty finding a reviewer, please reach out to the If this PR is no longer valid or desired, please feel free to close it. |
053359f to
df497eb
Compare
|
Rebased onto the latest main to resolve the stale status. This PR is still active and awaiting review. Any feedback would be greatly appreciated. |
df497eb to
8851d69
Compare
|
Hi, @laughingman7743 Could you help Run 'mvn spotless:apply' before the next review? |
8851d69 to
cac553f
Compare
|
Hi @RocMarshal, thanks for taking a look! I've run 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! 🙏 |
cac553f to
c0e976d
Compare
CI failure is a pre-existing flaky test on
|
|
Follow-up on the root cause above: I filed FLINK-39975 and opened #200 to fix the flaky The fix makes Once #200 lands on |
c0e976d to
b5f1c30
Compare
|
Hi, @davidradl @eskabetxe |
What is the purpose of the change
Adds Google Cloud Spanner support to flink-connector-jdbc as a new
flink-connector-jdbc-spannermodule.INFORMATION_SCHEMA, with semicolon-delimited URL parameter handling (;param=value)Changes to core module
AbstractJdbcCatalog: Added protected constructor and hooks (calculateUrlFunction,validateConnectionProperties) for dialects with non-standard URL formatsFieldNamedPreparedStatement: Array type supportTesting
All features are tested against the Spanner emulator via Testcontainers: dialect type mapping, catalog operations, end-to-end read/write, and factory SPI registration.
Jira
https://issues.apache.org/jira/browse/FLINK-37288
Discussion
https://lists.apache.org/thread/4344z501pszv5h7gmr0311fw7h6h4sw4