Commit 24830e6b by Chengbing Liu Committed by apoorvnaik

ATLAS-2816: Allow ignoring relationship in

EntityGraphRetriever for FullTextMapperV2 Signed-off-by: 's avatarapoorvnaik <apoorvnaik@apache.org>
parent 52ef9e7f
......@@ -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));
......
......@@ -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);
}
......
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