jayzhan211 opened a new pull request, #71106: URL: https://github.com/apache/doris/pull/71106
### Background Besides the standard JDBC `DatabaseMetaData` calls, the JDBC catalog connector (`fe-connector-jdbc`) sends a few SQL queries of its own to the remote database: an Oracle lookup in `ALL_SYNONYMS`, used by table listing, the table-existence check and column lookup, and a row-count query for MySQL, Oracle, PostgreSQL and SQL Server that feeds table statistics. Each filters on a remote schema or table name. ### What problem does this PR solve? Issue Number: None Related PR: #62183 (moved this code from fe-core into fe-connector-jdbc) PR Type: Bugfix Problem Summary: These queries splice the names into the SQL text as quoted literals, so a name that contains a single quote produces invalid SQL. On Oracle, listing a schema's tables or checking whether a table exists then fails with `Failed to process table`; the row-count queries log the error and report the row count as unknown (-1). This PR passes every name as a bind parameter of a `PreparedStatement`. Names without a quote behave as before. ### Details - **Change map:** 124 lines of production code (+73 -51) in the five JDBC client classes, one part; the other 177 lines are the new unit test. - **Frequency:** Not observed; found by static analysis. Triggers whenever a schema or table name that one of these queries filters on contains a single quote. - **Root cause:** The queries are built by string concatenation: the Oracle synonym lookup and `resolveSynonym` in `JdbcOracleConnectorClient`, and `getRowCount` in the MySQL, Oracle, PostgreSQL and SQL Server clients. The synonym lookup could not be bound at all, because the hook `getAdditionalTablesQuery` returned SQL text that `JdbcConnectorClient.processTable` ran through a plain `Statement`. - **Why existing tests missed it:** The client unit tests (`JdbcOracleConnectorClientTest` and others) cover type mapping and never call these methods. The `external_table_p0/jdbc` regression suites use only ordinary names. - **Fix:** Replace the hook with `prepareAdditionalTablesQuery`, which returns a `PreparedStatement` that `processTable` executes and closes, and bind the names in the Oracle synonym queries and the four `getRowCount` methods. The SQL text is otherwise unchanged. - **Other paths and branches:** fe-core's `JdbcOracleClient` builds the same synonym lookup by concatenation. On master only streaming jobs (`StreamingJobUtils`) reach it, so it is left for a follow-up. `branch-4.1` and `branch-4.2` have no `fe-connector-jdbc`; their JDBC catalogs use that fe-core client. ### Testing - New `JdbcMetadataQueryBindingTest`: runs the Oracle existence check, the Oracle table listing and the four `getRowCount` methods against a recording fake connection with the name `t' OR '1'='1`, and asserts that the name is only bound, never in the SQL text. The author ran it on JDK 17 on `e04a785e20`: the 3 cases fail without the fix and pass with it, and the module's 280 tests pass. The changed files are identical on that commit and the current base, but the tests were not re-run on the current base. FE UT CI runs this module. - Not run: the `external_table_p0/jdbc` suites against live databases. ### Notes for Reviewers - Start with `JdbcConnectorClient.processTable`. The decision I most want reviewed is replacing the protected hook rather than adding a second one: a client that still overrides `getAdditionalTablesQuery` would no longer be called, and in this repository only `JdbcOracleConnectorClient` overrides it. ### Release note JDBC catalogs on Oracle no longer fail to list or find tables whose schema or table name contains a single quote, and row counts of such tables on MySQL, Oracle, PostgreSQL and SQL Server are no longer reported as unknown. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Partially verified: the unit tests last ran on `e04a785e20`, not on the current base; the JDBC regression suites against live databases did not run. ### AI Disclosure - Tool: Claude Code; this description with Claude Opus 5.5, the model for the code and the test not stated - Generated: the fix, the unit test, and this description - Human review: The author reviewed all of the generated code and the test. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
