singhpk234 commented on code in PR #1686:
URL: https://github.com/apache/polaris/pull/1686#discussion_r2151023560


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java:
##########
@@ -403,6 +406,19 @@ boolean hasChildren(
       long catalogId,
       long parentId);
 
+  /**
+   * Check if the specified IcebergTableLikeEntity / NamespaceEntity has any 
sibling entities which
+   * share a base location
+   *
+   * @param callContext the polaris call context
+   * @param entity the entity to check for overlapping siblings for
+   * @return Optional.of(Optional.of(location)) if the parent entity has 
children,
+   *     Optional.of(Optional.empty()) if not, and Optional.empty() if the 
metastore doesn't support
+   *     this operation
+   */
+  <T extends PolarisEntity & LocationBasedEntity> Optional<Optional<String>> 
hasOverlappingSiblings(

Review Comment:
   Optional<Optional<String>> ? can't Optional<String> work ? 



##########
persistence/relational-jdbc/src/main/resources/h2/schema-v2.sql:
##########
@@ -0,0 +1,128 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file--
+--  distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"). You may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--  http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+--
+
+-- Changes from v1:
+--  * Added a `location` column to entities
+--  * Added an index `idx_locations` over (realm_id, parent_id, location) in 
entities
+
+CREATE SCHEMA IF NOT EXISTS POLARIS_SCHEMA;
+SET SCHEMA POLARIS_SCHEMA;
+
+CREATE TABLE IF NOT EXISTS version (
+    version_key VARCHAR PRIMARY KEY,
+    version_value INTEGER NOT NULL
+);
+
+MERGE INTO version (version_key, version_value)
+    KEY (version_key)
+    VALUES ('version', 2);
+
+-- H2 supports COMMENT, but some modes may ignore it
+COMMENT ON TABLE version IS 'the version of the JDBC schema in use';
+
+DROP TABLE IF EXISTS entities;
+CREATE TABLE IF NOT EXISTS entities (
+    realm_id TEXT NOT NULL,
+    catalog_id BIGINT NOT NULL,
+    id BIGINT NOT NULL,
+    parent_id BIGINT NOT NULL,
+    name TEXT NOT NULL,
+    entity_version INT NOT NULL,
+    type_code INT NOT NULL,
+    sub_type_code INT NOT NULL,
+    create_timestamp BIGINT NOT NULL,
+    drop_timestamp BIGINT NOT NULL,
+    purge_timestamp BIGINT NOT NULL,
+    to_purge_timestamp BIGINT NOT NULL,
+    last_update_timestamp BIGINT NOT NULL,
+    properties TEXT NOT NULL DEFAULT '{}',
+    internal_properties TEXT NOT NULL DEFAULT '{}',
+    grant_records_version INT NOT NULL,
+    location_without_scheme TEXT,
+    PRIMARY KEY (realm_id, id),
+    CONSTRAINT constraint_name UNIQUE (realm_id, catalog_id, parent_id, 
type_code, name)
+);
+
+DROP INDEX IF EXISTS idx_locations;
+CREATE INDEX idx_locations ON entities(realm_id, parent_id, 
location_without_scheme);

Review Comment:
   can do
   
   ```
   CREATE INDEX IF NOT EXISTS
   ```



##########
persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/QueryGeneratorTest.java:
##########
@@ -229,4 +202,52 @@ void testGenerateWhereClause_emptyMap() {
     Map<String, Object> whereClause = Collections.emptyMap();
     assertEquals("", QueryGenerator.generateWhereClause(Set.of(), 
whereClause).sql());
   }
+
+  @Test
+  void testGenerateOverlapQuery() {
+    assertEquals(
+        "SELECT id, catalog_id, parent_id, type_code, name, entity_version, 
sub_type_code,"
+            + " create_timestamp, drop_timestamp, purge_timestamp, 
to_purge_timestamp, last_update_timestamp,"
+            + " properties, internal_properties, grant_records_version, 
location_without_scheme FROM"
+            + " POLARIS_SCHEMA.ENTITIES WHERE realm_id = ? AND parent_id = ? 
AND (location = ? OR location = ?"
+            + " OR location = ? OR location = ? OR location = ? OR location 
LIKE ?)",
+        QueryGenerator.generateOverlapQuery("realmId", -123, 
"s3://bucket/tmp/location/").sql());
+    Assertions.assertThatCollection(
+            QueryGenerator.generateOverlapQuery("realmId", -123, 
"s3://bucket/tmp/location/")
+                .parameters())
+        .containsExactly(
+            "realmId",
+            -123L,
+            "/",
+            "//",
+            "//bucket/",
+            "//bucket/tmp/",
+            "//bucket/tmp/location/",
+            "//bucket/tmp/location/%");
+
+    assertEquals(
+        "SELECT id, catalog_id, parent_id, type_code, name, entity_version, 
sub_type_code,"
+            + " create_timestamp, drop_timestamp, purge_timestamp, 
to_purge_timestamp, last_update_timestamp,"
+            + " properties, internal_properties, grant_records_version, 
location_without_scheme FROM"
+            + " POLARIS_SCHEMA.ENTITIES WHERE realm_id = ? AND parent_id = ? 
AND (location = ? OR location = ?"
+            + " OR location = ? OR location = ? OR location = ? OR location 
LIKE ?)",

Review Comment:
   location ? should it be `location_without_scheme`



##########
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
+  public static PreparedQuery generateVersionQuery() {

Review Comment:
   can this just be 
   ```suggestion
    static PreparedQuery generateVersionQuery() {
   ```



##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/models/SchemaVersion.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.persistence.relational.jdbc.models;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+import org.apache.polaris.persistence.relational.jdbc.DatabaseType;
+
+public class SchemaVersion implements Converter<SchemaVersion> {
+  private final int value;

Review Comment:
   [cosmetic comment] can we `Integer` type and use NULL check ? instead of -1 
just avoid this confusion we had with snapshot-id in iceberg repo : 
https://lists.apache.org/thread/gqqsnww6nqc50pddwn29blzghmb0m0h3



##########
polaris-core/src/main/java/org/apache/polaris/core/entity/LocationBasedEntity.java:
##########
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.core.entity;
+
+/**
+ * An interface for entity types that represent data stored at some location. 
These entities provide
+ * a method `getBaseLocation` to retrieve that location.
+ */
+public interface LocationBasedEntity {

Review Comment:
   does it need to be a public interface ? 



-- 
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]

Reply via email to