Skip to content

Commit

Permalink
Core: Fix namespace SQL statement using ESCAPE character that works w…
Browse files Browse the repository at this point in the history
…ith MySQL/PostgreSQL (#10167) (#10169)

Co-authored-by: Chauncy <[email protected]>
  • Loading branch information
jbonofre and xuchuanqiu authored Apr 17, 2024
1 parent c45c9f6 commit 5d73e6b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/org/apache/iceberg/jdbc/JdbcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ enum SchemaVersion {
+ TABLE_NAMESPACE
+ " = ? OR "
+ TABLE_NAMESPACE
+ " LIKE ? ESCAPE '\\')"
+ " LIKE ? ESCAPE '!')"
+ " LIMIT 1";
static final String LIST_NAMESPACES_SQL =
"SELECT DISTINCT "
Expand Down Expand Up @@ -426,7 +426,7 @@ enum SchemaVersion {
+ NAMESPACE_NAME
+ " = ? OR "
+ NAMESPACE_NAME
+ " LIKE ? ESCAPE '\\' "
+ " LIKE ? ESCAPE '!' "
+ " ) ";
static final String INSERT_NAMESPACE_PROPERTIES_SQL =
"INSERT INTO "
Expand Down Expand Up @@ -783,7 +783,7 @@ static boolean namespaceExists(
// when namespace has sub-namespace then additionally checking it with LIKE statement.
// catalog.db can exists as: catalog.db.ns1 or catalog.db.ns1.ns2
String namespaceStartsWith =
namespaceEquals.replace("\\", "\\\\").replace("_", "\\_").replace("%", "\\%") + ".%";
namespaceEquals.replace("!", "!!").replace("_", "!_").replace("%", "!%") + ".%";
if (exists(connections, GET_NAMESPACE_SQL, catalogName, namespaceEquals, namespaceStartsWith)) {
return true;
}
Expand Down

0 comments on commit 5d73e6b

Please sign in to comment.