Repository: atlas
Updated Branches:
  refs/heads/master 52ef9e7f3 -> 24830e6bc


ATLAS-2816: Allow ignoring relationship in
 EntityGraphRetriever for FullTextMapperV2

Signed-off-by: apoorvnaik <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/24830e6b
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/24830e6b
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/24830e6b

Branch: refs/heads/master
Commit: 24830e6bc8624ae6d4abbe4f9037f0de8ad57cd0
Parents: 52ef9e7
Author: Chengbing Liu <[email protected]>
Authored: Wed Aug 15 20:20:18 2018 -0700
Committer: apoorvnaik <[email protected]>
Committed: Wed Aug 15 20:20:27 2018 -0700

----------------------------------------------------------------------
 .../repository/graph/FullTextMapperV2.java      | 32 +++++++++++---------
 .../store/graph/v2/EntityGraphRetriever.java    | 11 ++++++-
 2 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/24830e6b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
 
b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
index bc5ae5c..b85dc9b 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -53,16 +53,17 @@ public class FullTextMapperV2 {
     private static final String FULL_TEXT_EXCLUDE_ATTRIBUTE_PROPERTY = 
"atlas.search.fulltext.type";
 
     private final EntityGraphRetriever     entityGraphRetriever;
+    private final Configuration            configuration;
     private final boolean                  followReferences;
     private final Map<String, Set<String>> excludeAttributesCache = new 
HashMap<>();
 
-    private Configuration APPLICATION_PROPERTIES = null;
 
     @Inject
     public FullTextMapperV2(AtlasTypeRegistry typeRegistry, Configuration 
configuration) {
-        entityGraphRetriever   = new EntityGraphRetriever(typeRegistry);
-        APPLICATION_PROPERTIES = configuration;
-        followReferences       = APPLICATION_PROPERTIES != null && 
APPLICATION_PROPERTIES.getBoolean(FULL_TEXT_FOLLOW_REFERENCES, false);
+        this.configuration = configuration;
+        followReferences = this.configuration != null && 
this.configuration.getBoolean(FULL_TEXT_FOLLOW_REFERENCES, false);
+        // If followReferences = false then ignore relationship attr loading
+        entityGraphRetriever = new EntityGraphRetriever(typeRegistry, 
!followReferences);
     }
 
     /**
@@ -73,8 +74,8 @@ public class FullTextMapperV2 {
      * @throws AtlasBaseException
      */
     public String getIndexTextForClassifications(String guid, 
List<AtlasClassification> classifications) throws AtlasBaseException {
-        String                 ret     = null;
-        AtlasEntityWithExtInfo entityWithExtInfo  = getAndCacheEntity(guid);
+        String                 ret               = null;
+        AtlasEntityWithExtInfo entityWithExtInfo = getAndCacheEntity(guid);
 
         if (entityWithExtInfo != null) {
             StringBuilder sb = new StringBuilder();
@@ -100,8 +101,8 @@ public class FullTextMapperV2 {
     }
 
     public String getIndexTextForEntity(String guid) throws AtlasBaseException 
{
-        String                 ret     = null;
-        AtlasEntityWithExtInfo entity  = getAndCacheEntity(guid);
+        String                 ret    = null;
+        AtlasEntityWithExtInfo entity = getAndCacheEntity(guid);
 
         if (entity != null) {
             StringBuilder sb = new StringBuilder();
@@ -207,7 +208,8 @@ public class FullTextMapperV2 {
         AtlasEntityWithExtInfo entityWithExtInfo = context.getInstanceV2(guid);
 
         if (entityWithExtInfo == null) {
-            entityWithExtInfo = 
entityGraphRetriever.toAtlasEntityWithExtInfo(guid);
+            // Only map ownedRef and relationship attr when follow references 
is set to true
+            entityWithExtInfo = 
entityGraphRetriever.toAtlasEntityWithExtInfo(guid, !followReferences);
 
             if (entityWithExtInfo != null) {
                 context.cache(entityWithExtInfo);
@@ -230,9 +232,9 @@ public class FullTextMapperV2 {
         if (excludeAttributesCache.containsKey(typeName)) {
             ret = excludeAttributesCache.get(typeName);
 
-        } else if (APPLICATION_PROPERTIES != null) {
-            String[] excludeAttributes = 
APPLICATION_PROPERTIES.getStringArray(FULL_TEXT_EXCLUDE_ATTRIBUTE_PROPERTY + 
"." +
-                                                                               
typeName + "." + "attributes.exclude");
+        } else if (configuration != null) {
+            String[] excludeAttributes = 
configuration.getStringArray(FULL_TEXT_EXCLUDE_ATTRIBUTE_PROPERTY + "." +
+                                                                              
typeName + "." + "attributes.exclude");
 
             if (ArrayUtils.isNotEmpty(excludeAttributes)) {
                 ret = new HashSet<>(Arrays.asList(excludeAttributes));

http://git-wip-us.apache.org/repos/asf/atlas/blob/24830e6b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
index 34109b3..52c3745 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java
@@ -138,8 +138,15 @@ public final class EntityGraphRetriever {
 
     private final AtlasTypeRegistry typeRegistry;
 
+    private final boolean ignoreRelationshipAttr;
+
     public EntityGraphRetriever(AtlasTypeRegistry typeRegistry) {
+        this(typeRegistry, false);
+    }
+
+    public EntityGraphRetriever(AtlasTypeRegistry typeRegistry, boolean 
ignoreRelationshipAttr) {
         this.typeRegistry = typeRegistry;
+        this.ignoreRelationshipAttr = ignoreRelationshipAttr;
     }
 
     public AtlasEntity toAtlasEntity(String guid) throws AtlasBaseException {
@@ -385,7 +392,9 @@ public final class EntityGraphRetriever {
 
             mapAttributes(entityVertex, entity, entityExtInfo, isMinExtInfo);
 
-            mapRelationshipAttributes(entityVertex, entity);
+            if (!ignoreRelationshipAttr) { // only map when really needed
+                mapRelationshipAttributes(entityVertex, entity);
+            }
 
             mapClassifications(entityVertex, entity);
         }

Reply via email to