@@ -328,7 +328,7 @@ private void dropEntity(
328328 // load the grantee (either a catalog/principal role or a principal) and increment its grants
329329 // version
330330 PolarisBaseEntity granteeEntity =
331- ms .lookupEntity (callCtx , grantee .getCatalogId (), grantee .getId ());
331+ ms .lookupEntity (callCtx , grantee .getCatalogId (), grantee .getId (), grantee . getTypeCode () );
332332 callCtx
333333 .getDiagServices ()
334334 .checkNotNull (granteeEntity , "grantee_not_found" , "grantee={}" , grantee );
@@ -341,7 +341,8 @@ private void dropEntity(
341341 // we also need to invalidate the grants on that securable so that we can reload them.
342342 // load the securable and increment its grants version
343343 PolarisBaseEntity securableEntity =
344- ms .lookupEntity (callCtx , securable .getCatalogId (), securable .getId ());
344+ ms .lookupEntity (
345+ callCtx , securable .getCatalogId (), securable .getId (), securable .getTypeCode ());
345346 callCtx
346347 .getDiagServices ()
347348 .checkNotNull (securableEntity , "securable_not_found" , "securable={}" , securable );
@@ -404,7 +405,7 @@ private void revokeGrantRecord(
404405
405406 // load the grantee and increment its grants version
406407 PolarisBaseEntity refreshGrantee =
407- ms .lookupEntity (callCtx , grantee .getCatalogId (), grantee .getId ());
408+ ms .lookupEntity (callCtx , grantee .getCatalogId (), grantee .getId (), grantee . getTypeCode () );
408409 callCtx
409410 .getDiagServices ()
410411 .checkNotNull (
@@ -418,7 +419,8 @@ private void revokeGrantRecord(
418419 // we also need to invalidate the grants on that securable so that we can reload them.
419420 // load the securable and increment its grants version
420421 PolarisBaseEntity refreshSecurable =
421- ms .lookupEntity (callCtx , securable .getCatalogId (), securable .getId ());
422+ ms .lookupEntity (
423+ callCtx , securable .getCatalogId (), securable .getId (), securable .getTypeCode ());
422424 callCtx
423425 .getDiagServices ()
424426 .checkNotNull (
@@ -460,7 +462,7 @@ private void revokeGrantRecord(
460462
461463 // check if that catalog has already been created
462464 PolarisBaseEntity refreshCatalog =
463- ms .lookupEntity (callCtx , catalog .getCatalogId (), catalog .getId ());
465+ ms .lookupEntity (callCtx , catalog .getCatalogId (), catalog .getId (), catalog . getTypeCode () );
464466
465467 // if found, probably a retry, simply return the previously created catalog
466468 if (refreshCatalog != null ) {
@@ -822,7 +824,8 @@ public Map<String, String> deserializeProperties(PolarisCallContext callCtx, Str
822824
823825 // check if that catalog has already been created
824826 PolarisBaseEntity refreshPrincipal =
825- ms .lookupEntity (callCtx , principal .getCatalogId (), principal .getId ());
827+ ms .lookupEntity (
828+ callCtx , principal .getCatalogId (), principal .getId (), principal .getTypeCode ());
826829
827830 // if found, probably a retry, simply return the previously created principal
828831 if (refreshPrincipal != null ) {
@@ -950,7 +953,12 @@ public Map<String, String> deserializeProperties(PolarisCallContext callCtx, Str
950953 @ Nonnull String oldSecretHash ) {
951954 // if not found, the principal must have been dropped
952955 EntityResult loadEntityResult =
953- loadEntity (callCtx , ms , PolarisEntityConstants .getNullId (), principalId );
956+ loadEntity (
957+ callCtx ,
958+ ms ,
959+ PolarisEntityConstants .getNullId (),
960+ principalId ,
961+ PolarisEntityType .PRINCIPAL .getCode ());
954962 if (loadEntityResult .getReturnStatus () != BaseResult .ReturnStatus .SUCCESS ) {
955963 return null ;
956964 }
@@ -1061,7 +1069,8 @@ public Map<String, String> deserializeProperties(PolarisCallContext callCtx, Str
10611069 callCtx .getDiagServices ().checkNotNull (entity .getName (), "unexpected_null_entity_name" );
10621070
10631071 // first, check if the entity has already been created, in which case we will simply return it
1064- PolarisBaseEntity entityFound = ms .lookupEntity (callCtx , entity .getCatalogId (), entity .getId ());
1072+ PolarisBaseEntity entityFound =
1073+ ms .lookupEntity (callCtx , entity .getCatalogId (), entity .getId (), entity .getTypeCode ());
10651074 if (entityFound != null ) {
10661075 // probably the client retried, simply return it
10671076 return new EntityResult (entityFound );
@@ -1158,7 +1167,7 @@ public Map<String, String> deserializeProperties(PolarisCallContext callCtx, Str
11581167
11591168 // lookup the entity, cannot be null
11601169 PolarisBaseEntity entityRefreshed =
1161- ms .lookupEntity (callCtx , entity .getCatalogId (), entity .getId ());
1170+ ms .lookupEntity (callCtx , entity .getCatalogId (), entity .getId (), entity . getTypeCode () );
11621171 callCtx
11631172 .getDiagServices ()
11641173 .checkNotNull (entityRefreshed , "unexpected_entity_not_found" , "entity={}" , entity );
@@ -1280,7 +1289,11 @@ public Map<String, String> deserializeProperties(PolarisCallContext callCtx, Str
12801289
12811290 // find the entity to rename
12821291 PolarisBaseEntity refreshEntityToRename =
1283- ms .lookupEntity (callCtx , entityToRename .getCatalogId (), entityToRename .getId ());
1292+ ms .lookupEntity (
1293+ callCtx ,
1294+ entityToRename .getCatalogId (),
1295+ entityToRename .getId (),
1296+ entityToRename .getTypeCode ());
12841297
12851298 // if this entity was not found, return failure. Not expected here because it was
12861299 // resolved successfully (see above)
@@ -1389,7 +1402,8 @@ public Map<String, String> deserializeProperties(PolarisCallContext callCtx, Str
13891402
13901403 // first find the entity to drop
13911404 PolarisBaseEntity refreshEntityToDrop =
1392- ms .lookupEntity (callCtx , entityToDrop .getCatalogId (), entityToDrop .getId ());
1405+ ms .lookupEntity (
1406+ callCtx , entityToDrop .getCatalogId (), entityToDrop .getId (), entityToDrop .getTypeCode ());
13931407
13941408 // if this entity was not found, return failure
13951409 if (refreshEntityToDrop == null ) {
@@ -1921,14 +1935,15 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
19211935 callCtx , () -> this .loadEntitiesChangeTracking (callCtx , ms , entityIds ));
19221936 }
19231937
1924- /** Refer to {@link #loadEntity(PolarisCallContext, long, long)} */
1938+ /** Refer to {@link #loadEntity(PolarisCallContext, long, long, PolarisEntityType )} */
19251939 private @ Nonnull EntityResult loadEntity (
19261940 @ Nonnull PolarisCallContext callCtx ,
19271941 @ Nonnull TransactionalPersistence ms ,
19281942 long entityCatalogId ,
1929- long entityId ) {
1943+ long entityId ,
1944+ int entityTypeCode ) {
19301945 // this is an easy one
1931- PolarisBaseEntity entity = ms .lookupEntity (callCtx , entityCatalogId , entityId );
1946+ PolarisBaseEntity entity = ms .lookupEntity (callCtx , entityCatalogId , entityId , entityTypeCode );
19321947 return (entity != null )
19331948 ? new EntityResult (entity )
19341949 : new EntityResult (BaseResult .ReturnStatus .ENTITY_NOT_FOUND , null );
@@ -1937,13 +1952,17 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
19371952 /** {@inheritDoc} */
19381953 @ Override
19391954 public @ Nonnull EntityResult loadEntity (
1940- @ Nonnull PolarisCallContext callCtx , long entityCatalogId , long entityId ) {
1955+ @ Nonnull PolarisCallContext callCtx ,
1956+ long entityCatalogId ,
1957+ long entityId ,
1958+ @ Nonnull PolarisEntityType entityType ) {
19411959 // get metastore we should be using
19421960 TransactionalPersistence ms = callCtx .getMetaStore ();
19431961
19441962 // need to run inside a read transaction
19451963 return ms .runInReadTransaction (
1946- callCtx , () -> this .loadEntity (callCtx , ms , entityCatalogId , entityId ));
1964+ callCtx ,
1965+ () -> this .loadEntity (callCtx , ms , entityCatalogId , entityId , entityType .getCode ()));
19471966 }
19481967
19491968 /** Refer to {@link #loadTasks(PolarisCallContext, String, int)} */
@@ -2011,6 +2030,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
20112030 @ Nonnull PolarisCallContext callCtx ,
20122031 long catalogId ,
20132032 long entityId ,
2033+ PolarisEntityType entityType ,
20142034 boolean allowListOperation ,
20152035 @ Nonnull Set <String > allowedReadLocations ,
20162036 @ Nonnull Set <String > allowedWriteLocations ) {
@@ -2024,7 +2044,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
20242044 "allowed_locations_to_subscope_is_required" );
20252045
20262046 // reload the entity, error out if not found
2027- EntityResult reloadedEntity = loadEntity (callCtx , catalogId , entityId );
2047+ EntityResult reloadedEntity = loadEntity (callCtx , catalogId , entityId , entityType );
20282048 if (reloadedEntity .getReturnStatus () != BaseResult .ReturnStatus .SUCCESS ) {
20292049 return new ScopedCredentialsResult (
20302050 reloadedEntity .getReturnStatus (), reloadedEntity .getExtraInformation ());
@@ -2067,6 +2087,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
20672087 @ Nonnull PolarisCallContext callCtx ,
20682088 long catalogId ,
20692089 long entityId ,
2090+ PolarisEntityType entityType ,
20702091 @ Nonnull Set <PolarisStorageActions > actions ,
20712092 @ Nonnull Set <String > locations ) {
20722093 // get meta store we should be using
@@ -2077,7 +2098,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
20772098 !actions .isEmpty () && !locations .isEmpty (),
20782099 "locations_and_operations_privileges_are_required" );
20792100 // reload the entity, error out if not found
2080- EntityResult reloadedEntity = loadEntity (callCtx , catalogId , entityId );
2101+ EntityResult reloadedEntity = loadEntity (callCtx , catalogId , entityId , entityType );
20812102 if (reloadedEntity .getReturnStatus () != BaseResult .ReturnStatus .SUCCESS ) {
20822103 return new ValidateAccessResult (
20832104 reloadedEntity .getReturnStatus (), reloadedEntity .getExtraInformation ());
@@ -2129,15 +2150,16 @@ public Map<String, String> getInternalPropertyMap(
21292150 return deserializeProperties (callCtx , internalPropStr );
21302151 }
21312152
2132- /** {@link #loadResolvedEntityById(PolarisCallContext, long, long)} */
2153+ /** {@link #loadResolvedEntityById(PolarisCallContext, long, long, PolarisEntityType )} */
21332154 private @ Nonnull ResolvedEntityResult loadResolvedEntityById (
21342155 @ Nonnull PolarisCallContext callCtx ,
21352156 @ Nonnull TransactionalPersistence ms ,
21362157 long entityCatalogId ,
2137- long entityId ) {
2158+ long entityId ,
2159+ int typeCode ) {
21382160
21392161 // load that entity
2140- PolarisBaseEntity entity = ms .lookupEntity (callCtx , entityCatalogId , entityId );
2162+ PolarisBaseEntity entity = ms .lookupEntity (callCtx , entityCatalogId , entityId , typeCode );
21412163
21422164 // if entity not found, return null
21432165 if (entity == null ) {
@@ -2161,16 +2183,22 @@ public Map<String, String> getInternalPropertyMap(
21612183 /** {@inheritDoc} */
21622184 @ Override
21632185 public @ Nonnull ResolvedEntityResult loadResolvedEntityById (
2164- @ Nonnull PolarisCallContext callCtx , long entityCatalogId , long entityId ) {
2186+ @ Nonnull PolarisCallContext callCtx ,
2187+ long entityCatalogId ,
2188+ long entityId ,
2189+ PolarisEntityType entityType ) {
21652190 // get metastore we should be using
21662191 TransactionalPersistence ms = callCtx .getMetaStore ();
21672192
21682193 // need to run inside a read transaction
21692194 return ms .runInReadTransaction (
2170- callCtx , () -> this .loadResolvedEntityById (callCtx , ms , entityCatalogId , entityId ));
2195+ callCtx ,
2196+ () ->
2197+ this .loadResolvedEntityById (
2198+ callCtx , ms , entityCatalogId , entityId , entityType .getCode ()));
21712199 }
21722200
2173- /** {@link #loadResolvedEntityById(PolarisCallContext, long, long)} */
2201+ /** {@link #loadResolvedEntityById(PolarisCallContext, long, long, PolarisEntityType )} */
21742202 private @ Nonnull ResolvedEntityResult loadResolvedEntityByName (
21752203 @ Nonnull PolarisCallContext callCtx ,
21762204 @ Nonnull TransactionalPersistence ms ,
@@ -2292,7 +2320,7 @@ public Map<String, String> getInternalPropertyMap(
22922320 // load the entity if something changed
22932321 final PolarisBaseEntity entity ;
22942322 if (entityVersion != entityVersions .getEntityVersion ()) {
2295- entity = ms .lookupEntity (callCtx , entityCatalogId , entityId );
2323+ entity = ms .lookupEntity (callCtx , entityCatalogId , entityId , entityType . getCode () );
22962324
22972325 // if not found, return null
22982326 if (entity == null ) {
0 commit comments