harshitaajoshi commented on code in PR #17526:
URL: https://github.com/apache/iceberg/pull/17526#discussion_r3723939955
##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcUtil.java:
##########
@@ -530,6 +535,58 @@ static boolean isConstraintViolation(SQLException ex) {
|| (ex.getMessage() != null && ex.getMessage().contains("constraint
failed"));
}
+ /**
+ * Returns the catalog that {@link java.sql.DatabaseMetaData} lookups should
be restricted to, or
+ * null to leave them unrestricted.
+ *
+ * <p>A null catalog does not restrict a lookup to the database the
connection points at, so
+ * catalog tables in an unrelated database can be mistaken for this
catalog's own. An empty
+ * catalog name is not used because it selects only objects that belong to
no catalog.
+ *
+ * @param conn a connection to resolve the catalog of
+ */
+ static String metadataCatalog(Connection conn) {
+ try {
+ String catalog = conn.getCatalog();
+ return catalog == null || catalog.isEmpty() ? null : catalog;
+ } catch (SQLException e) {
Review Comment:
Agreed, this is the right call. Swallowing every `SQLException` would hide a
real connection failure and quietly fall back to searching all catalogs, which
is the exact behavior this PR is trying to fix.
Narrowed to `SQLFeatureNotSupportedException` and added a test asserting
other `SQLExceptions` propagate.
--
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]