|  | 
| 26 | 26 | import java.util.HashSet; | 
| 27 | 27 | import java.util.List; | 
| 28 | 28 | import java.util.Map; | 
|  | 29 | +import java.util.Objects; | 
| 29 | 30 | import org.apache.commons.lang3.tuple.ImmutablePair; | 
| 30 | 31 | import org.apache.commons.lang3.tuple.Pair; | 
| 31 | 32 | import org.apache.polaris.core.PolarisCallContext; | 
| @@ -2710,7 +2711,7 @@ public void testLookup() { | 
| 2710 | 2711 |     this.ensureNotExistsById(catalog.getId(), T1.getId(), PolarisEntityType.NAMESPACE); | 
| 2711 | 2712 |   } | 
| 2712 | 2713 | 
 | 
| 2713 |  | -  public void testBatchLoad() { | 
|  | 2714 | +  public void testLoadResolvedEntities() { | 
| 2714 | 2715 |     // load all principals | 
| 2715 | 2716 |     List<EntityNameLookupRecord> principals = | 
| 2716 | 2717 |         polarisMetaStoreManager | 
| @@ -2773,8 +2774,9 @@ public void testBatchLoad() { | 
| 2773 | 2774 |             InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) | 
| 2774 | 2775 |         .hasSize(4) | 
| 2775 | 2776 |         .allSatisfy(entity -> Assertions.assertThat(entity).isNotNull()) | 
| 2776 |  | -        .extracting(r -> (PolarisBaseEntity) r.getEntity()) | 
| 2777 |  | -        .containsExactly(catalog, N1, N1_N2, T1); | 
|  | 2777 | +        .extracting(r -> getEntityCore(r.getEntity())) | 
|  | 2778 | +        .containsExactly( | 
|  | 2779 | +            getEntityCore(catalog), getEntityCore(N1), getEntityCore(N1_N2), getEntityCore(T1)); | 
| 2778 | 2780 | 
 | 
| 2779 | 2781 |     ResolvedPolarisEntity catalogEntity = entitiesResult.getResolvedEntities().get(0); | 
| 2780 | 2782 |     Assertions.assertThat(catalogEntity) | 
| @@ -2866,10 +2868,118 @@ public void testBatchLoad() { | 
| 2866 | 2868 |             ResolvedEntitiesResult::getResolvedEntities, | 
| 2867 | 2869 |             InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) | 
| 2868 | 2870 |         .hasSize(6) | 
| 2869 |  | -        .filteredOn(e -> e != null) | 
|  | 2871 | +        .filteredOn(Objects::nonNull) | 
| 2870 | 2872 |         .hasSize(2) | 
| 2871 |  | -        .extracting(r -> (PolarisBaseEntity) r.getEntity()) | 
| 2872 |  | -        .containsExactly(catalog, T1); | 
|  | 2873 | +        .extracting(r -> getEntityCore(r.getEntity())) | 
|  | 2874 | +        .containsExactly(getEntityCore(catalog), getEntityCore(T1)); | 
|  | 2875 | +  } | 
|  | 2876 | + | 
|  | 2877 | +  public void testLoadResolvedEntitiesById() { | 
|  | 2878 | +    // load all principals | 
|  | 2879 | +    List<EntityNameLookupRecord> principals = | 
|  | 2880 | +        polarisMetaStoreManager | 
|  | 2881 | +            .listEntities( | 
|  | 2882 | +                this.polarisCallContext, | 
|  | 2883 | +                null, | 
|  | 2884 | +                PolarisEntityType.PRINCIPAL, | 
|  | 2885 | +                PolarisEntitySubType.NULL_SUBTYPE, | 
|  | 2886 | +                PageToken.readEverything()) | 
|  | 2887 | +            .getEntities(); | 
|  | 2888 | + | 
|  | 2889 | +    // create new catalog | 
|  | 2890 | +    PolarisBaseEntity catalog = | 
|  | 2891 | +        new PolarisBaseEntity( | 
|  | 2892 | +            PolarisEntityConstants.getNullId(), | 
|  | 2893 | +            polarisMetaStoreManager.generateNewEntityId(this.polarisCallContext).getId(), | 
|  | 2894 | +            PolarisEntityType.CATALOG, | 
|  | 2895 | +            PolarisEntitySubType.NULL_SUBTYPE, | 
|  | 2896 | +            PolarisEntityConstants.getRootEntityId(), | 
|  | 2897 | +            "test"); | 
|  | 2898 | +    CreateCatalogResult catalogCreated = | 
|  | 2899 | +        polarisMetaStoreManager.createCatalog(this.polarisCallContext, catalog, List.of()); | 
|  | 2900 | +    Assertions.assertThat(catalogCreated).isNotNull(); | 
|  | 2901 | + | 
|  | 2902 | +    // load the catalog again, since the grant versions are different | 
|  | 2903 | +    catalog = | 
|  | 2904 | +        polarisMetaStoreManager | 
|  | 2905 | +            .loadEntity( | 
|  | 2906 | +                polarisCallContext, | 
|  | 2907 | +                0L, | 
|  | 2908 | +                catalogCreated.getCatalog().getId(), | 
|  | 2909 | +                PolarisEntityType.CATALOG) | 
|  | 2910 | +            .getEntity(); | 
|  | 2911 | + | 
|  | 2912 | +    // now create all objects | 
|  | 2913 | +    PolarisBaseEntity N1 = this.createEntity(List.of(catalog), PolarisEntityType.NAMESPACE, "N1"); | 
|  | 2914 | +    PolarisBaseEntity N1_N2 = | 
|  | 2915 | +        this.createEntity(List.of(catalog, N1), PolarisEntityType.NAMESPACE, "N2"); | 
|  | 2916 | +    PolarisBaseEntity T1 = | 
|  | 2917 | +        this.createEntity( | 
|  | 2918 | +            List.of(catalog, N1, N1_N2), | 
|  | 2919 | +            PolarisEntityType.TABLE_LIKE, | 
|  | 2920 | +            PolarisEntitySubType.ICEBERG_TABLE, | 
|  | 2921 | +            "T1"); | 
|  | 2922 | + | 
|  | 2923 | +    // batch load all entities. They should all be present and non-null | 
|  | 2924 | +    ResolvedEntitiesResult entitiesResult = | 
|  | 2925 | +        polarisMetaStoreManager.loadResolvedEntities( | 
|  | 2926 | +            polarisCallContext, | 
|  | 2927 | +            PolarisEntityType.NAMESPACE, | 
|  | 2928 | +            List.of( | 
|  | 2929 | +                new PolarisEntityId(N1.getCatalogId(), N1.getId()), | 
|  | 2930 | +                new PolarisEntityId(N1_N2.getCatalogId(), N1_N2.getId()))); | 
|  | 2931 | +    Assertions.assertThat(entitiesResult) | 
|  | 2932 | +        .isNotNull() | 
|  | 2933 | +        .returns(BaseResult.ReturnStatus.SUCCESS, ResolvedEntitiesResult::getReturnStatus) | 
|  | 2934 | +        .extracting( | 
|  | 2935 | +            ResolvedEntitiesResult::getResolvedEntities, | 
|  | 2936 | +            InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) | 
|  | 2937 | +        .hasSize(2) | 
|  | 2938 | +        .allSatisfy(entity -> Assertions.assertThat(entity).isNotNull()) | 
|  | 2939 | +        .extracting(r -> getEntityCore(r.getEntity())) | 
|  | 2940 | +        .containsExactly(getEntityCore(N1), getEntityCore(N1_N2)); | 
|  | 2941 | + | 
|  | 2942 | +    // try entities which do not exist | 
|  | 2943 | +    entitiesResult = | 
|  | 2944 | +        polarisMetaStoreManager.loadResolvedEntities( | 
|  | 2945 | +            polarisCallContext, | 
|  | 2946 | +            PolarisEntityType.CATALOG, | 
|  | 2947 | +            List.of( | 
|  | 2948 | +                new PolarisEntityId(catalog.getId(), 27), | 
|  | 2949 | +                new PolarisEntityId(catalog.getId(), 35))); | 
|  | 2950 | +    Assertions.assertThat(entitiesResult) | 
|  | 2951 | +        .isNotNull() | 
|  | 2952 | +        .returns(BaseResult.ReturnStatus.SUCCESS, ResolvedEntitiesResult::getReturnStatus) | 
|  | 2953 | +        .extracting( | 
|  | 2954 | +            ResolvedEntitiesResult::getResolvedEntities, | 
|  | 2955 | +            InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) | 
|  | 2956 | +        .hasSize(2) | 
|  | 2957 | +        .allSatisfy(entity -> Assertions.assertThat(entity).isNull()); | 
|  | 2958 | + | 
|  | 2959 | +    // existing entities, some with wrong type | 
|  | 2960 | +    entitiesResult = | 
|  | 2961 | +        polarisMetaStoreManager.loadResolvedEntities( | 
|  | 2962 | +            polarisCallContext, | 
|  | 2963 | +            PolarisEntityType.NAMESPACE, | 
|  | 2964 | +            List.of( | 
|  | 2965 | +                new PolarisEntityId(catalog.getCatalogId(), catalog.getId()), | 
|  | 2966 | +                new PolarisEntityId(catalog.getId(), N1_N2.getId()), | 
|  | 2967 | +                new PolarisEntityId(catalog.getId(), T1.getId()))); | 
|  | 2968 | +    Assertions.assertThat(entitiesResult) | 
|  | 2969 | +        .isNotNull() | 
|  | 2970 | +        .returns(BaseResult.ReturnStatus.SUCCESS, ResolvedEntitiesResult::getReturnStatus) | 
|  | 2971 | +        .extracting( | 
|  | 2972 | +            ResolvedEntitiesResult::getResolvedEntities, | 
|  | 2973 | +            InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) | 
|  | 2974 | +        .hasSize(3) | 
|  | 2975 | +        .filteredOn(Objects::nonNull) | 
|  | 2976 | +        .hasSize(1) | 
|  | 2977 | +        .extracting(r -> getEntityCore(r.getEntity())) | 
|  | 2978 | +        .containsExactly(getEntityCore(N1_N2)); | 
|  | 2979 | +  } | 
|  | 2980 | + | 
|  | 2981 | +  private static PolarisEntityCore getEntityCore(PolarisBaseEntity entity) { | 
|  | 2982 | +    return new PolarisEntityCore.Builder<>(entity).build(); | 
| 2873 | 2983 |   } | 
| 2874 | 2984 | 
 | 
| 2875 | 2985 |   /** Test the set of functions for the entity cache */ | 
|  | 
0 commit comments