Skip to content

Commit a07ea01

Browse files
authored
Remove BaseMetaStoreManager.serializeProperties (#2374)
similar to 7af85be we should prefer the existing helper methods on the entity instead
1 parent 12ab618 commit a07ea01

File tree

3 files changed

+10
-77
lines changed

3 files changed

+10
-77
lines changed

polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private void dropEntity(
252252
// if it is a principal, we also need to drop the secrets
253253
if (entity.getType() == PolarisEntityType.PRINCIPAL) {
254254
// get internal properties
255-
Map<String, String> properties = this.deserializeProperties(entity.getInternalProperties());
255+
Map<String, String> properties = entity.getInternalPropertiesAsMap();
256256

257257
// get client_id
258258
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
@@ -432,7 +432,7 @@ private void revokeGrantRecord(
432432
// validate input
433433
callCtx.getDiagServices().checkNotNull(catalog, "unexpected_null_catalog");
434434

435-
Map<String, String> internalProp = getInternalPropertyMap(catalog);
435+
Map<String, String> internalProp = catalog.getInternalPropertiesAsMap();
436436
String integrationIdentifierOrId =
437437
internalProp.get(PolarisEntityConstants.getStorageIntegrationIdentifierPropertyName());
438438
String storageConfigInfoStr =
@@ -751,8 +751,7 @@ private void revokeGrantRecord(
751751
principal);
752752

753753
// get internal properties
754-
Map<String, String> properties =
755-
this.deserializeProperties(refreshPrincipal.getInternalProperties());
754+
Map<String, String> properties = refreshPrincipal.getInternalPropertiesAsMap();
756755

757756
// get client_id
758757
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
@@ -798,14 +797,14 @@ private void revokeGrantRecord(
798797
.generateNewPrincipalSecrets(callCtx, principal.getName(), principal.getId());
799798

800799
// generate properties
801-
Map<String, String> internalProperties = getInternalPropertyMap(principal);
800+
Map<String, String> internalProperties = principal.getInternalPropertiesAsMap();
802801
internalProperties.put(
803802
PolarisEntityConstants.getClientIdPropertyName(), principalSecrets.getPrincipalClientId());
804803

805804
// remember client id
806805
PolarisBaseEntity updatedPrincipal =
807806
new PolarisBaseEntity.Builder(principal)
808-
.internalProperties(this.serializeProperties(internalProperties))
807+
.internalPropertiesAsMap(internalProperties)
809808
.build();
810809
// now create and persist new catalog entity
811810
EntityResult lowLevelResult = this.persistNewEntity(callCtx, ms, updatedPrincipal);
@@ -1616,21 +1615,6 @@ private void revokeGrantRecord(
16161615
}
16171616
}
16181617

1619-
/**
1620-
* Get the internal property map for an entity
1621-
*
1622-
* @param entity the target entity
1623-
* @return a map of string representing the internal properties
1624-
*/
1625-
public Map<String, String> getInternalPropertyMap(@Nonnull PolarisBaseEntity entity) {
1626-
String internalPropStr = entity.getInternalProperties();
1627-
Map<String, String> res = new HashMap<>();
1628-
if (internalPropStr == null) {
1629-
return res;
1630-
}
1631-
return deserializeProperties(internalPropStr);
1632-
}
1633-
16341618
/** {@inheritDoc} */
16351619
@Override
16361620
public @Nonnull ResolvedEntityResult loadResolvedEntityById(

polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
package org.apache.polaris.core.persistence;
2020

21-
import com.fasterxml.jackson.core.JsonProcessingException;
22-
import com.fasterxml.jackson.core.type.TypeReference;
23-
import com.fasterxml.jackson.databind.ObjectMapper;
2421
import jakarta.annotation.Nonnull;
2522
import java.util.Map;
2623
import org.apache.polaris.core.PolarisCallContext;
@@ -34,8 +31,6 @@
3431

3532
/** Shared basic PolarisMetaStoreManager logic for transactional and non-transactional impls. */
3633
public abstract class BaseMetaStoreManager implements PolarisMetaStoreManager {
37-
/** mapper, allows to serialize/deserialize properties to/from JSON */
38-
private static final ObjectMapper MAPPER = new ObjectMapper();
3934

4035
public static PolarisStorageConfigurationInfo extractStorageConfiguration(
4136
@Nonnull PolarisDiagnostics diagnostics, PolarisBaseEntity reloadedEntity) {
@@ -52,36 +47,6 @@ public static PolarisStorageConfigurationInfo extractStorageConfiguration(
5247
return PolarisStorageConfigurationInfo.deserialize(storageConfigInfoStr);
5348
}
5449

55-
/**
56-
* Given the internal property as a map of key/value pairs, serialize it to a String
57-
*
58-
* @param properties a map of key/value pairs
59-
* @return a String, the JSON representation of the map
60-
*/
61-
public String serializeProperties(Map<String, String> properties) {
62-
try {
63-
// Deserialize the JSON string to a Map<String, String>
64-
return MAPPER.writeValueAsString(properties);
65-
} catch (JsonProcessingException ex) {
66-
throw new RuntimeException("serializeProperties failed: " + ex.getMessage(), ex);
67-
}
68-
}
69-
70-
/**
71-
* Given the serialized properties, deserialize those to a {@code Map<String, String>}
72-
*
73-
* @param properties a JSON string representing the set of properties
74-
* @return a Map of string
75-
*/
76-
public Map<String, String> deserializeProperties(String properties) {
77-
try {
78-
// Deserialize the JSON string to a Map<String, String>
79-
return MAPPER.readValue(properties, new TypeReference<>() {});
80-
} catch (JsonProcessingException ex) {
81-
throw new RuntimeException("deserializeProperties failed: " + ex.getMessage(), ex);
82-
}
83-
}
84-
8550
/**
8651
* Performs basic validation of expected invariants on a new entity, then returns the entity with
8752
* fields filled out for which the persistence layer is responsible.

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private void dropEntity(
240240
// if it is a principal, we also need to drop the secrets
241241
if (entity.getType() == PolarisEntityType.PRINCIPAL) {
242242
// get internal properties
243-
Map<String, String> properties = this.deserializeProperties(entity.getInternalProperties());
243+
Map<String, String> properties = entity.getInternalPropertiesAsMap();
244244

245245
// get client_id
246246
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
@@ -743,8 +743,7 @@ private void bootstrapPolarisService(
743743
principal);
744744

745745
// get internal properties
746-
Map<String, String> properties =
747-
this.deserializeProperties(refreshPrincipal.getInternalProperties());
746+
Map<String, String> properties = refreshPrincipal.getInternalPropertiesAsMap();
748747

749748
// get client_id
750749
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
@@ -792,14 +791,14 @@ private void bootstrapPolarisService(
792791
ms.generateNewPrincipalSecretsInCurrentTxn(callCtx, principal.getName(), principal.getId());
793792

794793
// generate properties
795-
Map<String, String> internalProperties = getInternalPropertyMap(principal);
794+
Map<String, String> internalProperties = principal.getInternalPropertiesAsMap();
796795
internalProperties.put(
797796
PolarisEntityConstants.getClientIdPropertyName(), principalSecrets.getPrincipalClientId());
798797

799798
// remember client id
800799
PolarisBaseEntity updatedPrincipal =
801800
new PolarisBaseEntity.Builder(principal)
802-
.internalProperties(this.serializeProperties(internalProperties))
801+
.internalPropertiesAsMap(internalProperties)
803802
.build();
804803

805804
// now create and persist new catalog entity
@@ -926,7 +925,7 @@ private void bootstrapPolarisService(
926925
// get metastore we should be using
927926
TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore());
928927

929-
Map<String, String> internalProp = getInternalPropertyMap(catalog);
928+
Map<String, String> internalProp = catalog.getInternalPropertiesAsMap();
930929
String integrationIdentifierOrId =
931930
internalProp.get(PolarisEntityConstants.getStorageIntegrationIdentifierPropertyName());
932931
String storageConfigInfoStr =
@@ -2017,21 +2016,6 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
20172016
}
20182017
}
20192018

2020-
/**
2021-
* Get the internal property map for an entity
2022-
*
2023-
* @param entity the target entity
2024-
* @return a map of string representing the internal properties
2025-
*/
2026-
public Map<String, String> getInternalPropertyMap(@Nonnull PolarisBaseEntity entity) {
2027-
String internalPropStr = entity.getInternalProperties();
2028-
Map<String, String> res = new HashMap<>();
2029-
if (internalPropStr == null) {
2030-
return res;
2031-
}
2032-
return deserializeProperties(internalPropStr);
2033-
}
2034-
20352019
/** {@link #loadResolvedEntityById(PolarisCallContext, long, long, PolarisEntityType)} */
20362020
private @Nonnull ResolvedEntityResult loadResolvedEntityById(
20372021
@Nonnull PolarisCallContext callCtx,

0 commit comments

Comments
 (0)