roryqi commented on code in PR #11074:
URL: https://github.com/apache/gravitino/pull/11074#discussion_r3256681568


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/HierarchicalConversionPOStorageOps.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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 java.util.List;
+import java.util.function.UnaryOperator;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.utils.HierarchicalSchemaUtil;
+
+/**
+ * Wraps a {@link BasePOStorageOps} to bridge the hierarchical schema naming 
convention. Identifiers
+ * and namespace segments in logical form (logical separator) are translated 
to physical form
+ * (physical separator) before delegating. Two optional PO rewriters allow 
callers to translate a PO
+ * field across the boundary: {@code physicalToLogicalRewriter} converts POs 
returned from the
+ * delegate back to logical form, and {@code logicalToPhysicalRewriter} 
converts POs passed into the
+ * delegate down to storage form. The terminology used throughout this class 
is exclusively
+ * physical/logical; there is no separate read/write naming.
+ *
+ * @param <PO> persistent object type
+ * @param <Mapper> MyBatis mapper type
+ */
+public class HierarchicalConversionPOStorageOps<PO, Mapper> extends 
BasePOStorageOps<PO, Mapper> {
+
+  private final BasePOStorageOps<PO, Mapper> delegate;
+  private final UnaryOperator<PO> physicalToLogicalRewriter;
+  private final UnaryOperator<PO> logicalToPhysicalRewriter;
+
+  public HierarchicalConversionPOStorageOps(BasePOStorageOps<PO, Mapper> 
delegate) {
+    this(delegate, UnaryOperator.identity(), UnaryOperator.identity());
+  }
+
+  public HierarchicalConversionPOStorageOps(
+      BasePOStorageOps<PO, Mapper> delegate,
+      UnaryOperator<PO> physicalToLogicalRewriter,
+      UnaryOperator<PO> logicalToPhysicalRewriter) {
+    this.delegate = delegate;
+    this.physicalToLogicalRewriter = physicalToLogicalRewriter;
+    this.logicalToPhysicalRewriter = logicalToPhysicalRewriter;
+  }
+
+  @Override
+  public void insertPO(Mapper mapper, PO po, boolean overwrite) {
+    delegate.insertPO(mapper, convertLogicalToPhysical(po), overwrite);
+  }
+
+  @Override
+  public void batchInsertPOs(Mapper mapper, List<PO> pos, boolean overwrite) {
+    delegate.batchInsertPOs(mapper, convertLogicalToPhysical(pos), overwrite);
+  }
+
+  @Override
+  public Integer updatePO(Mapper mapper, PO newPO, PO oldPO) {
+    return delegate.updatePO(
+        mapper, convertLogicalToPhysical(newPO), 
convertLogicalToPhysical(oldPO));
+  }
+
+  @Override
+  public PO getPO(Mapper mapper, Long parentId, String name) {
+    return convertPhysicalToLogical(
+        delegate.getPO(mapper, parentId, toPhysicalIfHierarchical(name)));
+  }
+
+  @Override
+  public List<PO> listPOs(Mapper mapper, Long parentId) {
+    return convertPhysicalToLogical(delegate.listPOs(mapper, parentId));
+  }
+
+  @Override
+  public List<PO> listPOs(Mapper mapper, Namespace logicalNamespace, 
List<String> names) {
+    Namespace physicalNamespace = logicalToPhysicalNamespace(logicalNamespace);
+    List<String> physicalNames =
+        names.stream()
+            .map(HierarchicalConversionPOStorageOps::toPhysicalIfHierarchical)
+            .collect(Collectors.toList());

Review Comment:
   This case won't occur.



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