Commit c04c0ab3 by Le Ma Committed by Madhan Neethiraj

ATLAS-3491: search on parent tag doesn't return entities associated with children tags

parent 6ad08536
......@@ -156,7 +156,7 @@ public class ClassificationSearchProcessor extends SearchProcessor {
StringBuilder queryString = new StringBuilder();
graphIndexQueryBuilder.addActiveStateQueryFilter(queryString);
graphIndexQueryBuilder.addTypeAndSubTypesQueryFilter(queryString, context.getSearchParameters().getClassification());
graphIndexQueryBuilder.addTypeAndSubTypesQueryFilter(queryString, typeAndSubTypesQryStr);
constructFilterQuery(queryString, classificationType, filterCriteria, indexAttributes);
......
......@@ -242,30 +242,31 @@ public abstract class SearchProcessor {
protected void filterWhiteSpaceClassification(List<AtlasVertex> entityVertices) {
if (CollectionUtils.isNotEmpty(entityVertices)) {
boolean hasExactMatch = false;
Iterator<AtlasVertex> it = entityVertices.iterator();
final Iterator<AtlasVertex> it = entityVertices.iterator();
final Set<String> typeAndSubTypes = context.getClassificationTypes();
while (it.hasNext()) {
AtlasVertex entityVertex = it.next();
List<String> classificationNames = AtlasGraphUtilsV2.getClassificationNames(entityVertex);
if (CollectionUtils.isNotEmpty(classificationNames) && classificationNames.contains(context.getClassificationType().getTypeName())) {
hasExactMatch = true;
if (CollectionUtils.isNotEmpty(classificationNames)) {
if (CollectionUtils.containsAny(classificationNames, typeAndSubTypes)) {
continue;
}
}
if (hasExactMatch) continue;
List<String> propagatedClassificationNames = AtlasGraphUtilsV2.getPropagatedClassificationNames(entityVertex);
classificationNames = AtlasGraphUtilsV2.getPropagatedClassificationNames(entityVertex);
if (CollectionUtils.isNotEmpty(classificationNames) && classificationNames.contains(context.getClassificationType().getTypeName())) {
hasExactMatch = true;
if (CollectionUtils.isNotEmpty(propagatedClassificationNames)) {
if (CollectionUtils.containsAny(propagatedClassificationNames, typeAndSubTypes)) {
continue;
}
}
if (!hasExactMatch) {
it.remove();
}
}
}
}
protected void constructFilterQuery(StringBuilder indexQuery, AtlasStructType type, FilterCriteria filterCriteria, Set<String> indexAttributes) {
if (filterCriteria != null) {
......
......@@ -19,6 +19,7 @@ package org.apache.atlas.web.adapters;
import static org.apache.atlas.TestUtilsV2.COLUMN_TYPE;
import static org.apache.atlas.TestUtilsV2.DATABASE_TYPE;
import static org.apache.atlas.TestUtilsV2.FETL_CLASSIFICATION;
import static org.apache.atlas.TestUtilsV2.PHI;
import static org.apache.atlas.TestUtilsV2.TABLE_TYPE;
......@@ -334,18 +335,27 @@ public class TestEntitiesREST {
ClassificationAssociateRequest clsAssRequest = new ClassificationAssociateRequest(createdGuids.get(DATABASE_TYPE), fetlCls);
entityREST.addClassification(clsAssRequest);
final AtlasClassification result_tag = entityREST.getClassification(createdGuids.get(DATABASE_TYPE).get(0), TestUtilsV2.PHI);
final AtlasClassification result_tag = entityREST.getClassification(createdGuids.get(DATABASE_TYPE).get(0), TestUtilsV2.FETL_CLASSIFICATION);
Assert.assertNotNull(result_tag);
Assert.assertEquals(result_tag.getTypeName(), FETL_CLASSIFICATION);
// basic search with subtypes
searchParameters = new SearchParameters();
searchParameters.setClassification(TestUtilsV2.CLASSIFICATION);
searchParameters.setIncludeSubTypes(true);
searchParameters.setIncludeSubClassifications(true);
AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNotNull(res.getEntities());
Assert.assertEquals(res.getEntities().size(), 3);
// basic search without subtypes
searchParameters.setIncludeSubClassifications(false);
res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNotNull(res.getEntities());
Assert.assertEquals(res.getEntities().size(), 2);
}
@Test(dependsOnMethods = "testTagToMultipleEntities")
......
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