This is an automated email from the ASF dual-hosted git repository.

emaynard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new 7af85be7f Use asMap property helpers (#2347)
7af85be7f is described below

commit 7af85be7f45c933a377314a669e2a16633c93532
Author: Christopher Lambert <xn...@gmx.de>
AuthorDate: Fri Aug 15 22:27:26 2025 +0200

    Use asMap property helpers (#2347)
    
    seems like these helpers existed for a long time but were just not
    getting used consistently
---
 .../polaris/core/entity/PolarisBaseEntity.java     | 40 ++++------------------
 .../AtomicOperationMetaStoreManager.java           | 21 ++++--------
 .../core/persistence/BaseMetaStoreManager.java     |  3 +-
 .../TransactionalMetaStoreManagerImpl.java         | 20 ++++-------
 .../storage/cache/StorageCredentialCacheTest.java  |  9 ++---
 .../BasePolarisMetaStoreManagerTest.java           |  4 +--
 .../persistence/PolarisTestMetaStoreManager.java   | 29 +++++-----------
 7 files changed, 35 insertions(+), 91 deletions(-)

diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisBaseEntity.java
 
b/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisBaseEntity.java
index c50c16fcf..80b0a9640 100644
--- 
a/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisBaseEntity.java
+++ 
b/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisBaseEntity.java
@@ -19,12 +19,9 @@
 package org.apache.polaris.core.entity;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import org.apache.polaris.core.persistence.PolarisObjectMapperUtil;
 
 /**
  * Base polaris entity representing all attributes of a Polaris Entity. This 
is used to exchange
@@ -34,9 +31,6 @@ public class PolarisBaseEntity extends PolarisEntityCore {
 
   public static final String EMPTY_MAP_STRING = "{}";
 
-  // to serialize/deserialize properties
-  private static final ObjectMapper MAPPER = new ObjectMapper();
-
   // the type of the entity when it was resolved
   protected final int subTypeCode;
 
@@ -106,25 +100,15 @@ public class PolarisBaseEntity extends PolarisEntityCore {
 
   @JsonIgnore
   public Map<String, String> getPropertiesAsMap() {
-    if (properties == null) {
-      return new HashMap<>();
-    }
-    try {
-      return MAPPER.readValue(properties, new TypeReference<>() {});
-    } catch (JsonProcessingException ex) {
-      throw new IllegalStateException(
-          String.format("Failed to deserialize json. properties %s", 
properties), ex);
-    }
+    return PolarisObjectMapperUtil.deserializeProperties(getProperties());
   }
 
   @JsonIgnore
-  public static String convertPropertiesToJson(Map<String, String> properties) 
{
-    try {
-      return properties == null ? null : MAPPER.writeValueAsString(properties);
-    } catch (JsonProcessingException ex) {
-      throw new IllegalStateException(
-          String.format("Failed to serialize json. properties %s", 
properties), ex);
+  protected static String convertPropertiesToJson(Map<String, String> 
properties) {
+    if (properties == null || properties.isEmpty()) {
+      return EMPTY_MAP_STRING;
     }
+    return PolarisObjectMapperUtil.serializeProperties(properties);
   }
 
   public String getInternalProperties() {
@@ -133,17 +117,7 @@ public class PolarisBaseEntity extends PolarisEntityCore {
 
   @JsonIgnore
   public Map<String, String> getInternalPropertiesAsMap() {
-    if (this.internalProperties == null) {
-      return new HashMap<>();
-    }
-    try {
-      return MAPPER.readValue(this.internalProperties, new TypeReference<>() 
{});
-    } catch (JsonProcessingException ex) {
-      throw new IllegalStateException(
-          String.format(
-              "Failed to deserialize json. internalProperties %s", 
this.internalProperties),
-          ex);
-    }
+    return 
PolarisObjectMapperUtil.deserializeProperties(getInternalProperties());
   }
 
   public int getGrantRecordsVersion() {
diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java
 
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java
index 5e598f9b4..c52e9273f 100644
--- 
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java
+++ 
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java
@@ -858,9 +858,7 @@ public class AtomicOperationMetaStoreManager extends 
BaseMetaStoreManager {
     }
 
     PolarisBaseEntity principal = loadEntityResult.getEntity();
-    Map<String, String> internalProps =
-        PolarisObjectMapperUtil.deserializeProperties(
-            principal.getInternalProperties() == null ? "{}" : 
principal.getInternalProperties());
+    Map<String, String> internalProps = principal.getInternalPropertiesAsMap();
 
     boolean doReset =
         reset
@@ -877,15 +875,13 @@ public class AtomicOperationMetaStoreManager extends 
BaseMetaStoreManager {
             
PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE)) {
       internalProps.put(
           PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE, 
"true");
-      principalBuilder.internalProperties(
-          PolarisObjectMapperUtil.serializeProperties(internalProps));
+      principalBuilder.internalPropertiesAsMap(internalProps);
       principalBuilder.entityVersion(principal.getEntityVersion() + 1);
       ms.writeEntity(callCtx, principalBuilder.build(), true, principal);
     } else if (internalProps.containsKey(
         PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE)) {
       
internalProps.remove(PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE);
-      principalBuilder.internalProperties(
-          PolarisObjectMapperUtil.serializeProperties(internalProps));
+      principalBuilder.internalPropertiesAsMap(internalProps);
       principalBuilder.entityVersion(principal.getEntityVersion() + 1);
       ms.writeEntity(callCtx, principalBuilder.build(), true, principal);
     }
@@ -1230,7 +1226,7 @@ public class AtomicOperationMetaStoreManager extends 
BaseMetaStoreManager {
           PolarisTaskConstants.TASK_DATA, 
PolarisObjectMapperUtil.serialize(refreshEntityToDrop));
       PolarisBaseEntity.Builder taskEntityBuilder =
           new PolarisBaseEntity.Builder()
-              
.properties(PolarisObjectMapperUtil.serializeProperties(properties))
+              .propertiesAsMap(properties)
               .id(ms.generateNewId(callCtx))
               .catalogId(0L)
               .name("entityCleanup_" + entityToDrop.getId())
@@ -1238,8 +1234,7 @@ public class AtomicOperationMetaStoreManager extends 
BaseMetaStoreManager {
               .subTypeCode(PolarisEntitySubType.NULL_SUBTYPE.getCode())
               .createTimestamp(clock.millis());
       if (cleanupProperties != null) {
-        taskEntityBuilder.internalProperties(
-            PolarisObjectMapperUtil.serializeProperties(cleanupProperties));
+        taskEntityBuilder.internalPropertiesAsMap(cleanupProperties);
       }
       // TODO: Add a way to create the task entities atomically with dropping 
the entity;
       // in the meantime, if the server fails partway through a dropEntity, 
it's possible that
@@ -1523,8 +1518,7 @@ public class AtomicOperationMetaStoreManager extends 
BaseMetaStoreManager {
                 task -> {
                   PolarisBaseEntity.Builder updatedTaskBuilder =
                       new PolarisBaseEntity.Builder(task);
-                  Map<String, String> properties =
-                      
PolarisObjectMapperUtil.deserializeProperties(task.getProperties());
+                  Map<String, String> properties = task.getPropertiesAsMap();
                   
properties.put(PolarisTaskConstants.LAST_ATTEMPT_EXECUTOR_ID, executorId);
                   properties.put(
                       PolarisTaskConstants.LAST_ATTEMPT_START_TIME, 
String.valueOf(clock.millis()));
@@ -1534,8 +1528,7 @@ public class AtomicOperationMetaStoreManager extends 
BaseMetaStoreManager {
                           Integer.parseInt(
                                   
properties.getOrDefault(PolarisTaskConstants.ATTEMPT_COUNT, "0"))
                               + 1));
-                  updatedTaskBuilder.properties(
-                      PolarisObjectMapperUtil.serializeProperties(properties));
+                  updatedTaskBuilder.propertiesAsMap(properties);
                   EntityResult result =
                       updateEntityPropertiesIfNotChanged(callCtx, null, 
updatedTaskBuilder.build());
                   if (result.getReturnStatus() == 
BaseResult.ReturnStatus.SUCCESS) {
diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java
 
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java
index 9820d8950..a56eeda3d 100644
--- 
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java
+++ 
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java
@@ -39,8 +39,7 @@ public abstract class BaseMetaStoreManager implements 
PolarisMetaStoreManager {
 
   public static PolarisStorageConfigurationInfo extractStorageConfiguration(
       @Nonnull PolarisDiagnostics diagnostics, PolarisBaseEntity 
reloadedEntity) {
-    Map<String, String> propMap =
-        
PolarisObjectMapperUtil.deserializeProperties(reloadedEntity.getInternalProperties());
+    Map<String, String> propMap = reloadedEntity.getInternalPropertiesAsMap();
     String storageConfigInfoStr =
         propMap.get(PolarisEntityConstants.getStorageConfigInfoPropertyName());
 
diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java
 
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java
index 50ebc52a7..18484a551 100644
--- 
a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java
+++ 
b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java
@@ -893,9 +893,7 @@ public class TransactionalMetaStoreManagerImpl extends 
BaseMetaStoreManager {
 
     PolarisBaseEntity principal = loadEntityResult.getEntity();
     PolarisBaseEntity.Builder principalBuilder = new 
PolarisBaseEntity.Builder(principal);
-    Map<String, String> internalProps =
-        PolarisObjectMapperUtil.deserializeProperties(
-            principal.getInternalProperties() == null ? "{}" : 
principal.getInternalProperties());
+    Map<String, String> internalProps = principal.getInternalPropertiesAsMap();
 
     boolean doReset =
         reset
@@ -911,15 +909,13 @@ public class TransactionalMetaStoreManagerImpl extends 
BaseMetaStoreManager {
             
PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE)) {
       internalProps.put(
           PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE, 
"true");
-      principalBuilder.internalProperties(
-          PolarisObjectMapperUtil.serializeProperties(internalProps));
+      principalBuilder.internalPropertiesAsMap(internalProps);
       principalBuilder.entityVersion(principal.getEntityVersion() + 1);
       ms.writeEntityInCurrentTxn(callCtx, principalBuilder.build(), true, 
principal);
     } else if (internalProps.containsKey(
         PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE)) {
       
internalProps.remove(PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE);
-      principalBuilder.internalProperties(
-          PolarisObjectMapperUtil.serializeProperties(internalProps));
+      principalBuilder.internalPropertiesAsMap(internalProps);
       principalBuilder.entityVersion(principal.getEntityVersion() + 1);
       ms.writeEntityInCurrentTxn(callCtx, principalBuilder.build(), true, 
principal);
     }
@@ -1438,10 +1434,9 @@ public class TransactionalMetaStoreManagerImpl extends 
BaseMetaStoreManager {
               .typeCode(PolarisEntityType.TASK.getCode())
               .subTypeCode(PolarisEntitySubType.NULL_SUBTYPE.getCode())
               .createTimestamp(clock.millis())
-              
.properties(PolarisObjectMapperUtil.serializeProperties(properties));
+              .propertiesAsMap(properties);
       if (cleanupProperties != null) {
-        taskEntityBuilder.internalProperties(
-            PolarisObjectMapperUtil.serializeProperties(cleanupProperties));
+        taskEntityBuilder.internalPropertiesAsMap(cleanupProperties);
       }
       PolarisBaseEntity taskEntity = taskEntityBuilder.build();
       createEntityIfNotExists(callCtx, ms, null, taskEntity);
@@ -1975,8 +1970,7 @@ public class TransactionalMetaStoreManagerImpl extends 
BaseMetaStoreManager {
             .map(
                 task -> {
                   PolarisBaseEntity.Builder updatedTask = new 
PolarisBaseEntity.Builder(task);
-                  Map<String, String> properties =
-                      
PolarisObjectMapperUtil.deserializeProperties(task.getProperties());
+                  Map<String, String> properties = task.getPropertiesAsMap();
                   
properties.put(PolarisTaskConstants.LAST_ATTEMPT_EXECUTOR_ID, executorId);
                   properties.put(
                       PolarisTaskConstants.LAST_ATTEMPT_START_TIME, 
String.valueOf(clock.millis()));
@@ -1986,7 +1980,7 @@ public class TransactionalMetaStoreManagerImpl extends 
BaseMetaStoreManager {
                           Integer.parseInt(
                                   
properties.getOrDefault(PolarisTaskConstants.ATTEMPT_COUNT, "0"))
                               + 1));
-                  
updatedTask.properties(PolarisObjectMapperUtil.serializeProperties(properties));
+                  updatedTask.propertiesAsMap(properties);
                   EntityResult result =
                       updateEntityPropertiesIfNotChanged(callCtx, ms, null, 
updatedTask.build());
                   if (result.getReturnStatus() == 
BaseResult.ReturnStatus.SUCCESS) {
diff --git 
a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
 
b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
index 5364fa843..07b233228 100644
--- 
a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
+++ 
b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java
@@ -36,7 +36,6 @@ 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.persistence.PolarisMetaStoreManager;
-import org.apache.polaris.core.persistence.PolarisObjectMapperUtil;
 import org.apache.polaris.core.persistence.dao.entity.BaseResult;
 import org.apache.polaris.core.persistence.dao.entity.ScopedCredentialsResult;
 import 
org.apache.polaris.core.persistence.transactional.TransactionalPersistence;
@@ -246,9 +245,7 @@ public class StorageCredentialCacheTest {
       internalMap.put(
           PolarisEntityConstants.getStorageConfigInfoPropertyName(), 
"newStorageConfig");
       PolarisBaseEntity updateEntity =
-          new PolarisBaseEntity.Builder(entity)
-              
.internalProperties(PolarisObjectMapperUtil.serializeProperties(internalMap))
-              .build();
+          new 
PolarisBaseEntity.Builder(entity).internalPropertiesAsMap(internalMap).build();
       storageCredentialCache.getOrGenerateSubScopeCreds(
           metaStoreManager,
           callCtx,
@@ -286,9 +283,7 @@ public class StorageCredentialCacheTest {
       internalMap.put(
           PolarisEntityConstants.getStorageConfigInfoPropertyName(), 
"newStorageConfig");
       PolarisBaseEntity updateEntity =
-          new PolarisBaseEntity.Builder(entity)
-              
.internalProperties(PolarisObjectMapperUtil.serializeProperties(internalMap))
-              .build();
+          new 
PolarisBaseEntity.Builder(entity).internalPropertiesAsMap(internalMap).build();
       storageCredentialCache.getOrGenerateSubScopeCreds(
           metaStoreManager,
           callCtx,
diff --git 
a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java
 
b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java
index 12096be46..6adb042ac 100644
--- 
a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java
+++ 
b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java
@@ -292,8 +292,8 @@ public abstract class BasePolarisMetaStoreManagerTest {
             entry ->
                 Assertions.assertThat(entry)
                     .extracting(
-                        e -> 
PolarisObjectMapperUtil.deserializeProperties(e.getProperties()))
-                    .asInstanceOf(InstanceOfAssertFactories.map(String.class, 
String.class))
+                        PolarisBaseEntity::getPropertiesAsMap,
+                        InstanceOfAssertFactories.map(String.class, 
String.class))
                     
.containsEntry(PolarisTaskConstants.LAST_ATTEMPT_EXECUTOR_ID, executorId)
                     .containsEntry(PolarisTaskConstants.ATTEMPT_COUNT, "1"));
     Set<String> firstTasks =
diff --git 
a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java
 
b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java
index f4aa7aa46..646aeee51 100644
--- 
a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java
+++ 
b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java
@@ -18,8 +18,6 @@
  */
 package org.apache.polaris.core.persistence;
 
-import static 
org.apache.polaris.core.entity.PolarisBaseEntity.convertPropertiesToJson;
-
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -419,11 +417,8 @@ public class PolarisTestMetaStoreManager {
             .subTypeCode(PolarisEntitySubType.NULL_SUBTYPE.getCode())
             .parentId(PolarisEntityConstants.getRootEntityId())
             .name(name)
-            .internalProperties(
-                PolarisObjectMapperUtil.serializeProperties(
-                    Map.of(
-                        
PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE,
-                        "true")))
+            .internalPropertiesAsMap(
+                
Map.of(PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE, 
"true"))
             .build();
 
     CreatePrincipalResult createPrincipalResult =
@@ -466,8 +461,7 @@ public class PolarisTestMetaStoreManager {
         .isEqualTo(secrets.getSecondarySecretHash());
 
     Map<String, String> internalProperties =
-        PolarisObjectMapperUtil.deserializeProperties(
-            createPrincipalResult.getPrincipal().getInternalProperties());
+        createPrincipalResult.getPrincipal().getInternalPropertiesAsMap();
     Assertions.assertThat(
             internalProperties.get(
                 
PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE))
@@ -510,8 +504,7 @@ public class PolarisTestMetaStoreManager {
                 createPrincipalResult.getPrincipal().getId(),
                 createPrincipalResult.getPrincipal().getType())
             .getEntity();
-    internalProperties =
-        
PolarisObjectMapperUtil.deserializeProperties(reloadPrincipal.getInternalProperties());
+    internalProperties = reloadPrincipal.getInternalPropertiesAsMap();
     Assertions.assertThat(
             internalProperties.get(
                 
PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE))
@@ -567,8 +560,7 @@ public class PolarisTestMetaStoreManager {
             .loadEntity(
                 this.polarisCallContext, 0L, principalEntity.getId(), 
principalEntity.getType())
             .getEntity();
-    internalProperties =
-        
PolarisObjectMapperUtil.deserializeProperties(newPrincipal.getInternalProperties());
+    internalProperties = newPrincipal.getInternalPropertiesAsMap();
     Assertions.assertThat(
             internalProperties.get(
                 
PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE))
@@ -601,8 +593,7 @@ public class PolarisTestMetaStoreManager {
             .loadEntity(
                 this.polarisCallContext, 0L, principalEntity.getId(), 
principalEntity.getType())
             .getEntity();
-    internalProperties =
-        
PolarisObjectMapperUtil.deserializeProperties(finalPrincipal.getInternalProperties());
+    internalProperties = finalPrincipal.getInternalPropertiesAsMap();
     Assertions.assertThat(
             internalProperties.get(
                 
PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE))
@@ -669,7 +660,7 @@ public class PolarisTestMetaStoreManager {
             .subTypeCode(entitySubType.getCode())
             .parentId(parentId)
             .name(name)
-            .properties(convertPropertiesToJson(properties))
+            .propertiesAsMap(properties)
             .build();
     PolarisBaseEntity entity =
         polarisMetaStoreManager
@@ -870,11 +861,9 @@ public class PolarisTestMetaStoreManager {
       Assertions.assertThat(cleanupTask).isNotNull();
       
Assertions.assertThat(cleanupTask.getType()).isEqualTo(PolarisEntityType.TASK);
       Assertions.assertThat(cleanupTask.getInternalProperties()).isNotNull();
-      Map<String, String> internalProperties =
-          
PolarisObjectMapperUtil.deserializeProperties(cleanupTask.getInternalProperties());
+      Map<String, String> internalProperties = 
cleanupTask.getInternalPropertiesAsMap();
       Assertions.assertThat(internalProperties).isEqualTo(cleanupProperties);
-      Map<String, String> properties =
-          
PolarisObjectMapperUtil.deserializeProperties(cleanupTask.getProperties());
+      Map<String, String> properties = cleanupTask.getPropertiesAsMap();
       Assertions.assertThat(properties).isNotNull();
       
Assertions.assertThat(properties.get(PolarisTaskConstants.TASK_DATA)).isNotNull();
       PolarisBaseEntity droppedEntity =

Reply via email to