in polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java [1430:1535]
public PolarisBaseEntity updateEntity(
List<PolarisEntityCore> catalogPath,
PolarisBaseEntity entity,
String props,
String internalProps) {
// ok, remember version and grants_version
int version = entity.getEntityVersion();
int grantRecsVersion = entity.getGrantRecordsVersion();
// derive the catalogId for that entity
long catalogId =
(catalogPath == null) ? PolarisEntityConstants.getNullId() : catalogPath.get(0).getId();
Assertions.assertThat(catalogId).isEqualTo(entity.getCatalogId());
// let's make some property updates
entity.setProperties(props);
entity.setInternalProperties(internalProps);
// lookup that entity, ensure it exists
PolarisBaseEntity beforeUpdateEntity =
polarisMetaStoreManager
.loadEntity(
this.polarisCallContext, entity.getCatalogId(), entity.getId(), entity.getType())
.getEntity();
// update that property
PolarisBaseEntity updatedEntity =
polarisMetaStoreManager
.updateEntityPropertiesIfNotChanged(this.polarisCallContext, catalogPath, entity)
.getEntity();
// if version mismatch, nothing should be updated
if (beforeUpdateEntity == null
|| beforeUpdateEntity.getEntityVersion() != entity.getEntityVersion()) {
Assertions.assertThat(updatedEntity).isNull();
// refresh catalog info
entity =
polarisMetaStoreManager
.loadEntity(
this.polarisCallContext, entity.getCatalogId(), entity.getId(), entity.getType())
.getEntity();
// ensure nothing has changed
if (beforeUpdateEntity != null && entity != null) {
Assertions.assertThat(entity.getEntityVersion())
.isEqualTo(beforeUpdateEntity.getEntityVersion());
Assertions.assertThat(entity.getGrantRecordsVersion())
.isEqualTo(beforeUpdateEntity.getGrantRecordsVersion());
Assertions.assertThat(entity.getProperties()).isEqualTo(beforeUpdateEntity.getProperties());
Assertions.assertThat(entity.getInternalProperties())
.isEqualTo(beforeUpdateEntity.getInternalProperties());
}
return null;
}
// entity should have been updated
Assertions.assertThat(updatedEntity).isNotNull();
// read back this entity and ensure that the update was performed
PolarisBaseEntity afterUpdateEntity =
this.ensureExistsById(
catalogPath,
entity.getId(),
true,
entity.getName(),
entity.getType(),
entity.getSubType());
// verify that version has changed, but not grantRecsVersion
Assertions.assertThat(updatedEntity.getEntityVersion()).isEqualTo(version + 1);
Assertions.assertThat(entity.getEntityVersion()).isEqualTo(version);
Assertions.assertThat(afterUpdateEntity.getEntityVersion()).isEqualTo(version + 1);
// grantRecsVersion should not have changed
Assertions.assertThat(updatedEntity.getGrantRecordsVersion()).isEqualTo(grantRecsVersion);
Assertions.assertThat(entity.getGrantRecordsVersion()).isEqualTo(grantRecsVersion);
Assertions.assertThat(afterUpdateEntity.getGrantRecordsVersion()).isEqualTo(grantRecsVersion);
// update should have been performed
Assertions.assertThat(jsonNode(updatedEntity.getProperties()))
.isEqualTo(jsonNode(entity.getProperties()));
Assertions.assertThat(jsonNode(afterUpdateEntity.getProperties()))
.isEqualTo(jsonNode(entity.getProperties()));
Assertions.assertThat(jsonNode(updatedEntity.getInternalProperties()))
.isEqualTo(jsonNode(entity.getInternalProperties()));
Assertions.assertThat(jsonNode(afterUpdateEntity.getInternalProperties()))
.isEqualTo(jsonNode(entity.getInternalProperties()));
// lookup the tracking slice to verify this has been updated too
if (supportsChangeTracking) {
List<PolarisChangeTrackingVersions> versions =
polarisMetaStoreManager
.loadEntitiesChangeTracking(
this.polarisCallContext, List.of(new PolarisEntityId(catalogId, entity.getId())))
.getChangeTrackingVersions();
Assertions.assertThat(versions).hasSize(1);
Assertions.assertThat(versions.get(0).getEntityVersion())
.isEqualTo(updatedEntity.getEntityVersion());
Assertions.assertThat(versions.get(0).getGrantRecordsVersion())
.isEqualTo(updatedEntity.getGrantRecordsVersion());
}
return updatedEntity;
}