diff --git a/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java b/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java index 1cce0e2ce77e..311cabf82f1c 100644 --- a/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java +++ b/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java @@ -162,8 +162,8 @@ private void initializeCatalogTables() { DatabaseMetaData dbMeta = conn.getMetaData(); ResultSet tableExists = dbMeta.getTables( - null /* catalog name */, - null /* schemaPattern */, + conn.getCatalog() /* catalog name */, + escape(conn.getSchema(), dbMeta.getSearchStringEscape()) /* schemaPattern */, JdbcUtil.CATALOG_TABLE_VIEW_NAME /* tableNamePattern */, null /* types */); if (tableExists.next()) { @@ -181,8 +181,8 @@ private void initializeCatalogTables() { DatabaseMetaData dbMeta = conn.getMetaData(); ResultSet tableExists = dbMeta.getTables( - null /* catalog name */, - null /* schemaPattern */, + conn.getCatalog() /* catalog name */, + escape(conn.getSchema(), dbMeta.getSearchStringEscape()) /* schemaPattern */, JdbcUtil.NAMESPACE_PROPERTIES_TABLE_NAME /* tableNamePattern */, null /* types */); @@ -208,6 +208,10 @@ private void initializeCatalogTables() { } } + private static String escape(String name, String escape) { + return name.replace("_", escape + "_").replace("%", escape + "%"); + } + private void updateSchemaIfRequired() { try { connections.run(