Repository: atlas Updated Branches: refs/heads/branch-0.8 3b5f0cad2 -> a21f865c5
ATLAS-2296: basic search enhancement to optionally exclude sub-type entities and sub-classifications (cherry picked from commit 1c58f3aae4bef0406c2415a8fc148b3558e02cae) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/a21f865c Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/a21f865c Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/a21f865c Branch: refs/heads/branch-0.8 Commit: a21f865c56a71d4b3bf55830c6081d2b74bd0c75 Parents: 3b5f0ca Author: Madhan Neethiraj <mad...@apache.org> Authored: Mon Dec 4 20:45:38 2017 -0800 Committer: Madhan Neethiraj <mad...@apache.org> Committed: Tue Dec 5 15:17:30 2017 -0800 ---------------------------------------------------------------------- .../atlas/model/discovery/SearchParameters.java | 32 +++++++++++++++ .../atlas/type/AtlasClassificationType.java | 5 +++ .../org/apache/atlas/type/AtlasEntityType.java | 9 ++++- .../ClassificationSearchProcessor.java | 24 +++++++---- .../atlas/discovery/EntitySearchProcessor.java | 42 +++++++++++++++----- 5 files changed, 91 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/a21f865c/intg/src/main/java/org/apache/atlas/model/discovery/SearchParameters.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/discovery/SearchParameters.java b/intg/src/main/java/org/apache/atlas/model/discovery/SearchParameters.java index ede841e..328c46b 100644 --- a/intg/src/main/java/org/apache/atlas/model/discovery/SearchParameters.java +++ b/intg/src/main/java/org/apache/atlas/model/discovery/SearchParameters.java @@ -45,6 +45,8 @@ public class SearchParameters implements Serializable { private String classification; private boolean excludeDeletedEntities; private boolean includeClassificationAttributes; + private boolean includeSubTypes = true; + private boolean includeSubClassifications = true; private int limit; private int offset; @@ -129,6 +131,36 @@ public class SearchParameters implements Serializable { } /** + * @return True iff sub-type entities are to be included + */ + public boolean getIncludeSubTypes() { + return includeSubTypes; + } + + /** + * Include sub-type entities in search + * @param includeSubTypes boolean flag + */ + public void setIncludeSubTypes(boolean includeSubTypes) { + this.includeSubTypes = includeSubTypes; + } + + /** + * @return True iff sub-classifications are to be included + */ + public boolean getIncludeSubClassifications() { + return includeSubClassifications; + } + + /** + * Include sub-classifications in search + * @param includeSubClassifications boolean flag + */ + public void setIncludeSubClassifications(boolean includeSubClassifications) { + this.includeSubClassifications = includeSubClassifications; + } + + /** * @return Max number of results to be returned */ public int getLimit() { http://git-wip-us.apache.org/repos/asf/atlas/blob/a21f865c/intg/src/main/java/org/apache/atlas/type/AtlasClassificationType.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasClassificationType.java b/intg/src/main/java/org/apache/atlas/type/AtlasClassificationType.java index 5392294..707d7b2 100644 --- a/intg/src/main/java/org/apache/atlas/type/AtlasClassificationType.java +++ b/intg/src/main/java/org/apache/atlas/type/AtlasClassificationType.java @@ -44,6 +44,7 @@ public class AtlasClassificationType extends AtlasStructType { private static final Logger LOG = LoggerFactory.getLogger(AtlasClassificationType.class); private final AtlasClassificationDef classificationDef; + private final String typeQryStr; private List<AtlasClassificationType> superTypes = Collections.emptyList(); private Set<String> allSuperTypes = Collections.emptySet(); @@ -56,6 +57,7 @@ public class AtlasClassificationType extends AtlasStructType { super(classificationDef); this.classificationDef = classificationDef; + this.typeQryStr = AtlasAttribute.escapeIndexQueryValue(Collections.singleton(getTypeName())); } public AtlasClassificationType(AtlasClassificationDef classificationDef, AtlasTypeRegistry typeRegistry) @@ -63,6 +65,7 @@ public class AtlasClassificationType extends AtlasStructType { super(classificationDef); this.classificationDef = classificationDef; + this.typeQryStr = AtlasAttribute.escapeIndexQueryValue(Collections.singleton(getTypeName())); resolveReferences(typeRegistry); } @@ -146,6 +149,8 @@ public class AtlasClassificationType extends AtlasStructType { public Set<String> getTypeAndAllSubTypes() { return typeAndAllSubTypes; } + public String getTypeQryStr() { return typeQryStr; } + public String getTypeAndAllSubTypesQryStr() { if (StringUtils.isEmpty(typeAndAllSubTypesQryStr)) { typeAndAllSubTypesQryStr = AtlasAttribute.escapeIndexQueryValue(typeAndAllSubTypes); http://git-wip-us.apache.org/repos/asf/atlas/blob/a21f865c/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java b/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java index 2f17381..8b3d78a 100644 --- a/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java +++ b/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java @@ -46,6 +46,7 @@ public class AtlasEntityType extends AtlasStructType { private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityType.class); private final AtlasEntityDef entityDef; + private final String typeQryStr; private List<AtlasEntityType> superTypes = Collections.emptyList(); private Set<String> allSuperTypes = Collections.emptySet(); @@ -57,13 +58,15 @@ public class AtlasEntityType extends AtlasStructType { public AtlasEntityType(AtlasEntityDef entityDef) { super(entityDef); - this.entityDef = entityDef; + this.entityDef = entityDef; + this.typeQryStr = AtlasAttribute.escapeIndexQueryValue(Collections.singleton(getTypeName())); } public AtlasEntityType(AtlasEntityDef entityDef, AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super(entityDef); - this.entityDef = entityDef; + this.entityDef = entityDef; + this.typeQryStr = AtlasAttribute.escapeIndexQueryValue(Collections.singleton(getTypeName())); resolveReferences(typeRegistry); } @@ -163,6 +166,8 @@ public class AtlasEntityType extends AtlasStructType { return typeAndAllSubTypesQryStr; } + public String getTypeQryStr() { return typeQryStr; } + @Override public AtlasEntity createDefaultValue() { AtlasEntity ret = new AtlasEntity(entityDef.getName()); http://git-wip-us.apache.org/repos/asf/atlas/blob/a21f865c/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java b/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java index 1565977..7b75321 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java +++ b/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java @@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory; import javax.script.ScriptEngine; import javax.script.ScriptException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -67,14 +68,21 @@ public class ClassificationSearchProcessor extends SearchProcessor { public ClassificationSearchProcessor(SearchContext context) { super(context); - final AtlasClassificationType classificationType = context.getClassificationType(); - final FilterCriteria filterCriteria = context.getSearchParameters().getTagFilters(); - final Set<String> typeAndSubTypes = classificationType.getTypeAndAllSubTypes(); - final String typeAndSubTypesQryStr = classificationType.getTypeAndAllSubTypesQryStr(); - final Set<String> indexAttributes = new HashSet<>(); - final Set<String> graphAttributes = new HashSet<>(); - final Set<String> allAttributes = new HashSet<>(); - + final AtlasClassificationType classificationType = context.getClassificationType(); + final FilterCriteria filterCriteria = context.getSearchParameters().getTagFilters(); + final Set<String> indexAttributes = new HashSet<>(); + final Set<String> graphAttributes = new HashSet<>(); + final Set<String> allAttributes = new HashSet<>(); + final Set<String> typeAndSubTypes; + final String typeAndSubTypesQryStr; + + if (context.getSearchParameters().getIncludeSubClassifications()) { + typeAndSubTypes = classificationType.getTypeAndAllSubTypes(); + typeAndSubTypesQryStr = classificationType.getTypeAndAllSubTypesQryStr(); + } else { + typeAndSubTypes = Collections.singleton(classificationType.getTypeName()); + typeAndSubTypesQryStr = classificationType.getTypeQryStr(); + } processSearchAttributes(classificationType, filterCriteria, indexAttributes, graphAttributes, allAttributes); http://git-wip-us.apache.org/repos/asf/atlas/blob/a21f865c/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java b/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java index 1119463..0a811f4 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java @@ -53,18 +53,38 @@ public class EntitySearchProcessor extends SearchProcessor { public EntitySearchProcessor(SearchContext context) { super(context); - final AtlasEntityType entityType = context.getEntityType(); - final FilterCriteria filterCriteria = context.getSearchParameters().getEntityFilters(); - final Set<String> typeAndSubTypes = entityType.getTypeAndAllSubTypes(); - final String typeAndSubTypesQryStr = entityType.getTypeAndAllSubTypesQryStr(); - final Set<String> indexAttributes = new HashSet<>(); - final Set<String> graphAttributes = new HashSet<>(); - final Set<String> allAttributes = new HashSet<>(); - - final AtlasClassificationType classificationType = context.getClassificationType(); - final boolean filterClassification = classificationType != null && !context.needClassificationProcessor(); - final Set<String> classificationTypeAndSubTypes = classificationType != null ? classificationType.getTypeAndAllSubTypes() : Collections.EMPTY_SET; + final AtlasEntityType entityType = context.getEntityType(); + final FilterCriteria filterCriteria = context.getSearchParameters().getEntityFilters(); + final Set<String> indexAttributes = new HashSet<>(); + final Set<String> graphAttributes = new HashSet<>(); + final Set<String> allAttributes = new HashSet<>(); + final Set<String> typeAndSubTypes; + final String typeAndSubTypesQryStr; + + if (context.getSearchParameters().getIncludeSubTypes()) { + typeAndSubTypes = entityType.getTypeAndAllSubTypes(); + typeAndSubTypesQryStr = entityType.getTypeAndAllSubTypesQryStr(); + } else { + typeAndSubTypes = Collections.singleton(entityType.getTypeName()); + typeAndSubTypesQryStr = entityType.getTypeQryStr(); + } + + final AtlasClassificationType classificationType = context.getClassificationType(); + final boolean filterClassification; + final Set<String> classificationTypeAndSubTypes; + + if (classificationType != null) { + filterClassification = !context.needClassificationProcessor(); + if (context.getSearchParameters().getIncludeSubClassifications()) { + classificationTypeAndSubTypes = classificationType.getTypeAndAllSubTypes(); + } else { + classificationTypeAndSubTypes = Collections.singleton(classificationType.getTypeName()); + } + } else { + filterClassification = false; + classificationTypeAndSubTypes = Collections.emptySet(); + } final Predicate typeNamePredicate = SearchPredicateUtil.getINPredicateGenerator() .generatePredicate(Constants.TYPE_NAME_PROPERTY_KEY, typeAndSubTypes, String.class);