You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/05/06 15:34:45 UTC

incubator-tinkerpop git commit: Fixes up TINKERPOP3-661 which caused problems with graphs that don't support user supplied ids in IO.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 02b3f89e0 -> 8e9871d2f


Fixes up TINKERPOP3-661 which caused problems with graphs that don't support user supplied ids in IO.

Edge creation was forcing the recreation of vertices given the default operations for attaching an Edge with Attachable.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/8e9871d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/8e9871d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/8e9871d2

Branch: refs/heads/master
Commit: 8e9871d2f9d9e5dbc3dcd3f35bea52cb95c58232
Parents: 02b3f89
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed May 6 09:33:22 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed May 6 09:33:22 2015 -0400

----------------------------------------------------------------------
 .../gremlin/structure/io/graphson/GraphSONReader.java  | 12 +++++++++++-
 .../gremlin/structure/io/gryo/GryoReader.java          | 13 ++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8e9871d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
index e90faa3..26b88d6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONReader.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
@@ -88,7 +89,10 @@ public class GraphSONReader implements GraphReader {
         // have vertex labels in the output we can't do this single pass
         final Map<StarGraph.StarVertex,Vertex> cache = new HashMap<>();
         final AtomicLong counter = new AtomicLong(0);
+
         final boolean supportsTx = graphToWriteTo.features().graph().supportsTransactions();
+        final boolean supportsUserSuppliedIdsOnEdge = graphToWriteTo.features().edge().supportsUserSuppliedIds();
+
         final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
         br.lines().<Vertex>map(FunctionUtils.wrapFunction(line -> readVertex(new ByteArrayInputStream(line.getBytes()), null, null, Direction.OUT))).forEach(vertex -> {
             final Attachable<Vertex> attachable = (Attachable<Vertex>) vertex;
@@ -97,7 +101,13 @@ public class GraphSONReader implements GraphReader {
                 graphToWriteTo.tx().commit();
         });
         cache.entrySet().forEach(kv -> kv.getKey().edges(Direction.OUT).forEachRemaining(e -> {
-            ((StarGraph.StarEdge) e).attach(Attachable.Method.create(kv.getValue()));
+            // can't use a standard Attachable attach method here because we have to use the cache for those
+            // graphs that don't support userSuppliedIds on edges.  note that outVertex/inVertex methods return
+            // StarAdjacentVertex whose equality should match StarVertex.
+            final Vertex cachedOutV = cache.get(e.outVertex());
+            final Vertex cachedInV = cache.get(e.inVertex());
+            final Edge newEdge = supportsUserSuppliedIdsOnEdge ? cachedOutV.addEdge(e.label(), cachedInV, T.id, e.id()) : cachedOutV.addEdge(e.label(), cachedInV);
+            e.properties().forEachRemaining(p -> newEdge.property(p.key(), p.value()));
             if (supportsTx && counter.incrementAndGet() % batchSize == 0)
                 graphToWriteTo.tx().commit();
         }));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8e9871d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
index bdce1af..359fe79 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoReader.java
@@ -19,9 +19,11 @@
 package org.apache.tinkerpop.gremlin.structure.io.gryo;
 
 import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.io.GraphWriter;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.Host;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
@@ -81,7 +83,10 @@ public class GryoReader implements GraphReader {
         // have vertex labels in the output we can't do this single pass
         final Map<StarGraph.StarVertex,Vertex> cache = new HashMap<>();
         final AtomicLong counter = new AtomicLong(0);
+
+        final boolean supportsUserSuppliedIdsOnEdge = graphToWriteTo.features().edge().supportsUserSuppliedIds();
         final boolean supportsTx = graphToWriteTo.features().graph().supportsTransactions();
+
         IteratorUtils.iterate(new VertexInputIterator(new Input(inputStream), attachable -> {
             final Vertex v = cache.put((StarGraph.StarVertex) attachable.get(), attachable.attach(Attachable.Method.create(graphToWriteTo)));
             if (supportsTx && counter.incrementAndGet() % batchSize == 0)
@@ -89,7 +94,13 @@ public class GryoReader implements GraphReader {
             return v;
         }, null, null));
         cache.entrySet().forEach(kv -> kv.getKey().edges(Direction.OUT).forEachRemaining(e -> {
-            ((StarGraph.StarEdge) e).attach(Attachable.Method.create(kv.getValue()));
+            // can't use a standard Attachable attach method here because we have to use the cache for those
+            // graphs that don't support userSuppliedIds on edges. note that outVertex/inVertex methods return
+            // StarAdjacentVertex whose equality should match StarVertex.
+            final Vertex cachedOutV = cache.get(e.outVertex());
+            final Vertex cachedInV = cache.get(e.inVertex());
+            final Edge newEdge = supportsUserSuppliedIdsOnEdge ? cachedOutV.addEdge(e.label(), cachedInV, T.id, e.id()) : cachedOutV.addEdge(e.label(), cachedInV);
+            e.properties().forEachRemaining(p -> newEdge.property(p.key(), p.value()));
             if (supportsTx && counter.incrementAndGet() % batchSize == 0)
                 graphToWriteTo.tx().commit();
         }));