You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/06/17 18:01:11 UTC
incubator-atlas git commit: ATLAS-1875: updated gremlin search to
include vertex id in the result
Repository: incubator-atlas
Updated Branches:
refs/heads/master d9f62cb5a -> c6081ddcf
ATLAS-1875: updated gremlin search to include vertex id in the result
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/c6081ddc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/c6081ddc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/c6081ddc
Branch: refs/heads/master
Commit: c6081ddcfdb4c8100a4b099405ac8d397fbf9583
Parents: d9f62cb
Author: Christian Rieck <ch...@dnvgl.com>
Authored: Fri Jun 16 10:45:22 2017 +0200
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Sat Jun 17 10:29:19 2017 -0700
----------------------------------------------------------------------
.../graph/GraphBackedDiscoveryService.java | 25 ++++++++++++++---
.../GraphBackedDiscoveryServiceTest.java | 28 +++++++++++++++++++-
2 files changed, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c6081ddc/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
index 083c34d..aed8659 100755
--- a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
@@ -71,6 +71,22 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
private final DefaultGraphPersistenceStrategy graphPersistenceStrategy;
public final static String SCORE = "score";
+ /**
+ * Where the vertex' internal gremlin id is stored in the Map produced by extractResult()
+ */
+ public final static String GREMLIN_ID_KEY = "id";
+ /**
+ * Where the id of an edge's incoming vertex is stored in the Map produced by extractResult()
+ */
+ public final static String GREMLIN_INVERTEX_KEY = "inVertex";
+ /**
+ * Where the id of an edge's outgoing vertex is stored in the Map produced by extractResult()
+ */
+ public final static String GREMLIN_OUTVERTEX_KEY = "outVertex";
+ /**
+ * Where an edge's label is stored in the Map produced by extractResult()
+ */
+ public final static String GREMLIN_LABEL_KEY = "label";
@Inject
GraphBackedDiscoveryService(MetadataRepository metadataRepository, AtlasGraph atlasGraph)
@@ -223,15 +239,16 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
oRow.put(key, propertyValue.toString());
}
}
+ oRow.put(GREMLIN_ID_KEY, vertex.getId().toString());
} else if (value instanceof String) {
oRow.put("", value.toString());
} else if(value instanceof AtlasEdge) {
AtlasEdge edge = (AtlasEdge) value;
- oRow.put("id", edge.getId().toString());
- oRow.put("label", edge.getLabel());
- oRow.put("inVertex", edge.getInVertex().getId().toString());
- oRow.put("outVertex", edge.getOutVertex().getId().toString());
+ oRow.put(GREMLIN_ID_KEY, edge.getId().toString());
+ oRow.put(GREMLIN_LABEL_KEY, edge.getLabel());
+ oRow.put(GREMLIN_INVERTEX_KEY, edge.getInVertex().getId().toString());
+ oRow.put(GREMLIN_OUTVERTEX_KEY, edge.getOutVertex().getId().toString());
for (String propertyKey : edge.getPropertyKeys()) {
oRow.put(propertyKey, GraphHelper.getProperty(edge, propertyKey).toString());
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c6081ddc/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java b/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
index 834abe1..675ab8a 100755
--- a/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
@@ -227,6 +227,32 @@ public class GraphBackedDiscoveryServiceTest extends BaseRepositoryTest {
assertEquals(rows.length(), 1);
}
+
+ /*
+ * https://issues.apache.org/jira/browse/ATLAS-1875
+ */
+ @Test
+ public void testGremlinSearchReturnVertexId() throws Exception {
+ List<Map<String,String>> gremlinResults = discoveryService.searchByGremlin("g.V.range(0,0).collect()");
+ assertEquals(gremlinResults.size(), 1);
+ Map<String, String> properties = gremlinResults.get(0);
+ Assert.assertTrue(properties.containsKey(GraphBackedDiscoveryService.GREMLIN_ID_KEY));
+ }
+
+ /*
+ * https://issues.apache.org/jira/browse/ATLAS-1875
+ */
+ @Test
+ public void testGremlinSearchReturnEdgeIds() throws Exception {
+ List<Map<String,String>> gremlinResults = discoveryService.searchByGremlin("g.E.range(0,0).collect()");
+ assertEquals(gremlinResults.size(), 1);
+ Map<String, String> properties = gremlinResults.get(0);
+ Assert.assertTrue(properties.containsKey(GraphBackedDiscoveryService.GREMLIN_INVERTEX_KEY));
+ Assert.assertTrue(properties.containsKey(GraphBackedDiscoveryService.GREMLIN_OUTVERTEX_KEY));
+ Assert.assertTrue(properties.containsKey(GraphBackedDiscoveryService.GREMLIN_LABEL_KEY));
+ }
+
+
@Test
public void testSearchByDSLReturnsEntity() throws Exception {
String dslQuery = "from Department";
@@ -1284,4 +1310,4 @@ public class GraphBackedDiscoveryServiceTest extends BaseRepositoryTest {
private boolean isGremlin3() {
return TestUtils.getGraph().getSupportedGremlinVersion() == GremlinVersion.THREE;
}
-}
\ No newline at end of file
+}