Skip to content

Commit

Permalink
feat: add qualifiedName hierarchy after preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
sumandas0 committed Aug 21, 2024
1 parent 9f5ea5f commit 03da5ca
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ private void personaPolicyToESDslClauses(List<AtlasEntity> policies,
* This will be dictated by the feature flag ENABLE_PERSONA_HIERARCHY_FILTER
*/

// If asset resource ends with /* then add it in hierarchical filter
boolean isHierarchical = asset.endsWith("/*");
if (isHierarchical) {
asset = asset.substring(0, asset.length() - 2);
}
boolean isWildcard = asset.contains("*") || asset.contains("?");

if (isWildcard) {
allowClauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, asset)));
} else if (useHierarchicalQualifiedNameFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,6 @@ private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)),
"create entity: type=", entity.getTypeName());
}
createQualifiedNameHierarchyField(entity, context.getVertex(entity.getGuid()));
}
}
// for existing entities, skip update if incoming entity doesn't have any change
Expand All @@ -1476,10 +1475,6 @@ private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean
AtlasEntityDiffResult diffResult = entityComparator.getDiffResult(entity, storedVertex, !storeDifferentialAudits);

if (diffResult.hasDifference()) {
if (diffResult.getDiffEntity().hasAttribute(QUALIFIED_NAME)) {
createQualifiedNameHierarchyField(entity, storedVertex);
}

if (storeDifferentialAudits) {
diffResult.getDiffEntity().setGuid(entity.getGuid());
reqContext.cacheDifferentialEntity(diffResult.getDiffEntity());
Expand Down Expand Up @@ -1534,6 +1529,20 @@ private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean

executePreProcessor(context);

// Updating hierarchy after preprocessor is executed so that qualifiedName update during preprocessor is considered
for (AtlasEntity entity : context.getCreatedEntities()) {
createQualifiedNameHierarchyField(entity, context.getVertex(entity.getGuid()));
}

for (AtlasEntity entity : context.getUpdatedEntities()) {
// If qualifiedName update is part of the update, update the qualifiedName hierarchy field
AtlasEntity diffEntity = RequestContext.get().getDifferentialEntitiesMap().get(entity.getGuid());
if (diffEntity != null && diffEntity.hasAttribute(QUALIFIED_NAME)) {
createQualifiedNameHierarchyField(entity, context.getVertex(entity.getGuid()));
}
}


EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate,
replaceClassifications, replaceBusinessAttributes, isOverwriteBusinessAttribute);

Expand Down Expand Up @@ -1808,28 +1817,36 @@ private AtlasStruct getStarredDetailsStruct(String assetStarredBy, long assetSta
}

private void createQualifiedNameHierarchyField(AtlasEntity entity, AtlasVertex vertex) {
if (entity.hasAttribute(QUALIFIED_NAME)) {
String qualifiedName = (String) entity.getAttribute(QUALIFIED_NAME);
if (StringUtils.isNotEmpty(qualifiedName)) {
vertex.removeProperty(QUALIFIED_NAME_HIERARCHY_PROPERTY_KEY);
String[] parts = qualifiedName.split("/");
StringBuilder currentPath = new StringBuilder();

for (int i = 0; i < parts.length; i++) {
String part = parts[i];
if (StringUtils.isNotEmpty(part)) {
if (i > 0) {
currentPath.append("/");
}
currentPath.append(part);
// i>1 reason: we don't want to add the first part of the qualifiedName as it is the entity name
// Example qualifiedName : default/snowflake/123/db_name we only want `default/snowflake/123` and `default/snowflake/123/db_name`
if (i > 1) {
AtlasGraphUtilsV2.addEncodedProperty(vertex, QUALIFIED_NAME_HIERARCHY_PROPERTY_KEY, currentPath.toString());
MetricRecorder metric = RequestContext.get().startMetricRecord("createQualifiedNameHierarchyField");
try {
if (vertex == null) {
vertex = AtlasGraphUtilsV2.findByGuid(graph, entity.getGuid());
}
if (entity.hasAttribute(QUALIFIED_NAME)) {
String qualifiedName = (String) entity.getAttribute(QUALIFIED_NAME);
if (StringUtils.isNotEmpty(qualifiedName)) {
vertex.removeProperty(QUALIFIED_NAME_HIERARCHY_PROPERTY_KEY);
String[] parts = qualifiedName.split("/");
StringBuilder currentPath = new StringBuilder();

for (int i = 0; i < parts.length; i++) {
String part = parts[i];
if (StringUtils.isNotEmpty(part)) {
if (i > 0) {
currentPath.append("/");
}
currentPath.append(part);
// i>1 reason: we don't want to add the first part of the qualifiedName as it is the entity name
// Example qualifiedName : default/snowflake/123/db_name we only want `default/snowflake/123` and `default/snowflake/123/db_name`
if (i > 1) {
AtlasGraphUtilsV2.addEncodedProperty(vertex, QUALIFIED_NAME_HIERARCHY_PROPERTY_KEY, currentPath.toString());
}
}
}
}
}
} finally {
RequestContext.get().endMetricRecord(metric);
}
}

Expand Down

0 comments on commit 03da5ca

Please sign in to comment.