poojanilangekar commented on code in PR #2223: URL: https://github.com/apache/polaris/pull/2223#discussion_r2255846641
########## service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java: ########## @@ -2034,6 +2136,74 @@ private boolean grantPrivilegeOnTableLikeToRole( .isSuccess(); } + /** + * Creates and persists the missing synthetic table-like entity and its parent namespace entities + * for external catalogs. + * + * @param catalogEntity the external passthrough facade catalog entity. + * @param identifier the path of the table-like entity(including the namespace). + * @param subTypes the expected subtypes of the table-like entity + * @param existingPathWrapper the partially resolved path currently stored in the metastore. + * @return the resolved path wrapper + */ + private PolarisResolvedPathWrapper createSyntheticTableLikeEntities( + CatalogEntity catalogEntity, + TableIdentifier identifier, + List<PolarisEntitySubType> subTypes, + PolarisResolvedPathWrapper existingPathWrapper) { + + Namespace namespace = identifier.namespace(); + PolarisResolvedPathWrapper resolvedNamespacePathWrapper = + !namespace.isEmpty() + ? createSyntheticNamespaceEntities(catalogEntity, namespace, existingPathWrapper) + : existingPathWrapper; + + if (resolvedNamespacePathWrapper == null + || (!namespace.isEmpty() + && !resolvedNamespacePathWrapper.isFullyResolvedNamespace( + catalogEntity.getName(), namespace))) { + throw new RuntimeException( + String.format( + "Failed to create synthetic namespace entities for namespace %s in catalog %s", + namespace.toString(), catalogEntity.getName())); + } + + // TODO: Instead of creating a synthetic table-like entity, rely on external catalog mediated + // backfill. + PolarisEntity parentNamespaceEntity = resolvedNamespacePathWrapper.getRawLeafEntity(); + PolarisEntity syntheticTableEntity = + new PolarisEntity.Builder() Review Comment: Done. ########## service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java: ########## @@ -1730,6 +1746,79 @@ public boolean revokePrivilegeOnNamespaceFromRole( .isSuccess(); } + /** + * Creates and persists the missing synthetic namespace entities for external catalogs. + * + * @param catalogEntity the external passthrough facade catalog entity. + * @param namespace the expected fully resolved namespace to be created. + * @param existingPath the partially resolved path currently stored in the metastore. + * @return the fully resolved path wrapper. + */ + private PolarisResolvedPathWrapper createSyntheticNamespaceEntities( + CatalogEntity catalogEntity, Namespace namespace, PolarisResolvedPathWrapper existingPath) { + + if (existingPath == null) { + throw new IllegalStateException( + String.format("Catalog entity %s does not exist.", catalogEntity.getName())); + } + + List<PolarisEntity> completePath = new ArrayList<>(existingPath.getRawFullPath()); + PolarisEntity currentParent = existingPath.getRawLeafEntity(); + + String[] allNamespaceLevels = namespace.levels(); + int matchingLevel = -1; + for (PolarisEntity entity : completePath.subList(1, completePath.size())) { + if (entity.getName().equals(allNamespaceLevels[matchingLevel + 1])) { + matchingLevel++; + } else { + break; + } + } + + for (int i = matchingLevel + 1; i < allNamespaceLevels.length; i++) { + String namespacePart = allNamespaceLevels[i]; + + // TODO: Instead of creating synthetic entitties, rely on external catalog mediated backfill. + PolarisEntity syntheticNamespace = + new PolarisEntity.Builder() Review Comment: Done. -- 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: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org