Skip to content

Commit

Permalink
add strict check for business attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshi0301 committed Dec 10, 2024
1 parent 87568ed commit 291cb2e
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ private Map<String, Object> preloadProperties(AtlasVertex entityVertex, AtlasEnt
AtlasAttribute attribute = entityType.getAttribute(property.key());
TypeCategory typeCategory = attribute != null ? attribute.getAttributeType().getTypeCategory() : null;
TypeCategory elementTypeCategory = attribute != null && attribute.getAttributeType().getTypeCategory() == TypeCategory.ARRAY ? ((AtlasArrayType) attribute.getAttributeType()).getElementType().getTypeCategory() : null;
boolean isBusinessAttribute = attribute == null;
boolean canBeBusinessAttribute = attribute == null;

if (property.isPresent()) {
if (typeCategory == TypeCategory.ARRAY && elementTypeCategory == TypeCategory.PRIMITIVE) {
Expand All @@ -1046,7 +1046,7 @@ private Map<String, Object> preloadProperties(AtlasVertex entityVertex, AtlasEnt
} else {
if (propertiesMap.get(property.key()) == null) {
propertiesMap.put(property.key(), property.value());
} else if (isBusinessAttribute) { // If it is a business attribute, and is a multi-valued attribute
} else if (canBeBusinessAttribute) { // If it is a business attribute, and is a multi-valued attribute
LOG.warn("Duplicate property key {} found for entity vertex: {}", property.key(), entityVertex);
List<Object> values = new ArrayList<>();
values.add(propertiesMap.get(property.key()));
Expand Down Expand Up @@ -1903,22 +1903,23 @@ public Object getVertexAttributePreFetchCache(AtlasVertex vertex, AtlasAttribute
TypeCategory elementTypeCategory = typeCategory == TypeCategory.ARRAY ? ((AtlasArrayType) attribute.getAttributeType()).getElementType().getTypeCategory() : null;
boolean isArrayOfPrimitives = typeCategory.equals(TypeCategory.ARRAY) && elementTypeCategory.equals(TypeCategory.PRIMITIVE);
boolean isPrefetchValueFinal = (typeCategory.equals(TypeCategory.PRIMITIVE) || typeCategory.equals(TypeCategory.ENUM) || typeCategory.equals(TypeCategory.MAP) || isArrayOfPrimitives);
boolean isMultiValueBusinessAttribute = attribute.getDefinedInType() != null && attribute.getDefinedInType().getTypeCategory() == TypeCategory.BUSINESS_METADATA && isArrayOfPrimitives;

// value is present and value is not marker (SPACE for further lookup) and type is primitive or array of primitives
if (properties.get(attribute.getName()) != null && properties.get(attribute.getName()) != StringUtils.SPACE && isPrefetchValueFinal) {
if (properties.get(attribute.getName()) != null && properties.get(attribute.getName()) != StringUtils.SPACE && (isMultiValueBusinessAttribute || isPrefetchValueFinal)) {
return properties.get(attribute.getName());
}

//when value is not present and type is primitive, return null
if(properties.get(attribute.getName()) == null && isPrefetchValueFinal) {
return null;
}

// if value is empty && element is array of primitives, return empty list
if (properties.get(attribute.getName()) == null && isArrayOfPrimitives) {
return new ArrayList<>();
}

//when value is not present and type is primitive, return null
if(properties.get(attribute.getName()) == null && isPrefetchValueFinal) {
return null;
}

// value is present as marker, fetch the value from the vertex
if (ATLAS_INDEXSEARCH_ENABLE_FETCHING_NON_PRIMITIVE_ATTRIBUTES.getBoolean()) {
//AtlasPerfMetrics.MetricRecorder nonPrimitiveAttributes = RequestContext.get().startMetricRecord("processNonPrimitiveAttributes");
Expand Down

0 comments on commit 291cb2e

Please sign in to comment.