Commit 1e8fa7e5 by Mandar Ambawane Committed by Sarath Subramanian

ATLAS-3709 Issues with quick search/suggestions in conjunction with Business Metadata attributes

parent 3ff785a8
...@@ -92,7 +92,7 @@ public class ChangedTypeDefs { ...@@ -92,7 +92,7 @@ public class ChangedTypeDefs {
} }
public boolean hasBusinessMetadataDef() { public boolean hasBusinessMetadataDef() {
return hasBusinessMetadataDef(createdTypeDefs) || hasEntityDef(updatedTypeDefs) || hasEntityDef(deletedTypeDefs); return hasBusinessMetadataDef(createdTypeDefs) || hasBusinessMetadataDef(updatedTypeDefs) || hasBusinessMetadataDef(deletedTypeDefs);
} }
private boolean hasBusinessMetadataDef(List<? extends AtlasBaseTypeDef> typeDefs) { private boolean hasBusinessMetadataDef(List<? extends AtlasBaseTypeDef> typeDefs) {
......
...@@ -980,22 +980,9 @@ public class AtlasTypeRegistry { ...@@ -980,22 +980,9 @@ public class AtlasTypeRegistry {
new Exception().fillInStackTrace()); new Exception().fillInStackTrace());
} else if (typeRegistryUpdateLock.getHoldCount() == 1) { } else if (typeRegistryUpdateLock.getHoldCount() == 1) {
if (ttr != null && commitUpdates) { if (ttr != null && commitUpdates) {
// copy indexName for entity attributes from current typeRegistry to new one // copy indexName for attributes from current typeRegistry to new one
for (AtlasEntityType ttrEntityType : ttr.getAllEntityTypes()) { copyIndexNameFromCurrent(ttr.getAllEntityTypes());
AtlasEntityType currEntityType = typeRegistry.getEntityTypeByName(ttrEntityType.getTypeName()); copyIndexNameFromCurrent(ttr.getAllBusinessMetadataTypes());
if (currEntityType != null) { // ttrEntityType could be a new type introduced
for (AtlasAttribute attribute : ttrEntityType.getAllAttributes().values()) {
if (StringUtils.isEmpty(attribute.getIndexFieldName())) {
AtlasAttribute currAttribute = currEntityType.getAttribute(attribute.getName());
if (currAttribute != null) {
attribute.setIndexFieldName(currAttribute.getIndexFieldName());
}
}
}
}
}
typeRegistry.registryData = ttr.registryData; typeRegistry.registryData = ttr.registryData;
} }
...@@ -1018,6 +1005,34 @@ public class AtlasTypeRegistry { ...@@ -1018,6 +1005,34 @@ public class AtlasTypeRegistry {
LOG.debug("<== releaseTypeRegistryForUpdate()"); LOG.debug("<== releaseTypeRegistryForUpdate()");
} }
private void copyIndexNameFromCurrent(Collection<? extends AtlasStructType> ttrTypes) {
for (AtlasStructType ttrType : ttrTypes) {
final AtlasStructType currType;
if (ttrType instanceof AtlasEntityType) {
currType = typeRegistry.getEntityTypeByName(ttrType.getTypeName());
} else if (ttrType instanceof AtlasBusinessMetadataType) {
currType = typeRegistry.getBusinessMetadataTypeByName(ttrType.getTypeName());
} else {
currType = null;
}
if (currType == null) { // ttrType could be a new type introduced
continue;
}
for (AtlasAttribute ttrAttribute : ttrType.getAllAttributes().values()) {
if (StringUtils.isEmpty(ttrAttribute.getIndexFieldName())) {
AtlasAttribute currAttribute = currType.getAttribute(ttrAttribute.getName());
if (currAttribute != null) {
ttrAttribute.setIndexFieldName(currAttribute.getIndexFieldName());
}
}
}
}
}
} }
} }
......
...@@ -209,14 +209,18 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -209,14 +209,18 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
LOG.debug("Type definition load completed. Informing the completion to IndexChangeListeners."); LOG.debug("Type definition load completed. Informing the completion to IndexChangeListeners.");
} }
Collection<AtlasEntityDef> entityDefs = typeRegistry.getAllEntityDefs(); ChangedTypeDefs changedTypeDefs = null;
ChangedTypeDefs changedTypeDefs = new ChangedTypeDefs(null, new ArrayList<>(entityDefs), null); AtlasGraphManagement management = null;
AtlasGraphManagement management = null;
try { try {
management = provider.get().getManagementSystem(); management = provider.get().getManagementSystem();
//resolve index fields names for the new entity attributes. //resolve index fields names for the new entity attributes.
changedTypeDefs = new ChangedTypeDefs(null, new ArrayList<>(typeRegistry.getAllEntityDefs()), null);
resolveIndexFieldNames(management, changedTypeDefs);
//resolve index fields names for the new business metadata attributes.
changedTypeDefs = new ChangedTypeDefs(null, new ArrayList<>(typeRegistry.getAllBusinessMetadataDefs()), null);
resolveIndexFieldNames(management, changedTypeDefs); resolveIndexFieldNames(management, changedTypeDefs);
//Commit indexes //Commit indexes
...@@ -382,19 +386,13 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -382,19 +386,13 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
resolveIndexFieldNames(managementSystem, businessMetadataType); resolveIndexFieldNames(managementSystem, businessMetadataType);
} else { } else {
LOG.debug("Ignoring the non-entity type definition {}", baseTypeDef.getName()); LOG.debug("Ignoring type definition {}", baseTypeDef.getName());
} }
} }
} }
private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, AtlasEntityType entityType) { private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, AtlasStructType structType) {
for(AtlasAttribute attribute: entityType.getAllAttributes().values()) { for(AtlasAttribute attribute: structType.getAllAttributes().values()) {
resolveIndexFieldName(managementSystem, attribute);
}
}
private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, AtlasBusinessMetadataType businessMetadataType) {
for (AtlasAttribute attribute : businessMetadataType.getAllAttributes().values()) {
resolveIndexFieldName(managementSystem, attribute); resolveIndexFieldName(managementSystem, attribute);
} }
} }
......
...@@ -25,6 +25,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph; ...@@ -25,6 +25,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient; import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient;
import org.apache.atlas.type.AtlasBusinessMetadataType; import org.apache.atlas.type.AtlasBusinessMetadataType;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute; import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.util.AtlasRepositoryConfiguration; import org.apache.atlas.util.AtlasRepositoryConfiguration;
...@@ -118,58 +119,39 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -118,58 +119,39 @@ public class SolrIndexHelper implements IndexChangeListener {
} }
private Map<String, Integer> geIndexFieldNamesWithSearchWeights() { private Map<String, Integer> geIndexFieldNamesWithSearchWeights() {
Map<String, Integer> ret = new HashMap<>(); Map<String, Integer> ret = new HashMap<>();
Collection<AtlasEntityType> entityTypes = typeRegistry.getAllEntityTypes();
Collection<AtlasBusinessMetadataType> businessMetadataTypes = typeRegistry.getAllBusinessMetadataTypes();
//the following properties are specially added manually. //the following properties are specially added manually.
//as, they don't come in the entity definitions as attributes. //as, they don't come in the entity definitions as attributes.
ret.put(typeRegistry.getIndexFieldName(CLASSIFICATION_TEXT_KEY), SEARCHWEIGHT_FOR_CLASSIFICATIONS); ret.put(typeRegistry.getIndexFieldName(CLASSIFICATION_TEXT_KEY), SEARCHWEIGHT_FOR_CLASSIFICATIONS);
ret.put(typeRegistry.getIndexFieldName(LABELS_PROPERTY_KEY), SEARCHWEIGHT_FOR_LABELS); ret.put(typeRegistry.getIndexFieldName(LABELS_PROPERTY_KEY), SEARCHWEIGHT_FOR_LABELS);
ret.put(typeRegistry.getIndexFieldName(CUSTOM_ATTRIBUTES_PROPERTY_KEY), SEARCHWEIGHT_FOR_CUSTOM_ATTRS); ret.put(typeRegistry.getIndexFieldName(CUSTOM_ATTRIBUTES_PROPERTY_KEY), SEARCHWEIGHT_FOR_CUSTOM_ATTRS);
ret.put(typeRegistry.getIndexFieldName(TYPE_NAME_PROPERTY_KEY), SEARCHWEIGHT_FOR_TYPENAME); ret.put(typeRegistry.getIndexFieldName(TYPE_NAME_PROPERTY_KEY), SEARCHWEIGHT_FOR_TYPENAME);
if (!CollectionUtils.isNotEmpty(entityTypes) && CollectionUtils.isEmpty(businessMetadataTypes)) { for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
return ret;
}
for (AtlasEntityType entityType : entityTypes) {
if (entityType.isInternalType()) { if (entityType.isInternalType()) {
continue; continue;
} }
processEntityType(ret, entityType); processType(ret, entityType);
} }
for(AtlasBusinessMetadataType businessMetadataType : businessMetadataTypes){ for (AtlasBusinessMetadataType businessMetadataType : typeRegistry.getAllBusinessMetadataTypes()) {
processBusinessMetadataType(ret, businessMetadataType); processType(ret, businessMetadataType);
} }
return ret; return ret;
} }
private void processBusinessMetadataType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasBusinessMetadataType businessMetadataType) { private void processType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasStructType structType) {
List<AtlasAttributeDef> attributes = businessMetadataType.getBusinessMetadataDef().getAttributeDefs(); List<AtlasAttributeDef> attributes = structType.getStructDef().getAttributeDefs();
if (CollectionUtils.isNotEmpty(attributes)) { if (CollectionUtils.isNotEmpty(attributes)) {
for (AtlasAttributeDef attribute : attributes) { for (AtlasAttributeDef attribute : attributes) {
processAttribute(indexFieldNameWithSearchWeights, businessMetadataType.getAttribute(attribute.getName())); processAttribute(indexFieldNameWithSearchWeights, structType.getAttribute(attribute.getName()));
} }
} else { } else {
LOG.debug("No attributes are defined for BusinessMetadata {}", businessMetadataType.getTypeName()); LOG.debug("No attributes are defined for type {}", structType.getTypeName());
}
}
private void processEntityType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasEntityType entityType) {
List<AtlasAttributeDef> attributes = entityType.getEntityDef().getAttributeDefs();
if(CollectionUtils.isNotEmpty(attributes)) {
for (AtlasAttributeDef attribute : attributes) {
processAttribute(indexFieldNameWithSearchWeights, entityType.getAttribute(attribute.getName()));
}
} else {
LOG.debug("No attributes are defined for entity {}", entityType.getTypeName());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment