Commit 667abe4a by Madhan Neethiraj

ATLAS-2304: fix Relationship search API to work TinkerPop3

parent 28fb3cc6
...@@ -608,11 +608,11 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { ...@@ -608,11 +608,11 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
} }
if (ret.getEntities() == null) { if (ret.getEntities() == null) {
ret.setEntities(new ArrayList<AtlasEntityHeader>()); ret.setEntities(new ArrayList<>());
} }
} catch (ScriptException e) { } catch (ScriptException e) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Gremlin script execution failed for relationship search query: " + e); LOG.debug("Gremlin script execution failed for relationship search query: {}", relatedEntitiesQuery, e);
} }
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "Relationship search query failed"); throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "Relationship search query failed");
......
...@@ -23,6 +23,10 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider { ...@@ -23,6 +23,10 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider {
// In case any overrides are necessary, a specific switch case can be added here to // In case any overrides are necessary, a specific switch case can be added here to
// return Gremlin 3 specific query otherwise delegate to super.getQuery // return Gremlin 3 specific query otherwise delegate to super.getQuery
switch (gremlinQuery) { switch (gremlinQuery) {
case TYPE_UNUSED_COUNT_METRIC:
return "g.V().has('__type', 'typeSystem').filter({ !it.getProperty('__type.category').name().matches('TRAIT') && it.inE().count() == 0}).count()";
case ENTITY_COUNT_METRIC:
return "g.V().has('__superTypeNames', within(['Referenceable'])).count()";
case EXPORT_TYPE_STARTS_WITH: case EXPORT_TYPE_STARTS_WITH:
return "g.V().has('__typeName',typeName).filter({it.get().value(attrName).startsWith(attrValue)}).has('__guid').values('__guid').toList()"; return "g.V().has('__typeName',typeName).filter({it.get().value(attrName).startsWith(attrValue)}).has('__guid').values('__guid').toList()";
case EXPORT_TYPE_ENDS_WITH: case EXPORT_TYPE_ENDS_WITH:
...@@ -33,6 +37,8 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider { ...@@ -33,6 +37,8 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider {
return "g.V().has('__typeName',typeName).filter({it.get().value(attrName).matches(attrValue)}).has('__guid').values('__guid').toList()"; return "g.V().has('__typeName',typeName).filter({it.get().value(attrName).matches(attrValue)}).has('__guid').values('__guid').toList()";
case EXPORT_TYPE_DEFAULT: case EXPORT_TYPE_DEFAULT:
return "g.V().has('__typeName',typeName).has(attrName, attrValue).has('__guid').values('__guid').toList()"; return "g.V().has('__typeName',typeName).has(attrName, attrValue).has('__guid').values('__guid').toList()";
case EXPORT_BY_GUID_FULL:
return "g.V().has('__guid', startGuid).bothE().bothV().has('__guid').transform{[__guid:it.__guid,isProcess:(it.__superTypeNames != null) ? it.__superTypeNames.contains('Process') : false ]}.dedup().toList()";
case EXPORT_BY_GUID_CONNECTED_IN_EDGE: case EXPORT_BY_GUID_CONNECTED_IN_EDGE:
return "g.V().has('__guid', startGuid).inE().outV().has('__guid').project('__guid', 'isProcess').by('__guid').by(map {it.get().values('__superTypeNames').toSet().contains('Process')}).dedup().toList()"; return "g.V().has('__guid', startGuid).inE().outV().has('__guid').project('__guid', 'isProcess').by('__guid').by(map {it.get().values('__superTypeNames').toSet().contains('Process')}).dedup().toList()";
case EXPORT_BY_GUID_CONNECTED_OUT_EDGE: case EXPORT_BY_GUID_CONNECTED_OUT_EDGE:
...@@ -45,6 +51,14 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider { ...@@ -45,6 +51,14 @@ public class AtlasGremlin3QueryProvider extends AtlasGremlin2QueryProvider {
return "g.V().has('__guid', '%s').repeat(__.in('%s').out('%s')).times(%s)." + return "g.V().has('__guid', '%s').repeat(__.in('%s').out('%s')).times(%s)." +
"emit(has('__superTypeNames').and().properties('__superTypeNames').hasValue('DataSet'))." + "emit(has('__superTypeNames').and().properties('__superTypeNames').hasValue('DataSet'))." +
"path().toList()"; "path().toList()";
case TO_RANGE_LIST:
return ".range(startIdx, endIdx).toList()";
case RELATIONSHIP_SEARCH:
return "g.V().has('__guid', guid).both(relation).has('__state', within(states))";
case RELATIONSHIP_SEARCH_ASCENDING_SORT:
return ".order().by(sortAttributeName, incr)";
case RELATIONSHIP_SEARCH_DESCENDING_SORT:
return ".order().by(sortAttributeName, decr)";
case GREMLIN_SEARCH_RETURNS_VERTEX_ID: case GREMLIN_SEARCH_RETURNS_VERTEX_ID:
return "g.V().range(0,1).toList()"; return "g.V().range(0,1).toList()";
case GREMLIN_SEARCH_RETURNS_EDGE_ID: case GREMLIN_SEARCH_RETURNS_EDGE_ID:
......
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