Commit c88ea511 by Le Ma Committed by Sarath Subramanian

ATLAS-3425 gremlin Script Execution Failed Due To Unsupported Functions

parent 85a5eeba
......@@ -188,15 +188,15 @@ public class ClassificationSearchProcessor extends SearchProcessor {
gremlinQueryBindings = new HashMap<>();
StringBuilder gremlinQuery = new StringBuilder();
gremlinQuery.append("g.V().has('__guid', T.in, guids)");
gremlinQuery.append("g.V().has('__guid', within(guids))");
gremlinQuery.append(queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.BASIC_SEARCH_CLASSIFICATION_FILTER));
gremlinQuery.append(".as('e').out()");
gremlinQuery.append(".as('e').filter(out()");
gremlinQuery.append(queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.BASIC_SEARCH_TYPE_FILTER));
constructGremlinFilterQuery(gremlinQuery, gremlinQueryBindings, context.getClassificationType(), context.getSearchParameters().getTagFilters());
// After filtering on tags go back to e and output the list of entity vertices
gremlinQuery.append(".back('e').toList()");
gremlinQuery.append(").toList()");
gremlinQueryBindings.put("traitNames", typeAndSubTypes);
gremlinQueryBindings.put("typeNames", typeAndSubTypes); // classification typeName
......
......@@ -57,9 +57,9 @@ public class AtlasGremlin2QueryProvider extends AtlasGremlinQueryProvider {
"path().toList()";
case BASIC_SEARCH_TYPE_FILTER:
return ".has('__typeName', T.in, typeNames)";
return ".has('__typeName', within(typeNames))";
case BASIC_SEARCH_CLASSIFICATION_FILTER:
return ".or(has('__traitNames', T.in, traitNames), has('__propagatedTraitNames', T.in, traitNames))";
return ".or(has('__traitNames', within(traitNames)), has('__propagatedTraitNames', within(traitNames)))";
case BASIC_SEARCH_STATE_FILTER:
return ".has('__state', state)";
case TO_RANGE_LIST:
......@@ -67,17 +67,17 @@ public class AtlasGremlin2QueryProvider extends AtlasGremlinQueryProvider {
case GUID_PREFIX_FILTER:
return ".filter{it.'__guid'.matches(guid)}";
case COMPARE_LT:
return ".has('%s', T.lt, %s)";
return ".has('%s', lt(%s))";
case COMPARE_LTE:
return ".has('%s', T.lte, %s)";
return ".has('%s', lte(%s))";
case COMPARE_GT:
return ".has('%s', T.gt, %s)";
return ".has('%s', gt(%s))";
case COMPARE_GTE:
return ".has('%s', T.gte, %s)";
return ".has('%s', gte(%s))";
case COMPARE_EQ:
return ".has('%s', T.eq, %s)";
return ".has('%s', eq(%s))";
case COMPARE_NEQ:
return ".has('%s', T.neq, %s)";
return ".has('%s', neq(%s))";
case COMPARE_MATCHES:
return ".filter({it.getProperty('%s').matches(%s)})";
case COMPARE_STARTS_WITH:
......@@ -91,7 +91,7 @@ public class AtlasGremlin2QueryProvider extends AtlasGremlinQueryProvider {
case COMPARE_NOT_NULL:
return ".has('%s')";
case RELATIONSHIP_SEARCH:
return "g.V('__guid', guid).both(relation).has('__state', T.in, states)";
return "g.V('__guid', guid).both(relation).has('__state', within(states))";
case RELATIONSHIP_SEARCH_ASCENDING_SORT:
return ".order{it.a.getProperty(sortAttributeName) <=> it.b.getProperty(sortAttributeName)}";
case RELATIONSHIP_SEARCH_DESCENDING_SORT:
......
......@@ -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.PHI;
import static org.apache.atlas.TestUtilsV2.TABLE_TYPE;
import org.apache.atlas.AtlasClient;
......@@ -56,6 +57,7 @@ import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -230,6 +232,42 @@ public class TestEntitiesREST {
Assert.assertEquals(res.getEntities().size(), 1);
}
@Test(dependsOnMethods = "testBasicSearchAddCls")
public void testGraphQueryFilter() throws Exception {
searchParameters = new SearchParameters();
searchParameters.setQuery("sample_string");
searchParameters.setClassification(PHI);
SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria();
fc.setOperator(SearchParameters.Operator.EQ);
fc.setAttributeName("booleanAttr");
fc.setAttributeValue("true");
searchParameters.setTagFilters(fc);
AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNotNull(res.getEntities());
Assert.assertEquals(res.getEntities().size(), 1);
Assert.assertEquals(res.getEntities().get(0).getTypeName(), DATABASE_TYPE);
AtlasClassification cls = new AtlasClassification(TestUtilsV2.PHI, new HashMap<String, Object>() {{
put("stringAttr", "sample_string");
put("booleanAttr", false);
put("integerAttr", 100);
}});
ClassificationAssociateRequest clsAssRequest = new ClassificationAssociateRequest(Collections.singletonList(createdGuids.get(TABLE_TYPE).get(0)), cls);
entityREST.addClassification(clsAssRequest);
final AtlasClassification result_tag = entityREST.getClassification(createdGuids.get(TABLE_TYPE).get(0), TestUtilsV2.PHI);
Assert.assertNotNull(result_tag);
res = discoveryREST.searchWithParameters(searchParameters);
Assert.assertNotNull(res.getEntities());
Assert.assertEquals(res.getEntities().size(), 1);
Assert.assertEquals(res.getEntities().get(0).getTypeName(), DATABASE_TYPE);
}
private void addPHICls() throws Exception {
AtlasClassification clsPHI = new AtlasClassification(TestUtilsV2.PHI, new HashMap<String, Object>() {{
put("stringAttr", "string");
......
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