yuqi1129 commented on code in PR #14802:
URL: https://github.com/apache/gravitino/pull/14802#discussion_r4520841373
##########
flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/jdbc/postgresql/PostgresqlPropertiesConverter.java:
##########
@@ -43,23 +49,58 @@ public String getFlinkCatalogType() {
return GravitinoJdbcCatalogFactoryOptions.POSTGRESQL_IDENTIFIER;
}
+ /**
+ * For PostgreSQL, a Flink "database" is a Gravitino schema, so
'default-database' names the
+ * schema Flink starts in, while JDBC connections always target the
catalog's PostgreSQL database.
+ * That database is resolved from jdbc-database, or from jdbc-url when
jdbc-database is not set,
+ * and also serves as 'default-database' when that is not set.
+ */
+ @Override
+ public Map<String, String> toFlinkCatalogProperties(Map<String, String>
gravitinoProperties) {
+ Map<String, String> flinkCatalogProperties =
+ super.toFlinkCatalogProperties(gravitinoProperties);
+ String connectionDatabase =
+
gravitinoProperties.get(JdbcPropertiesConstants.GRAVITINO_JDBC_DATABASE);
+ if (StringUtils.isBlank(connectionDatabase)) {
+ connectionDatabase =
+ getDatabaseFromJdbcUrl(
+
gravitinoProperties.get(JdbcPropertiesConstants.GRAVITINO_JDBC_URL));
+ }
+ if (StringUtils.isNotBlank(connectionDatabase)) {
+ flinkCatalogProperties.put(
+ JdbcPropertiesConstants.GRAVITINO_CONNECTION_DATABASE,
connectionDatabase);
+ flinkCatalogProperties.putIfAbsent(
Review Comment:
**[Important] The URL fallback introduces a catalog-load failure on Flink
2.1/2.2.**
With only `jdbc-url=jdbc:postgresql://host:5432/gravitino` configured
(neither `jdbc-database` nor `flink.bypass.default-database`), this new
fallback makes `configuredDefaultDatabase` non-null and activates the inner
catalog's `open()`. The derived `base-url` ends in `/`, and JDBC connector
4.1.x actually opens `jdbc:postgresql://host:5432/`, without the database. The
PostgreSQL driver then selects the database named after the JDBC user. If that
database does not exist, loading the catalog fails before any table operation.
I compared the pre-change and PR implementations: the former skips
inner-catalog open for this configuration; the latter opens the database-less
URL. The dependency's trailing-slash behavior predates this PR, but the new
fallback makes it a regression for this previously loadable configuration.
Please normalize the URL passed to the inner catalog so it targets the
resolved connection database on all four versions, and add a test that reaches
the real native factory/open path. The new
`testInnerCatalogUsesConnectionDatabase` currently throws before that path
executes.
##########
flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConverter.java:
##########
@@ -121,6 +119,10 @@ public Map<String, String> toFlinkTableProperties(
jdbcPassword != null, JdbcPropertiesConstants.FLINK_JDBC_PASSWORD + "
should not be null.");
Preconditions.checkArgument(
jdbcBaseUrl != null, JdbcPropertiesConstants.FLINK_JDBC_URL + " should
not be null.");
+ // Same as FlinkJdbcCatalog, accept a base-url with or without the
trailing slash.
+ if (!jdbcBaseUrl.endsWith("/")) {
Review Comment:
**[Important] A supported Flink 2.x bypass URL is corrupted when
constructing the table URL.**
Flink 2.1/2.2's JDBC connector 4.1.x accepts a `base-url` containing the
database and query parameters. Now that `flink.bypass.base-url` is preserved,
an override such as `jdbc:postgresql://client:5432/gravitino` reaches this code
unchanged. The native catalog opens the correct URL, but the table URL becomes
`jdbc:postgresql://client:5432/gravitino/gravitino`.
Similarly, `jdbc:postgresql://client:5432/gravitino?sslmode=require` becomes
`jdbc:postgresql://client:5432/gravitino?sslmode=require/gravitino`, corrupting
the parameter value. I reproduced both mismatches with the actual Flink 2.1/2.2
factories and this converter.
Please make the native-catalog and table URL construction consistent,
preserving parameters and avoiding a second database suffix. Add coverage for
these override forms; the shared converter also needs the corresponding MySQL
case.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]