You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "ismailsimsek (via GitHub)" <gi...@apache.org> on 2023/08/17 10:18:33 UTC
[GitHub] [iceberg] ismailsimsek commented on a diff in pull request #8340: JDBC catalog fix namespaceExists check
ismailsimsek commented on code in PR #8340:
URL: https://github.com/apache/iceberg/pull/8340#discussion_r1297015928
##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcUtil.java:
##########
@@ -345,38 +345,44 @@ public static String deletePropertiesStatement(Set<String> properties) {
static boolean namespaceExists(
String catalogName, JdbcClientPool connections, Namespace namespace) {
- if (exists(
+ if (namespaceExists(
connections,
JdbcUtil.GET_NAMESPACE_SQL,
catalogName,
- JdbcUtil.namespaceToString(namespace) + "%")) {
+ JdbcUtil.namespaceToString(namespace))) {
return true;
}
- if (exists(
+ if (namespaceExists(
connections,
JdbcUtil.GET_NAMESPACE_PROPERTIES_SQL,
catalogName,
- JdbcUtil.namespaceToString(namespace) + "%")) {
+ JdbcUtil.namespaceToString(namespace))) {
return true;
}
return false;
}
@SuppressWarnings("checkstyle:NestedTryDepth")
- private static boolean exists(JdbcClientPool connections, String sql, String... args) {
+ private static boolean namespaceExists(
+ JdbcClientPool connections, String sql, String catalogName, String namespace) {
try {
return connections.run(
conn -> {
try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
- for (int pos = 0; pos < args.length; pos += 1) {
- preparedStatement.setString(pos + 1, args[pos]);
- }
-
+ preparedStatement.setString(1, catalogName);
+ preparedStatement.setString(2, namespace + "%");
try (ResultSet rs = preparedStatement.executeQuery()) {
- if (rs.next()) {
- return true;
+ while (rs.next()) {
+ String ns = rs.getString(1);
+ // given namespace can exist as is or can be parent of sub namespace level,
+ // containing `.`
+ // for existing namespace: `root.namespace.subnamespace` searching
+ // `root.namespace` will return true
Review Comment:
No it will check for `root.name.` as prefix match.
While SQL side is still doing wildcard match following java logic is doing exact match on the returned result.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org