Commit b064d8c3 by Le Ma Committed by Sarath Subramanian

ATLAS-3467 - Regression: Tagfilters (begins_with, ends_with, contains) and space…

ATLAS-3467 - Regression: Tagfilters (begins_with, ends_with, contains) and space fetches incorrect results ATLAS-3476 - Regression: Case insensitivity in tag filters in search Signed-off-by: 's avatarSarath Subramanian <sarath@apache.org>
parent 9ba32176
...@@ -30,8 +30,11 @@ import org.apache.atlas.repository.graphdb.AtlasVertex; ...@@ -30,8 +30,11 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
import org.apache.atlas.type.AtlasClassificationType; import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.util.AtlasGremlinQueryProvider; import org.apache.atlas.util.AtlasGremlinQueryProvider;
import org.apache.atlas.util.SearchPredicateUtil;
import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.PredicateUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.process.traversal.Order; import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -153,7 +156,7 @@ public class ClassificationSearchProcessor extends SearchProcessor { ...@@ -153,7 +156,7 @@ public class ClassificationSearchProcessor extends SearchProcessor {
StringBuilder queryString = new StringBuilder(); StringBuilder queryString = new StringBuilder();
graphIndexQueryBuilder.addActiveStateQueryFilter(queryString); graphIndexQueryBuilder.addActiveStateQueryFilter(queryString);
graphIndexQueryBuilder.addTypeAndSubTypesQueryFilter(queryString, typeAndSubTypesQryStr); graphIndexQueryBuilder.addTypeAndSubTypesQueryFilter(queryString, context.getSearchParameters().getClassification());
constructFilterQuery(queryString, classificationType, filterCriteria, indexAttributes); constructFilterQuery(queryString, classificationType, filterCriteria, indexAttributes);
...@@ -161,6 +164,15 @@ public class ClassificationSearchProcessor extends SearchProcessor { ...@@ -161,6 +164,15 @@ public class ClassificationSearchProcessor extends SearchProcessor {
indexQueryString = STRAY_OR_PATTERN.matcher(indexQueryString).replaceAll(")"); indexQueryString = STRAY_OR_PATTERN.matcher(indexQueryString).replaceAll(")");
indexQueryString = STRAY_ELIPSIS_PATTERN.matcher(indexQueryString).replaceAll(""); indexQueryString = STRAY_ELIPSIS_PATTERN.matcher(indexQueryString).replaceAll("");
Predicate typeNamePredicate = SearchPredicateUtil.getINPredicateGenerator().generatePredicate(Constants.TYPE_NAME_PROPERTY_KEY, typeAndSubTypes, String.class);
Predicate attributePredicate = constructInMemoryPredicate(classificationType, filterCriteria, indexAttributes);
if (attributePredicate != null) {
inMemoryPredicate = PredicateUtils.andPredicate(typeNamePredicate, attributePredicate);
} else {
inMemoryPredicate = typeNamePredicate;
}
this.classificationIndexQuery = graph.indexQuery(Constants.VERTEX_INDEX, indexQueryString); this.classificationIndexQuery = graph.indexQuery(Constants.VERTEX_INDEX, indexQueryString);
} else { } else {
classificationIndexQuery = null; classificationIndexQuery = null;
...@@ -263,6 +275,9 @@ public class ClassificationSearchProcessor extends SearchProcessor { ...@@ -263,6 +275,9 @@ public class ClassificationSearchProcessor extends SearchProcessor {
getVerticesFromIndexQueryResult(queryResult, classificationVertices); getVerticesFromIndexQueryResult(queryResult, classificationVertices);
// Do in-memory filtering before the graph query
CollectionUtils.filter(classificationVertices, inMemoryPredicate);
} else if (context.getSearchParameters().getTagFilters() != null) { } else if (context.getSearchParameters().getTagFilters() != null) {
Iterator<AtlasVertex> queryResult = tagGraphQueryWithAttributes.vertices(qryOffset, limit).iterator(); Iterator<AtlasVertex> queryResult = tagGraphQueryWithAttributes.vertices(qryOffset, limit).iterator();
......
...@@ -105,6 +105,8 @@ public class TestEntitiesREST { ...@@ -105,6 +105,8 @@ public class TestEntitiesREST {
tableEntity.setAttribute("columns", getObjIdList(columns)); tableEntity.setAttribute("columns", getObjIdList(columns));
tableEntity2.setAttribute("columns", getObjIdList(columns2)); tableEntity2.setAttribute("columns", getObjIdList(columns2));
createEntities();
} }
@AfterMethod @AfterMethod
...@@ -112,8 +114,7 @@ public class TestEntitiesREST { ...@@ -112,8 +114,7 @@ public class TestEntitiesREST {
RequestContext.clear(); RequestContext.clear();
} }
@Test private void createEntities() throws Exception {
public void testCreateOrUpdateEntities() throws Exception {
AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo(); AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo();
entities.addEntity(dbEntity); entities.addEntity(dbEntity);
...@@ -142,7 +143,7 @@ public class TestEntitiesREST { ...@@ -142,7 +143,7 @@ public class TestEntitiesREST {
} }
} }
@Test(dependsOnMethods = "testCreateOrUpdateEntities") @Test
public void testTagToMultipleEntities() throws Exception{ public void testTagToMultipleEntities() throws Exception{
AtlasClassification tag = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }}); AtlasClassification tag = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }});
...@@ -153,7 +154,7 @@ public class TestEntitiesREST { ...@@ -153,7 +154,7 @@ public class TestEntitiesREST {
for (int i = 0; i < createdGuids.get(TABLE_TYPE).size() - 1; i++) { for (int i = 0; i < createdGuids.get(TABLE_TYPE).size() - 1; i++) {
final AtlasClassification result_tag = entityREST.getClassification(createdGuids.get(TABLE_TYPE).get(i), TestUtilsV2.CLASSIFICATION); final AtlasClassification result_tag = entityREST.getClassification(createdGuids.get(TABLE_TYPE).get(i), TestUtilsV2.CLASSIFICATION);
Assert.assertNotNull(result_tag); Assert.assertNotNull(result_tag);
Assert.assertEquals(result_tag, tag); Assert.assertEquals(result_tag.getTypeName(), tag.getTypeName());
} }
} }
...@@ -280,6 +281,10 @@ public class TestEntitiesREST { ...@@ -280,6 +281,10 @@ public class TestEntitiesREST {
Assert.assertNotNull(res.getEntities()); Assert.assertNotNull(res.getEntities());
Assert.assertEquals(res.getEntities().size(), 2); Assert.assertEquals(res.getEntities().size(), 2);
filterCriteria.setAttributeValue("STRING");
res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNull(res.getEntities());
} }
@Test(dependsOnMethods = "testWildCardBasicSearch") @Test(dependsOnMethods = "testWildCardBasicSearch")
...@@ -305,6 +310,29 @@ public class TestEntitiesREST { ...@@ -305,6 +310,29 @@ public class TestEntitiesREST {
Assert.assertEquals(res.getEntities().size(), 3); Assert.assertEquals(res.getEntities().size(), 3);
} }
@Test(dependsOnMethods = "testTagToMultipleEntities")
public void testBasicSearchWithFilter() throws Exception {
searchParameters = new SearchParameters();
searchParameters.setIncludeSubClassifications(true);
searchParameters.setClassification(TestUtilsV2.CLASSIFICATION);
SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria();
fc.setOperator(SearchParameters.Operator.CONTAINS);
fc.setAttributeValue("new comments");
fc.setAttributeName("tag");
searchParameters.setTagFilters(fc);
AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNull(res.getEntities());
fc.setOperator(SearchParameters.Operator.ENDS_WITH);
res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNull(res.getEntities());
fc.setOperator(SearchParameters.Operator.STARTS_WITH);
res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNull(res.getEntities());
}
@Test(dependsOnMethods = "testBasicSearchWithSubTypes") @Test(dependsOnMethods = "testBasicSearchWithSubTypes")
public void testUpdateWithSerializedEntities() throws Exception { public void testUpdateWithSerializedEntities() throws Exception {
...@@ -334,7 +362,7 @@ public class TestEntitiesREST { ...@@ -334,7 +362,7 @@ public class TestEntitiesREST {
Assert.assertEquals(newGuids.size(), 3); Assert.assertEquals(newGuids.size(), 3);
} }
@Test(dependsOnMethods = "testCreateOrUpdateEntities") @Test
public void testGetEntities() throws Exception { public void testGetEntities() throws Exception {
final AtlasEntitiesWithExtInfo response = entityREST.getByGuids(createdGuids.get(DATABASE_TYPE), false, false); final AtlasEntitiesWithExtInfo response = entityREST.getByGuids(createdGuids.get(DATABASE_TYPE), false, false);
......
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