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

sarath pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 6c6323d  ATLAS-3709 Issues with quick search/suggestions in 
conjunction with Business Metadata attributes
6c6323d is described below

commit 6c6323d400d73631279a8aad73829e35797fd7c0
Author: Mandar Ambawane <[email protected]>
AuthorDate: Fri Apr 10 14:37:18 2020 +0530

    ATLAS-3709 Issues with quick search/suggestions in conjunction with 
Business Metadata attributes
    
    Signed-off-by: Sarath Subramanian <[email protected]>
    (cherry picked from commit 1e8fa7e59b332e3543d797618879510f70ff8fe4)
---
 .../org/apache/atlas/listener/ChangedTypeDefs.java |  2 +-
 .../org/apache/atlas/type/AtlasTypeRegistry.java   | 47 ++++++++++++++--------
 .../repository/graph/GraphBackedSearchIndexer.java | 22 +++++-----
 .../atlas/repository/graph/SolrIndexHelper.java    | 38 +++++------------
 4 files changed, 52 insertions(+), 57 deletions(-)

diff --git a/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java 
b/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java
index 58e889a..c686e3e 100644
--- a/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java
+++ b/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java
@@ -92,7 +92,7 @@ public class ChangedTypeDefs {
     }
 
     public boolean hasBusinessMetadataDef() {
-        return hasBusinessMetadataDef(createdTypeDefs) || 
hasEntityDef(updatedTypeDefs) || hasEntityDef(deletedTypeDefs);
+        return hasBusinessMetadataDef(createdTypeDefs) || 
hasBusinessMetadataDef(updatedTypeDefs) || 
hasBusinessMetadataDef(deletedTypeDefs);
     }
 
     private boolean hasBusinessMetadataDef(List<? extends AtlasBaseTypeDef> 
typeDefs) {
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java 
b/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
index 9df89a2..2c7cb2b 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
@@ -980,22 +980,9 @@ public class AtlasTypeRegistry {
                                 new Exception().fillInStackTrace());
                     } else if (typeRegistryUpdateLock.getHoldCount() == 1) {
                         if (ttr != null && commitUpdates) {
-                            // copy indexName for entity attributes from 
current typeRegistry to new one
-                            for (AtlasEntityType ttrEntityType : 
ttr.getAllEntityTypes()) {
-                                AtlasEntityType currEntityType = 
typeRegistry.getEntityTypeByName(ttrEntityType.getTypeName());
-
-                                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());
-                                            }
-                                        }
-                                    }
-                                }
-                            }
+                            // copy indexName for attributes from current 
typeRegistry to new one
+                            copyIndexNameFromCurrent(ttr.getAllEntityTypes());
+                            
copyIndexNameFromCurrent(ttr.getAllBusinessMetadataTypes());
 
                             typeRegistry.registryData = ttr.registryData;
                         }
@@ -1018,6 +1005,34 @@ public class AtlasTypeRegistry {
             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());
+                        }
+                    }
+                }
+            }
+
+        }
     }
 }
 
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
index f1dfc69..8289069 100755
--- 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
@@ -209,14 +209,18 @@ public class GraphBackedSearchIndexer implements 
SearchIndexer, ActiveStateChang
             LOG.debug("Type definition load completed. Informing the 
completion to IndexChangeListeners.");
         }
 
-        Collection<AtlasEntityDef> entityDefs      = 
typeRegistry.getAllEntityDefs();
-        ChangedTypeDefs            changedTypeDefs = new ChangedTypeDefs(null, 
new ArrayList<>(entityDefs), null);
-        AtlasGraphManagement       management      = null;
+        ChangedTypeDefs      changedTypeDefs = null;
+        AtlasGraphManagement management      = null;
 
         try {
             management = provider.get().getManagementSystem();
 
             //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);
 
             //Commit indexes
@@ -382,19 +386,13 @@ public class GraphBackedSearchIndexer implements 
SearchIndexer, ActiveStateChang
 
                 resolveIndexFieldNames(managementSystem, businessMetadataType);
             } 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) {
-        for(AtlasAttribute attribute: entityType.getAllAttributes().values()) {
-            resolveIndexFieldName(managementSystem, attribute);
-        }
-    }
-
-    private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, 
AtlasBusinessMetadataType businessMetadataType) {
-        for (AtlasAttribute attribute : 
businessMetadataType.getAllAttributes().values()) {
+    private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, 
AtlasStructType structType) {
+        for(AtlasAttribute attribute: structType.getAllAttributes().values()) {
             resolveIndexFieldName(managementSystem, attribute);
         }
     }
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
 
b/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
index 814b9f5..0670d50 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
@@ -25,6 +25,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
 import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient;
 import org.apache.atlas.type.AtlasBusinessMetadataType;
 import org.apache.atlas.type.AtlasEntityType;
+import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.atlas.util.AtlasRepositoryConfiguration;
@@ -118,58 +119,39 @@ public class SolrIndexHelper implements 
IndexChangeListener {
     }
 
     private Map<String, Integer> geIndexFieldNamesWithSearchWeights() {
-        Map<String, Integer>        ret         = new HashMap<>();
-        Collection<AtlasEntityType> entityTypes = 
typeRegistry.getAllEntityTypes();
-        Collection<AtlasBusinessMetadataType> businessMetadataTypes = 
typeRegistry.getAllBusinessMetadataTypes();
+        Map<String, Integer> ret = new HashMap<>();
 
         //the following properties are specially added manually.
         //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(LABELS_PROPERTY_KEY), 
SEARCHWEIGHT_FOR_LABELS);
         
ret.put(typeRegistry.getIndexFieldName(CUSTOM_ATTRIBUTES_PROPERTY_KEY), 
SEARCHWEIGHT_FOR_CUSTOM_ATTRS);
         ret.put(typeRegistry.getIndexFieldName(TYPE_NAME_PROPERTY_KEY), 
SEARCHWEIGHT_FOR_TYPENAME);
 
-        if (!CollectionUtils.isNotEmpty(entityTypes) && 
CollectionUtils.isEmpty(businessMetadataTypes)) {
-            return ret;
-        }
-
-        for (AtlasEntityType entityType : entityTypes) {
+        for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
             if (entityType.isInternalType()) {
                 continue;
             }
 
-            processEntityType(ret, entityType);
+            processType(ret, entityType);
         }
 
-        for(AtlasBusinessMetadataType businessMetadataType : 
businessMetadataTypes){
-            processBusinessMetadataType(ret, businessMetadataType);
+        for (AtlasBusinessMetadataType businessMetadataType : 
typeRegistry.getAllBusinessMetadataTypes()) {
+            processType(ret, businessMetadataType);
         }
 
         return ret;
     }
 
-    private void processBusinessMetadataType(Map<String, Integer> 
indexFieldNameWithSearchWeights, AtlasBusinessMetadataType 
businessMetadataType) {
-        List<AtlasAttributeDef> attributes = 
businessMetadataType.getBusinessMetadataDef().getAttributeDefs();
+    private void processType(Map<String, Integer> 
indexFieldNameWithSearchWeights, AtlasStructType structType) {
+        List<AtlasAttributeDef> attributes = 
structType.getStructDef().getAttributeDefs();
 
         if (CollectionUtils.isNotEmpty(attributes)) {
             for (AtlasAttributeDef attribute : attributes) {
-                processAttribute(indexFieldNameWithSearchWeights, 
businessMetadataType.getAttribute(attribute.getName()));
+                processAttribute(indexFieldNameWithSearchWeights, 
structType.getAttribute(attribute.getName()));
             }
         } else {
-            LOG.debug("No attributes are defined for BusinessMetadata {}", 
businessMetadataType.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());
+            LOG.debug("No attributes are defined for type {}", 
structType.getTypeName());
         }
     }
 

Reply via email to