Skip to content

[#12929] fix(flink-connector): Use catalog database instead of schema for PostgreSQL JDBC table scans - #12930

Open
diqiu50 wants to merge 2 commits into
apache:mainfrom
diqiu50:fix/flink-postgres-jdbc-catalog-scan-database
Open

[#12929] fix(flink-connector): Use catalog database instead of schema for PostgreSQL JDBC table scans#12930
diqiu50 wants to merge 2 commits into
apache:mainfrom
diqiu50:fix/flink-postgres-jdbc-catalog-scan-database

Conversation

@diqiu50

@diqiu50 diqiu50 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

For PostgreSQL catalogs, JdbcPropertiesConverter#toFlinkTableProperties used the Flink "database" (= Postgres schema) as the JDBC scan connection database instead of the real jdbc-database. This PR makes PostgresqlPropertiesConverter use the catalog's actual database (via default-database, defaulted from jdbc-database) for the connection, and carries the schema via a schema-qualified table-name instead. MySQL behavior is unchanged.

Why are the changes needed?

Flink SQL SELECT on a Postgres catalog table fails with FATAL: database "public" does not exist.

Fix: #12929

Does this PR introduce any user-facing change?

No. PostgreSQL Flink table scans now work; previously always failed.

How was this patch tested?

Added unit tests in TestPostgresqlPropertiesConverter/TestMysqlPropertiesConverter; ran FlinkJdbcMysqlCatalogIT120 (passes, no regression).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kqa6kk4Wkdt9VC6s5Znipo

…schema for PostgreSQL JDBC table scans

For a jdbc-postgresql catalog, JdbcPropertiesConverter#toFlinkTableProperties
appended the Flink "database" (the PostgreSQL schema) to the base JDBC URL
instead of the catalog's real database, so scans failed with
"FATAL: database \"public\" does not exist" even though catalog browsing
worked fine.

PostgresqlPropertiesConverter now builds the scan connection URL from the
catalog's database (via the Flink default-database option, defaulted from
jdbc-database when not explicitly set), and carries the schema through a
schema-qualified table-name instead. MySQL behavior is unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kqa6kk4Wkdt9VC6s5Znipo
Copilot AI lite review requested due to automatic review settings September 4, 2026 11:11
@diqiu50 diqiu50 self-assigned this Sep 4, 2026
@diqiu50 diqiu50 added the branch-1.3 Automatically cherry-pick commit to branch-1.3 label Sep 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new PostgreSQL unit tests currently use a MySQL base JDBC URL from the shared test suite, which can allow the tests to pass without actually exercising PostgreSQL URL handling.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes Flink JDBC table scan property generation for PostgreSQL catalogs so scans connect to the configured PostgreSQL database (catalog jdbc-database → Flink default-database) while carrying the schema via a schema-qualified table-name, preventing failures like FATAL: database "public" does not exist.

Changes:

  • Default Flink default-database from Gravitino jdbc-database during catalog property conversion so it’s available for per-table scan properties.
  • Add PostgreSQL-specific overrides to build the scan connection database from default-database and emit schema.table for table-name.
  • Add unit tests for PostgreSQL/MySQL behavior and update JDBC catalog documentation to include PostgreSQL notes.
File summaries
File Description
flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConverter.java Defaults Flink default-database from jdbc-database and factors per-table URL/table-name generation into overridable hooks.
flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/jdbc/postgresql/PostgresqlPropertiesConverter.java Overrides connection database selection and table-name formatting for PostgreSQL scans.
flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/jdbc/TestPostgresqlPropertiesConverter.java Adds PostgreSQL-focused unit tests for correct scan URL DB selection and schema-qualified table naming.
flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/jdbc/TestMysqlPropertiesConverter.java Adds a MySQL unit test asserting existing behavior remains unchanged.
docs/flink-connector/flink-catalog-jdbc.md Documents PostgreSQL support and clarifies default-database/jdbc-database behavior.
Review details

Suppressed comments (1)

flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/jdbc/TestPostgresqlPropertiesConverter.java:90

  • This PostgreSQL converter test also asserts against flinkUrl (a MySQL URL from the shared test suite). Setting the input jdbc-url to a PostgreSQL URL and asserting against flinkUrlWithDomain makes the test actually exercise the PostgreSQL path and avoids false confidence.
    Map<String, String> flinkCatalogProperties =
        getConverter(catalogPropertiesWithBoth).toFlinkCatalogProperties(catalogPropertiesWithBoth);
    Map<String, String> tableProperties =
        getConverter(catalogPropertiesWithBoth)
            .toFlinkTableProperties(
                flinkCatalogProperties, ImmutableMap.of(), new ObjectPath("public", "t"));

    Assertions.assertEquals(
        flinkUrl + explicitDefaultDatabase,
        tableProperties.get(JdbcPropertiesConstants.FLINK_JDBC_TABLE_DATABASE_URL));
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +44 to +66
// No 'flink.bypass.default-database' is set, so the connection database must fall back to
// the catalog's jdbc-database.
Map<String, String> catalogPropertiesWithDatabase = new HashMap<>(catalogProperties);
catalogPropertiesWithDatabase.remove(FLINK_BYPASS_DEFAULT_DATABASE);
catalogPropertiesWithDatabase.put(
JdbcPropertiesConstants.GRAVITINO_JDBC_DATABASE, jdbcDatabase);

// Mirrors the production call in BaseCatalog#toFlinkTable: the first argument is the Flink
// catalog properties (as produced by toFlinkCatalogProperties), the second is the Gravitino
// table's own properties, which do not carry catalog-level properties like jdbc-database.
Map<String, String> flinkCatalogProperties =
getConverter(catalogPropertiesWithDatabase)
.toFlinkCatalogProperties(catalogPropertiesWithDatabase);
Map<String, String> tableProperties =
getConverter(catalogPropertiesWithDatabase)
.toFlinkTableProperties(
flinkCatalogProperties, ImmutableMap.of(), new ObjectPath(schema, tableName));

// The connection URL must target the PostgreSQL database (jdbc-database), not the schema.
Assertions.assertEquals(
flinkUrl + jdbcDatabase,
tableProperties.get(JdbcPropertiesConstants.FLINK_JDBC_TABLE_DATABASE_URL));
// The schema must be carried via the schema-qualified table name instead.
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Code Coverage Report

Overall Project 69.51% +0.01% 🟢
Files changed 97.96% 🟢

Module Coverage
aliyun 19.74% 🔴
api 51.57% 🟢
authorization-common 85.96% 🟢
authorization-ranger 4.38% 🔴
aws 53.54% 🟢
azure 32.1% 🔴
catalog-common 20.87% 🔴
catalog-fileset 82.17% 🟢
catalog-glue 69.24% 🟢
catalog-hive 82.96% 🟢
catalog-jdbc-common 45.69% 🟢
catalog-jdbc-doris 82.69% 🟢
catalog-jdbc-mysql 79.33% 🟢
catalog-jdbc-postgresql 83.39% 🟢
catalog-jdbc-starrocks 79.16% 🟢
catalog-kafka 76.99% 🟢
catalog-lakehouse-generic 60.88% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.97% 🟢
catalog-lakehouse-paimon 84.29% 🟢
catalog-model 77.99% 🟢
cli 44.51% 🟢
client-java 77.5% 🟢
common 56.34% 🟢
core 83.97% 🟢
filesystem-hadoop3 76.48% 🟢
flink 0.0% 🔴
flink-common 53.19% +1.31% 🟢
flink-runtime 0.0% 🔴
gcp 32.2% 🔴
hadoop-auth 68.0% 🟢
hadoop-common 17.84% 🔴
hive-metastore-common 53.4% 🟢
iceberg-aliyun-bundle 0.0% 🔴
iceberg-common 66.58% 🟢
iceberg-rest-server 76.68% 🟢
idp-basic 87.1% 🟢
integration-test-common 0.0% 🔴
jobs 62.92% 🟢
lance-common 32.52% 🔴
lance-rest-server 68.02% 🟢
lineage 59.39% 🟢
optimizer 83.24% 🟢
optimizer-api 21.95% 🔴
server 90.08% 🟢
server-common 81.27% 🟢
spark 28.57% 🔴
spark-common 52.04% 🟢
tencent 81.78% 🟢
trino-connector 58.36% 🟢
Files
Module File Coverage
flink-common PostgresqlPropertiesConverter.java 100.0% 🟢
JdbcPropertiesConverter.java 97.5% 🟢

…tiesConverter tests

Address Copilot review comment on apache#12930: the assertions were checking
against the shared MySQL flinkUrl fixture, so the tests could pass even
if PostgreSQL URL handling regressed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch-1.3 Automatically cherry-pick commit to branch-1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug report] Flink SQL SELECT against a jdbc-postgresql catalog fails with "database \"public\" does not exist"

2 participants