yuqi1129 commented on code in PR #14350:
URL: https://github.com/apache/gravitino/pull/14350#discussion_r4439392756


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/DomainMetaBaseSQLProvider.java:
##########
@@ -202,6 +211,34 @@ public String listDomainPOsByMetalakeAndDomainNames(
         + "</script>";
   }
 
+  /**
+   * Returns SQL that resolves the live parent and lists its sub-domains in 
one statement.
+   *
+   * @param metalakeName The metalake name.
+   * @param parentName The parent domain name.
+   * @return The SQL. An existing childless parent produces a row with a null 
domain ID.
+   */
+  public String listDomainPOsByParentIdentifier(
+      @Param("metalakeName") String metalakeName, @Param("parentName") String 
parentName) {
+    return "SELECT "
+        + DOMAIN_COLUMNS
+        + ", bt.tag_name as backingTagName, lp.domain_name as parentName"
+        + " FROM "
+        + DOMAIN_TABLE_NAME
+        + " lp JOIN "
+        + MetalakeMetaMapper.TABLE_NAME
+        + " mm ON lp.metalake_id = mm.metalake_id AND mm.deleted_at = 0"
+        + " LEFT JOIN "
+        + DomainRelMapper.DOMAIN_REL_TABLE_NAME
+        + " dr ON lp.domain_id = dr.parent_id AND dr.deleted_at = 0"
+        + " LEFT JOIN "
+        + DOMAIN_TABLE_NAME
+        + " dm ON dr.child_id = dm.domain_id AND dm.deleted_at = 0"
+        + BACKING_TAG_JOIN

Review Comment:
   [Nit] This query already resolves the parent through `dr`/`lp`, but 
`BACKING_TAG_JOIN` also adds the `pr`/`pd` parent joins, whose columns are 
unused here. Could we separate the backing-tag and parent join fragments and 
use only the backing-tag fragment here? This keeps the single-statement 
snapshot guarantee while removing redundant SQL. Non-blocking; I have not 
measured a performance impact.



##########
core/src/main/java/org/apache/gravitino/storage/relational/service/DomainRelService.java:
##########
@@ -0,0 +1,348 @@
+/*
+ * 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.gravitino.storage.relational.service;
+
+import static 
org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.EntityAlreadyExistsException;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.exceptions.NonEmptyEntityException;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.meta.DomainEntity;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.DomainMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.DomainRelMapper;
+import org.apache.gravitino.storage.relational.po.DomainPO;
+import org.apache.gravitino.storage.relational.po.DomainRelPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+
+/**
+ * The service that stores the parent edge of sub-domains in the {@code 
domain_rel} table. A domain
+ * has at most one active edge, enforced by the unique key on {@code 
(child_id, deleted_at)}.
+ *
+ * <p>It is also the one parent resolver of domains: domain names carry no 
parent, so every reader
+ * that needs a domain's parent, such as domain reads and the inherited 
authorization checks, gets
+ * it from {@link #getParentDomainName(Long)} or {@link 
#batchGetParentDomainNames(List)}.

Review Comment:
   [Nit] This description is now out of date: domain get/list/batch reads 
project the parent directly in their SQL joins rather than calling these 
resolver methods. Could we distinguish joined entity reads from 
parent-name-only resolution, and describe the authorization consumers as future 
wiring? Keeping that distinction explicit should help preserve the snapshot 
fix. Non-blocking.



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