collado-mike commented on code in PR #514:
URL: https://github.com/apache/polaris/pull/514#discussion_r1883121365


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/impl/PolarisMetaStoreManagerImpl.java:
##########
@@ -1006,6 +1012,20 @@ public Map<String, String> 
deserializeProperties(PolarisCallContext callCtx, Str
         : new PrincipalSecretsResult(secrets);
   }
 
+  @Override
+  @Nonnull
+  public ResolutionManifestBuilder newResolutionManifestBuilder(

Review Comment:
   This should be completely separate from the `PolarisMetaStoreManager`. I 
think the `Resolver` process is business logic, not persistence and I think the 
`PolarisMetaStoreManager` interface should be focused on persistence only.



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/resolution/ResolutionManifestBuilder.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.persistence.resolution;
+
+import com.google.errorprone.annotations.CanIgnoreReturnValue;

Review Comment:
   Do we use these annotations anywhere else? 



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/impl/PolarisResolutionManifestBuilder.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.persistence.impl;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
+import org.apache.polaris.core.entity.PolarisEntityConstants;
+import org.apache.polaris.core.entity.PolarisEntitySubType;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.entity.PrincipalRoleEntity;
+import org.apache.polaris.core.persistence.EntityNotFoundException;
+import org.apache.polaris.core.persistence.resolution.ResolutionManifest;
+import 
org.apache.polaris.core.persistence.resolution.ResolutionManifestBuilder;
+import org.apache.polaris.core.persistence.resolution.ResolvedPolarisEntity;
+import org.apache.polaris.core.persistence.resolver.ResolverBuilder;
+import org.apache.polaris.core.persistence.resolver.ResolverException;
+import org.apache.polaris.core.persistence.resolver.ResolverPath;
+
+final class PolarisResolutionManifestBuilder implements 
ResolutionManifestBuilder {
+  private Function<EntityNotFoundException, RuntimeException> 
notFoundExceptionMapper = nf -> nf;
+
+  private final Supplier<ResolverBuilder> resolverSupplier;
+  private final AuthenticatedPolarisPrincipal authenticatedPrincipal;
+  private final String catalogName;
+  private final ResolverBuilder primaryResolver;
+  private final PolarisDiagnostics diagnostics;
+
+  private final Map<Object, Integer> pathLookup = new HashMap<>();
+  private final List<ResolverPath> addedPaths = new ArrayList<>();
+  private final Multimap<String, PolarisEntityType> addedTopLevelNames = 
HashMultimap.create();
+  private final Map<Object, ResolverPath> passthroughPaths = new HashMap<>();
+
+  private int currentPathIndex = 0;
+  private ResolvedPolarisEntity rootContainerEntity;
+
+  PolarisResolutionManifestBuilder(
+      AuthenticatedPolarisPrincipal authenticatedPrincipal,
+      String catalogName,
+      Supplier<ResolverBuilder> resolverSupplier,
+      PolarisDiagnostics diagnostics) {
+    this.authenticatedPrincipal = authenticatedPrincipal;
+    this.catalogName = catalogName;
+    this.resolverSupplier = resolverSupplier;
+    this.primaryResolver = resolverSupplier.get();
+    this.diagnostics = diagnostics;
+
+    // TODO: Make the rootContainer lookup no longer optional in the 
persistence store.
+    // For now, we'll try to resolve the rootContainer as "optional", and only 
if we fail to find
+    // it, we'll use the "simulated" rootContainer entity.
+    addTopLevelName(PolarisEntityConstants.getRootContainerName(), 
PolarisEntityType.ROOT, true);
+  }
+
+  @Override
+  public ResolutionManifestBuilder withRootContainerEntity(
+      ResolvedPolarisEntity rootContainerEntity) {
+    this.rootContainerEntity = rootContainerEntity;
+    return this;
+  }
+
+  @Override
+  public ResolutionManifestBuilder addTopLevelName(
+      String entityName, PolarisEntityType entityType, boolean optional) {
+    addedTopLevelNames.put(entityName, entityType);
+    if (optional) {
+      primaryResolver.addOptionalEntityByName(entityType, entityName);
+    } else {
+      primaryResolver.addEntityByName(entityType, entityName);
+    }
+    return this;
+  }
+
+  @Override
+  public ResolutionManifestBuilder addPath(ResolverPath resolverPath, String 
catalogRoleName) {
+    return addPathInternal(resolverPath, catalogRoleName);
+  }
+
+  @Override
+  public ResolutionManifestBuilder addPath(ResolverPath resolverPath, 
Namespace namespace) {
+    return addPathInternal(resolverPath, namespace);
+  }
+
+  @Override
+  public ResolutionManifestBuilder addPath(
+      ResolverPath resolverPath, TableIdentifier tableIdentifier) {
+    return addPathInternal(resolverPath, tableIdentifier);
+  }
+
+  private ResolutionManifestBuilder addPathInternal(ResolverPath path, Object 
key) {
+    primaryResolver.addPath(path);
+    pathLookup.put(key, currentPathIndex);
+    addedPaths.add(path);
+    ++currentPathIndex;
+    return this;
+  }
+
+  @Override
+  public ResolutionManifestBuilder addPassthroughPath(
+      ResolverPath resolverPath, TableIdentifier tableIdentifier) {
+    return addPassthroughPathInternal(resolverPath, tableIdentifier);
+  }
+
+  @Override
+  public ResolutionManifestBuilder addPassthroughPath(
+      ResolverPath resolverPath, Namespace namespace) {
+    return addPassthroughPathInternal(resolverPath, namespace);
+  }
+
+  private ResolutionManifestBuilder addPassthroughPathInternal(
+      ResolverPath resolverPath, Object key) {
+    addPathInternal(resolverPath, key);
+    passthroughPaths.put(key, resolverPath);
+    return this;
+  }
+
+  @Override
+  public ResolutionManifestBuilder notFoundExceptionMapper(
+      Function<EntityNotFoundException, RuntimeException> 
notFoundExceptionMapper) {
+    this.notFoundExceptionMapper = notFoundExceptionMapper;
+    return this;
+  }
+
+  @Override
+  public ResolutionManifest buildResolved() {
+    return buildResolved(null);
+  }
+
+  @Override
+  public ResolutionManifest buildResolved(PolarisEntitySubType subType) {
+
+    try {
+      var resolver = primaryResolver.buildResolved();
+
+      List<PrincipalRoleEntity> activatedPrincipalRoles =
+          resolver.getResolvedCallerPrincipalRoles().stream()
+              .map(ce -> PrincipalRoleEntity.of(ce.getEntity()))
+              .collect(Collectors.toList());
+      
this.authenticatedPrincipal.setActivatedPrincipalRoles(activatedPrincipalRoles);

Review Comment:
   Why is this pulled out of the `Resolver` process? I mean, I don't think it 
should be in there, but I think it should be part of the construction of the 
`AuthenticatedPolarisPrincipal`, not here. I'd scope this change to keep the 
logic inside the `Resolver` process for now, then extract the PrincipalRole 
resolution as part of a new change.



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/resolution/ResolutionManifestBuilder.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.persistence.resolution;
+
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import java.util.function.Function;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.polaris.core.entity.PolarisEntitySubType;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.persistence.EntityNotFoundException;
+import org.apache.polaris.core.persistence.resolver.ResolverPath;
+
+public interface ResolutionManifestBuilder {
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder withRootContainerEntity(
+      ResolvedPolarisEntity simulatedResolvedRootContainerEntity);
+
+  /** Adds a name of a top-level entity (Catalog, Principal, PrincipalRole) to 
be resolved. */
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder addTopLevelName(
+      String topLevelEntityName, PolarisEntityType entityType, boolean 
optional);
+
+  /**
+   * Adds a path that will be statically resolved with the primary Resolver 
when resolveAll() is
+   * called, and which contributes to the resolution status of whether all 
paths have successfully
+   * resolved.
+   *
+   * @param catalogRoleName the friendly lookup key for retrieving 
resolvedPaths after resolveAll()
+   */
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder addPath(ResolverPath resolverPath, String 
catalogRoleName);
+
+  /**
+   * Adds a path that will be statically resolved with the primary Resolver 
when resolveAll() is
+   * called, and which contributes to the resolution status of whether all 
paths have successfully
+   * resolved.
+   *
+   * @param namespace the friendly lookup key for retrieving resolvedPaths 
after resolveAll()
+   */
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder addPath(ResolverPath resolverPath, Namespace 
namespace);
+
+  /**
+   * Adds a path that will be statically resolved with the primary Resolver 
when resolveAll() is
+   * called, and which contributes to the resolution status of whether all 
paths have successfully
+   * resolved.
+   *
+   * @param tableIdentifier the friendly lookup key for retrieving 
resolvedPaths after resolveAll()
+   */
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder addPath(ResolverPath resolverPath, TableIdentifier 
tableIdentifier);
+
+  /**
+   * Adds a path that is allowed to be dynamically resolved with a new 
Resolver when
+   * getPassthroughResolvedPath is called. These paths are also included in 
the primary static
+   * resolution set resolved during resolveAll().
+   */
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder addPassthroughPath(
+      ResolverPath resolverPath, TableIdentifier tableIdentifier);
+
+  /**
+   * Adds a path that is allowed to be dynamically resolved with a new 
Resolver when
+   * getPassthroughResolvedPath is called. These paths are also included in 
the primary static
+   * resolution set resolved during resolveAll().
+   */
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder addPassthroughPath(ResolverPath resolverPath, 
Namespace namespace);
+
+  @CanIgnoreReturnValue
+  ResolutionManifestBuilder notFoundExceptionMapper(
+      Function<EntityNotFoundException, RuntimeException> 
notFoundExceptionMapper);
+
+  ResolutionManifest buildResolved(PolarisEntitySubType subType);
+
+  ResolutionManifest buildResolved();

Review Comment:
   `build` or `buildManifest`



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/ResolverImpl.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.persistence.resolver;
+
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import java.util.List;
+import java.util.Map;
+import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.persistence.cache.EntityCacheByNameKey;
+import org.apache.polaris.core.persistence.cache.EntityCacheEntry;
+
+final class ResolverImpl implements Resolver {

Review Comment:
   Why not push these fields into the `PolarisResolutionManifest`? It seems 
that the `ResolverImpl` is just a container, but the 
`PolarisResolutionManifestBuilder` seems to build a fully resolved manifest. 
Can we just consolidate these?



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