harshitaajoshi commented on code in PR #17526:
URL: https://github.com/apache/iceberg/pull/17526#discussion_r3723941859
##########
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) {
+ // databases without catalog support may fail instead of reporting no
catalog
+ LOG.debug("Cannot determine the connection catalog, searching all
catalogs", e);
+ return null;
+ }
+ }
+
+ /**
+ * Escapes a literal name so that it matches only itself when used as a
{@link
+ * java.sql.DatabaseMetaData} pattern.
+ *
+ * <p>Pattern arguments treat {@code _} and {@code %} as wildcards, so an
unescaped name such as
+ * {@code iceberg_tables} also matches unrelated names like {@code
iceberg1tables}. The name is
+ * returned unchanged when the driver reports no escape string, because
escaping is not supported
+ * in that case.
+ *
+ * @param name a literal table or column name
+ * @param escape the driver's escape string, from {@link
+ * java.sql.DatabaseMetaData#getSearchStringEscape()}
+ */
+ static String escapeMetadataPattern(String name, String escape) {
+ if (escape == null || escape.isEmpty()) {
Review Comment:
It is only used for table and column name patterns right now, where null is
not meaningful, so I left it as is. If schema scoping lands in the follow-up
then null becomes a valid input and I will make it null safe as part of that
change.
--
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]