harshitaajoshi opened a new pull request, #17526: URL: https://github.com/apache/iceberg/pull/17526
## Summary Fixes #17300 `JdbcCatalog` calls `DatabaseMetaData.getTables()` and `DatabaseMetaData.getColumns()` with a `null` catalog and with raw table and column names as the pattern arguments. Two things go wrong there. A `null` catalog does not limit the lookup to the database the connection actually points at. MySQL Connector/J flipped the default of `nullCatalogMeansCurrent` to `false` in 8.0, so a null catalog now searches every database the user can see. The pattern arguments also treat `_` and `%` as wildcards, so `iceberg_tables` matches unrelated names like `iceberg1tables`. Together that means `updateSchemaIfRequired()` can find an `iceberg_type` column that does not exist in the current database, decide the schema is V1, and then fail every later query with `Unknown column 'iceberg_type' in 'field list'`. It also quietly overrides an explicit `jdbc.schema-version=V0`, since that property is only read when the column lookup comes back empty. While digging into this I hit a worse variant in `atomicCreateTable()`. If an unrelated table matches the pattern, the catalog tables are never created because they look like they already exist, and initialization then fails with `no such table: iceberg_tables`. ## Fix Scope both lookups to the connection's catalog, and escape the names before using them as patterns. `JdbcUtil.metadataCatalog(Connection)` works out which catalog to restrict the lookup to. An empty catalog name becomes `null`, because `""` only selects objects that belong to no catalog at all. Some drivers throw instead of reporting that they have no catalog support, so that case falls back to the current unrestricted behavior rather than breaking initialization. `JdbcUtil.escapeMetadataPattern(String, String)` escapes `_`, `%`, and the escape character itself. It takes the escape string from `DatabaseMetaData.getSearchStringEscape()` instead of hardcoding a backslash, and returns the name untouched when the driver reports no escape string. Passing `conn.getCatalog()` here is what Oracle suggests as the workaround for this same driver behavior in [MySQL Bug #95717](https://bugs.mysql.com/bug.php?id=95717). Databases without catalogs are not affected. SQLite and Derby report no catalog, and Derby reports no escape string, so both helpers hand back exactly what the code passes today. ## Tests `TestJdbcCatalog.catalogTablesAreCreatedWhenAnotherTableMatchesTheirNamePattern` covers the initialization failure. `TestJdbcCatalog.schemaVersionIgnoresColumnsOfTablesMatchingTheCatalogTableNamePattern` covers the false V1 detection. Without the fix it fails with `no such column: iceberg_type`, which is how SQLite words the error from the issue. `TestJdbcUtil` covers `escapeMetadataPattern` plus all four `metadataCatalog` outcomes, including a driver that throws. One gap worth calling out: the catalog scoping cannot be tested end to end against SQLite or Derby, since neither reports a catalog, so it is covered by unit tests on the helper instead. Happy to add a MySQL or PostgreSQL test if you would prefer one here. -- 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]
