eric-maynard commented on code in PR #1686:
URL: https://github.com/apache/polaris/pull/1686#discussion_r2158089209


##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/QueryGenerator.java:
##########
@@ -208,6 +209,59 @@ static QueryFragment generateWhereClause(
     return new QueryFragment(clause, parameters);
   }
 
+  @VisibleForTesting
+  static PreparedQuery generateVersionQuery() {
+    return new PreparedQuery("SELECT version_value FROM 
POLARIS_SCHEMA.VERSION", List.of());
+  }
+
+  /**
+   * Generate a SELECT query to find any entities that have a given realm & 
parent and that may with
+   * a given location. The check is performed without consideration for the 
scheme, so a path on one
+   * storage type may give a false positive for overlapping with another 
storage type. This should
+   * be combined with a check using `StorageLocation`.
+   *
+   * @param realmId A realm to search within
+   * @param parentId A parent entity to search within
+   * @param baseLocation The base location to look for overlap with, with or 
without a scheme
+   * @return The list of possibly overlapping entities that meet the criteria
+   */
+  @VisibleForTesting
+  public static PreparedQuery generateOverlapQuery(
+      String realmId, long parentId, String baseLocation) {
+    StorageLocation baseStorageLocation = StorageLocation.of(baseLocation);
+    String locationWithoutScheme = baseStorageLocation.withoutScheme();
+
+    List<String> conditions = new ArrayList<>();
+    List<Object> parameters = new ArrayList<>();
+
+    String[] components = locationWithoutScheme.split("/");
+    StringBuilder pathBuilder = new StringBuilder();
+
+    for (String component : components) {
+      pathBuilder.append(component).append("/");
+      conditions.add("location_without_scheme = ?");
+      parameters.add(pathBuilder.toString());
+    }

Review Comment:
   There is a check on directory depth 
[here](https://github.com/apache/polaris/pull/1686/files#diff-39f93c8ebe1e27a42d211677d30f3617647497964f4cf34061bcb419fcf8b356R85),
 but we can adjust it if you think it needs to 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: issues-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to