adutra commented on code in PR #4023:
URL: https://github.com/apache/polaris/pull/4023#discussion_r3396980960


##########
polaris-core/src/main/java/org/apache/polaris/core/storage/StorageConfigOverrideResolver.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.storage;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.apache.polaris.core.entity.PolarisEntityConstants;
+import org.jspecify.annotations.NonNull;
+
+/**
+ * Resolves the effective {@link PolarisStorageConfigurationInfo} for an 
entity hierarchy by
+ * applying any nearest-ancestor {@code storage_name_override} on top of the 
catalog's base storage
+ * configuration.
+ *
+ * <p>The input list is in root-to-leaf order (the catalog is at index 0). The 
walk runs
+ * leaf-to-root and:
+ *
+ * <ol>
+ *   <li>Captures the first {@code storage_name_override} encountered (nearest 
wins).
+ *   <li>Returns the first {@code storage_configuration_info} encountered — 
the base config.
+ * </ol>
+ *
+ * <p>If a base config exists and an override was captured, the result is 
{@link
+ * PolarisStorageConfigurationInfo#withStorageName} applied to the base. If no 
base config exists,
+ * the result is empty regardless of any override.
+ */
+public final class StorageConfigOverrideResolver {
+
+  private StorageConfigOverrideResolver() {}
+
+  /**
+   * Walk {@code entityPath} leaf-to-root and return the effective storage 
configuration. The base
+   * config is sourced from the nearest entity that has {@code 
storage_configuration_info} in its
+   * internal properties; if any closer ancestor (including the leaf itself) 
carries {@code
+   * storage_name_override}, that name replaces the base config's {@code 
storageName}.
+   *
+   * @param entityPath entities in root-to-leaf order; the catalog is at index 0
+   * @return effective config, or empty if no entity in the chain has a base 
storage config
+   */
+  public static Optional<PolarisStorageConfigurationInfo> 
resolveEffectiveConfig(
+      @NonNull List<? extends PolarisEntity> entityPath) {
+    String override = null;
+    for (int i = entityPath.size() - 1; i >= 0; i--) {
+      Map<String, String> internalProps = 
entityPath.get(i).getInternalPropertiesAsMap();
+      if (override == null) {
+        String candidate =
+            
internalProps.get(PolarisEntityConstants.getStorageNameOverridePropertyName());
+        if (candidate != null && !candidate.isEmpty()) {
+          override = candidate;
+        }
+      }
+      String serializedBase =
+          
internalProps.get(PolarisEntityConstants.getStorageConfigInfoPropertyName());
+      if (serializedBase != null) {
+        PolarisStorageConfigurationInfo base =
+            PolarisStorageConfigurationInfo.deserialize(serializedBase);
+        if (override != null) {
+          return 
Optional.of(PolarisStorageConfigurationInfo.withStorageName(base, override));

Review Comment:
   Exactly, I don't think it's a good idea to let users define the storage 
profile name on a namespace or table in a managed environment.
   
   > I remember that introducing a separate crud resource for storages was 
rejected
   
   You mean for storage profile names or for `PolarisStorageConfigurationInfo`? 
I think we need to settle on this topic; I am leaning more towards the idea of 
leveraging the management API. That's the direction suggested in [this design 
doc](https://docs.google.com/document/d/1hbDkE-w84Pn_112iW2vCnlDKPDtyg8flaYcFGjvD120/edit?tab=t.0)
 by @sririshindra.



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