You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/04/24 21:41:03 UTC
[1/3] incubator-tinkerpop git commit: Add Direction back to
readVertex/Vertices.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/p-predicate-model 5ae2fd5cb -> d67884402
Add Direction back to readVertex/Vertices.
It seems necessary to have this to decide which edges should be given to the edgeMaker. Without there could be a lot of wasted processing.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/7bc95318
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/7bc95318
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/7bc95318
Branch: refs/heads/p-predicate-model
Commit: 7bc9531891685cef31ad3e5b41840e9b441e18b1
Parents: 1ea7692
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Apr 24 15:25:15 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Apr 24 15:25:15 2015 -0400
----------------------------------------------------------------------
.../gremlin/structure/io/GraphReader.java | 9 +++-
.../structure/io/graphml/GraphMLReader.java | 7 ++-
.../structure/io/graphson/GraphSONReader.java | 13 +++--
.../io/graphson/LegacyGraphSONReader.java | 8 ++-
.../gremlin/structure/io/gryo/GryoReader.java | 34 ++++++++----
.../tinkerpop/gremlin/structure/IoTest.java | 57 ++++++--------------
.../io/graphson/GraphSONRecordReader.java | 2 +-
.../structure/io/gryo/GryoRecordReader.java | 2 +-
8 files changed, 68 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
index f61d00a..73d929c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.structure.io;
+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.Vertex;
@@ -62,10 +63,12 @@ public interface GraphReader {
* @param edgeMaker a function that creates an edge from the stream where the first argument is the edge
* identifier, the second argument is the out vertex id, the third is the in vertex id,
* the fourth is the label, and the fifth is the list of properties as key/value pairs.
+ * @param attachEdgesOfThisDirection only edges of this direction are passed to the {@code edgeMaker}.
*/
public Vertex readVertex(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException;
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException;
/**
* Reads a set of vertices from an {@link InputStream} which were written by
@@ -78,10 +81,12 @@ public interface GraphReader {
* @param edgeMaker a function that creates an edge from the stream where the first argument is the edge
* identifier, the second argument is the out vertex id, the third is the in vertex id,
* the fourth is the label, and the fifth is the list of properties as key/value pairs.
+ * @param attachEdgesOfThisDirection only edges of this direction are passed to the {@code edgeMaker}.
*/
public Iterator<Vertex> readVertices(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException;
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException;
/**
* Reads a single edge from an {@link InputStream}.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
index 2a8f8e0..23c5b96 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.structure.io.graphml;
+import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -73,7 +74,8 @@ public class GraphMLReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@@ -89,7 +91,8 @@ public class GraphMLReader implements GraphReader {
@Override
public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/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 cd27543..31af797 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
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -139,9 +140,10 @@ public class GraphSONReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
- return br.lines().<Vertex>map(FunctionUtils.wrapFunction(line -> readVertex(new ByteArrayInputStream(line.getBytes()), vertexMaker, edgeMaker))).iterator();
+ return br.lines().<Vertex>map(FunctionUtils.wrapFunction(line -> readVertex(new ByteArrayInputStream(line.getBytes()), vertexMaker, edgeMaker, attachEdgesOfThisDirection))).iterator();
}
@Override
@@ -166,14 +168,15 @@ public class GraphSONReader implements GraphReader {
@Override
public Vertex readVertex(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
final Map<String, Object> vertexData = mapper.readValue(inputStream, mapTypeReference);
final Vertex v = readVertexData(vertexData, vertexMaker);
- if (vertexData.containsKey(GraphSONTokens.OUT_E))
+ if (edgeMaker != null && vertexData.containsKey(GraphSONTokens.OUT_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.OUT))
readVertexEdges(edgeMaker, vertexData, GraphSONTokens.OUT_E);
- if (vertexData.containsKey(GraphSONTokens.IN_E))
+ if (edgeMaker != null && vertexData.containsKey(GraphSONTokens.IN_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.IN))
readVertexEdges(edgeMaker, vertexData, GraphSONTokens.IN_E);
return v;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
index ed062df..d607795 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
+import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -118,7 +119,8 @@ public class LegacyGraphSONReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@@ -133,7 +135,9 @@ public class LegacyGraphSONReader implements GraphReader {
}
@Override
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker, final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker,
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/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 9c7eca0..9279580 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
@@ -64,8 +64,9 @@ public class GryoReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
- return new VertexInputIterator(new Input(inputStream), vertexMaker);
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
+ return new VertexInputIterator(new Input(inputStream), vertexMaker, attachEdgesOfThisDirection, edgeMaker);
}
@Override
@@ -78,15 +79,16 @@ public class GryoReader implements GraphReader {
@Override
public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker) throws IOException {
- return readVertex(inputStream, vertexMaker, null);
+ return readVertex(inputStream, vertexMaker, null, null);
}
@Override
public Vertex readVertex(final InputStream inputStream,
final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction attachEdgesOfThisDirection) throws IOException {
final Input input = new Input(inputStream);
- return readVertexInternal(vertexMaker, input);
+ return readVertexInternal(vertexMaker, edgeMaker, attachEdgesOfThisDirection, input);
}
@Override
@@ -101,7 +103,7 @@ public class GryoReader implements GraphReader {
if (supportsTx && counter.incrementAndGet() % batchSize == 0)
graphToWriteTo.tx().commit();
return v;
- }));
+ }, null, null));
cache.entrySet().forEach(kv -> kv.getKey().edges(Direction.OUT).forEachRemaining(e -> {
((StarGraph.StarEdge) e).attach(Attachable.Method.create(kv.getValue()));
if (supportsTx && counter.incrementAndGet() % batchSize == 0)
@@ -114,14 +116,19 @@ public class GryoReader implements GraphReader {
return clazz.cast(this.kryo.readClassAndObject(new Input(inputStream)));
}
- private Vertex readVertexInternal(final Function<Attachable<Vertex>, Vertex> vertexMaker, final Input input) throws IOException {
+ private Vertex readVertexInternal(final Function<Attachable<Vertex>, Vertex> vertexMaker,
+ final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Direction d,
+ final Input input) throws IOException {
readHeader(input);
final StarGraph starGraph = kryo.readObject(input, StarGraph.class);
// read the terminator
kryo.readClassAndObject(input);
- return vertexMaker.apply(starGraph.getStarVertex());
+ final Vertex v = vertexMaker.apply(starGraph.getStarVertex());
+ if (edgeMaker != null) starGraph.getStarVertex().edges(d).forEachRemaining(e -> edgeMaker.apply((Attachable<Edge>) e));
+ return v;
}
private void readHeader(final Input input) throws IOException {
@@ -173,9 +180,16 @@ public class GryoReader implements GraphReader {
private class VertexInputIterator implements Iterator<Vertex> {
private final Input input;
private final Function<Attachable<Vertex>, Vertex> vertexMaker;
+ private final Direction d;
+ private final Function<Attachable<Edge>, Edge> edgeMaker;
- public VertexInputIterator(final Input input, final Function<Attachable<Vertex>, Vertex> vertexMaker) {
+ public VertexInputIterator(final Input input,
+ final Function<Attachable<Vertex>, Vertex> vertexMaker,
+ final Direction d,
+ final Function<Attachable<Edge>, Edge> edgeMaker) {
this.input = input;
+ this.d = d;
+ this.edgeMaker = edgeMaker;
this.vertexMaker = vertexMaker;
}
@@ -187,7 +201,7 @@ public class GryoReader implements GraphReader {
@Override
public Vertex next() {
try {
- return readVertexInternal(vertexMaker, input);
+ return readVertexInternal(vertexMaker, edgeMaker, d, input);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
index 5a28680..0525b30 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
@@ -1308,7 +1308,7 @@ public class IoTest extends AbstractGremlinTest {
final Vertex detachedVertex = attachable.get();
called.incrementAndGet();
return detachedVertex;
- }, null);
+ }, null, null);
assertNotNull(itty.next());
assertNotNull(itty.next());
@@ -1332,7 +1332,6 @@ public class IoTest extends AbstractGremlinTest {
String line = br.readLine();
reader.readVertex(new ByteArrayInputStream(line.getBytes()),
attachable -> {
- final Vertex detachedVertex = attachable.get();
called.incrementAndGet();
return mock(Vertex.class);
});
@@ -1377,22 +1376,15 @@ public class IoTest extends AbstractGremlinTest {
},
attachable -> {
final Edge detachedEdge = attachable.get();
- assertEquals(e.id(), detachedEdge.id());
- assertEquals(v1.id(), detachedEdge.outVertex().id());
- assertEquals(v2.id(), detachedEdge.inVertex().id());
- assertEquals(v1.label(), detachedEdge.outVertex().label());
- assertEquals(v2.label(), detachedEdge.inVertex().label());
- assertEquals(e.label(), detachedEdge.label());
- assertEquals(1, IteratorUtils.count(detachedEdge.properties()));
- assertEquals(0.5d, detachedEdge.value("weight"), 0.00001d);
-
+ TestHelper.validateEdgeEquality(e, detachedEdge);
calledEdge.set(true);
return detachedEdge;
- });
+ }, Direction.OUT);
}
assertTrue(calledVertex.get());
+ assertTrue(calledEdge.get());
}
}
@@ -1436,7 +1428,7 @@ public class IoTest extends AbstractGremlinTest {
calledEdge.set(true);
return null;
- });
+ }, Direction.OUT);
}
assertTrue(calledVertex.get());
@@ -1471,22 +1463,15 @@ public class IoTest extends AbstractGremlinTest {
return detachedVertex;
}, attachable -> {
final Edge detachedEdge = attachable.get();
- assertEquals(e.id(), detachedEdge.id());
- assertEquals(v2.id(), detachedEdge.outVertex().id());
- assertEquals(v1.id(), detachedEdge.inVertex().id());
- assertEquals(v1.label(), detachedEdge.outVertex().label());
- assertEquals(v2.label(), detachedEdge.inVertex().label());
- assertEquals(e.label(), detachedEdge.label());
- assertEquals(1, IteratorUtils.count(detachedEdge.properties()));
- assertEquals(0.5d, detachedEdge.value("weight"), 0.00001d);
-
+ TestHelper.validateEdgeEquality(e, detachedEdge);
calledEdge.set(true);
return detachedEdge;
- });
+ }, Direction.IN);
}
assertTrue(calledVertex.get());
+ assertTrue(calledEdge.get());
}
}
@@ -1531,7 +1516,7 @@ public class IoTest extends AbstractGremlinTest {
calledEdge.set(true);
return null;
- });
+ }, Direction.IN);
}
assertTrue(calledVertex.get());
@@ -1569,32 +1554,22 @@ public class IoTest extends AbstractGremlinTest {
},attachable -> {
final Edge detachedEdge = attachable.get();
if (detachedEdge.id().equals(e1.id())) {
- assertEquals(v2.id(), detachedEdge.outVertex().id());
- assertEquals(v1.id(), detachedEdge.inVertex().id());
- assertEquals(v1.label(), detachedEdge.outVertex().label());
- assertEquals(v2.label(), detachedEdge.inVertex().label());
- assertEquals(e1.label(), detachedEdge.label());
- assertEquals(1, IteratorUtils.count(detachedEdge.properties()));
- assertEquals(0.5d, detachedEdge.value("weight"), 0.00001d);
+ TestHelper.validateEdgeEquality(e1, detachedEdge);
calledEdge1.set(true);
} else if (detachedEdge.id().equals(e2.id())) {
- assertEquals(v1.id(), detachedEdge.outVertex().id());
- assertEquals(v2.id(), detachedEdge.inVertex().id());
- assertEquals(v1.label(), detachedEdge.outVertex().label());
- assertEquals(v2.label(), detachedEdge.inVertex().label());
- assertEquals(e1.label(), detachedEdge.label());
- assertEquals(1, IteratorUtils.count(detachedEdge.properties()));
- assertEquals(1.0d, detachedEdge.value("weight"), 0.00001d);
+ TestHelper.validateEdgeEquality(e2, detachedEdge);
calledEdge2.set(true);
} else {
fail("An edge id generated that does not exist");
}
return null;
- });
+ }, Direction.BOTH);
}
assertTrue(calledVertex.get());
+ assertTrue(calledEdge1.get());
+ assertTrue(calledEdge2.get());
}
}
@@ -1655,7 +1630,7 @@ public class IoTest extends AbstractGremlinTest {
}
return null;
- });
+ }, Direction.BOTH);
}
assertTrue(vertexCalled.get());
@@ -1723,7 +1698,7 @@ public class IoTest extends AbstractGremlinTest {
}
return null;
- });
+ }, Direction.BOTH);
}
assertTrue(vertexCalled.get());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONRecordReader.java
index 6a61cd7..69fca07 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONRecordReader.java
@@ -69,7 +69,7 @@ public class GraphSONRecordReader extends RecordReader<NullWritable, VertexWrita
final Function<Attachable<Edge>, Edge> edgeMaker = detachedEdge -> detachedEdge.attach(Attachable.Method.create(starGraph));
try (InputStream in = new ByteArrayInputStream(this.lineRecordReader.getCurrentValue().getBytes())) {
this.vertexWritable.set(this.hasEdges ?
- this.graphsonReader.readVertex(in, vertexMaker, edgeMaker) :
+ this.graphsonReader.readVertex(in, vertexMaker, edgeMaker, Direction.BOTH) :
this.graphsonReader.readVertex(in, vertexMaker));
return true;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7bc95318/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/GryoRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/GryoRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/GryoRecordReader.java
index 775246b..8435666 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/GryoRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/GryoRecordReader.java
@@ -135,7 +135,7 @@ public class GryoRecordReader extends RecordReader<NullWritable, VertexWritable>
final Function<Attachable<Edge>, Edge> edgeMaker = detachedEdge -> detachedEdge.attach(Attachable.Method.create(starGraph));
try (InputStream in = new ByteArrayInputStream(output.toByteArray())) {
this.vertexWritable.set(this.hasEdges ?
- this.gryoReader.readVertex(in, vertexMaker, edgeMaker) :
+ this.gryoReader.readVertex(in, vertexMaker, edgeMaker, Direction.BOTH) :
this.gryoReader.readVertex(in, vertexMaker));
return true;
}
[2/3] incubator-tinkerpop git commit: Rename parameters for
readVertex attachment methods.
Posted by ok...@apache.org.
Rename parameters for readVertex attachment methods.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/86b78b73
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/86b78b73
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/86b78b73
Branch: refs/heads/p-predicate-model
Commit: 86b78b73d1ea62ef48c690adda1b90c4ba41c6b2
Parents: 7bc9531
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Apr 24 15:31:55 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Apr 24 15:31:55 2015 -0400
----------------------------------------------------------------------
.../gremlin/structure/io/GraphReader.java | 24 ++++++++---------
.../structure/io/graphml/GraphMLReader.java | 12 ++++-----
.../structure/io/graphson/GraphSONReader.java | 28 ++++++++++----------
.../io/graphson/LegacyGraphSONReader.java | 12 ++++-----
.../gremlin/structure/io/gryo/GryoReader.java | 20 +++++++-------
5 files changed, 48 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/86b78b73/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
index 73d929c..5aad86f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/GraphReader.java
@@ -48,26 +48,26 @@ public interface GraphReader {
* Reads a single vertex from an {@link InputStream}. This method will read vertex properties but not edges.
*
* @param inputStream a stream containing a single vertex as defined by the accompanying {@link GraphWriter}
- * @param vertexMaker a function to create a vertex where the first argument is the vertex identifier, the
+ * @param vertexAttachMethod a function to create a vertex where the first argument is the vertex identifier, the
* second argument is vertex label and the last is the list of properties for it
*/
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker) throws IOException;
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod) throws IOException;
/**
* Reads a single vertex from an {@link InputStream}. This method will read vertex properties as well as edges
* given the direction supplied as an argument.
*
* @param inputStream a stream containing a single vertex as defined by the accompanying {@link GraphWriter}
- * @param vertexMaker a function to create a vertex where the first argument is the vertex identifier, the
+ * @param vertexAttachMethod a function to create a vertex where the first argument is the vertex identifier, the
* second argument is vertex label and the last is the list of properties for it
- * @param edgeMaker a function that creates an edge from the stream where the first argument is the edge
+ * @param edgeAttachMethod a function that creates an edge from the stream where the first argument is the edge
* identifier, the second argument is the out vertex id, the third is the in vertex id,
* the fourth is the label, and the fifth is the list of properties as key/value pairs.
* @param attachEdgesOfThisDirection only edges of this direction are passed to the {@code edgeMaker}.
*/
public Vertex readVertex(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException;
/**
@@ -76,27 +76,27 @@ public interface GraphReader {
* will read vertex properties as well as edges given the direction supplied as an argument.
*
* @param inputStream a stream containing a single vertex as defined by the accompanying {@link GraphWriter}
- * @param vertexMaker a function to create a vertex where the first argument is the vertex identifier, the
+ * @param vertexAttachMethod a function to create a vertex where the first argument is the vertex identifier, the
* second argument is vertex label and the last is the list of properties for it
- * @param edgeMaker a function that creates an edge from the stream where the first argument is the edge
+ * @param edgeAttachMethod a function that creates an edge from the stream where the first argument is the edge
* identifier, the second argument is the out vertex id, the third is the in vertex id,
* the fourth is the label, and the fifth is the list of properties as key/value pairs.
* @param attachEdgesOfThisDirection only edges of this direction are passed to the {@code edgeMaker}.
*/
public Iterator<Vertex> readVertices(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException;
/**
* Reads a single edge from an {@link InputStream}.
*
* @param inputStream a stream containing a single vertex as defined by the accompanying {@link GraphWriter}
- * @param reattach a function that creates an edge from the stream where the first argument is the edge
+ * @param edgeAttachMethod a function that creates an edge from the stream where the first argument is the edge
* identifier, the second argument is the out vertex id, the third is the in vertex id,
* the fourth is the label, and the fifth is the list of properties as key/value pairs.
*/
- public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> reattach) throws IOException;
+ public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException;
/**
* Reads an arbitrary object using the standard serializers.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/86b78b73/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
index 23c5b96..209c320 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
@@ -73,25 +73,25 @@ public class GraphMLReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@Override
- public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@Override
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker) throws IOException {
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@Override
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/86b78b73/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 31af797..d3e3204 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
@@ -139,15 +139,15 @@ public class GraphSONReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
- return br.lines().<Vertex>map(FunctionUtils.wrapFunction(line -> readVertex(new ByteArrayInputStream(line.getBytes()), vertexMaker, edgeMaker, attachEdgesOfThisDirection))).iterator();
+ return br.lines().<Vertex>map(FunctionUtils.wrapFunction(line -> readVertex(new ByteArrayInputStream(line.getBytes()), vertexAttachMethod, edgeAttachMethod, attachEdgesOfThisDirection))).iterator();
}
@Override
- public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException {
final Map<String, Object> edgeData = mapper.readValue(inputStream, mapTypeReference);
final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokens.ID),
@@ -156,28 +156,28 @@ public class GraphSONReader implements GraphReader {
Pair.with(edgeData.get(GraphSONTokens.OUT), edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
Pair.with(edgeData.get(GraphSONTokens.IN), edgeData.get(GraphSONTokens.IN_LABEL).toString()));
- return edgeMaker.apply(edge);
+ return edgeAttachMethod.apply(edge);
}
@Override
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker) throws IOException {
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod) throws IOException {
final Map<String, Object> vertexData = mapper.readValue(inputStream, mapTypeReference);
- return readVertexData(vertexData, vertexMaker);
+ return readVertexData(vertexData, vertexAttachMethod);
}
@Override
public Vertex readVertex(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
final Map<String, Object> vertexData = mapper.readValue(inputStream, mapTypeReference);
- final Vertex v = readVertexData(vertexData, vertexMaker);
+ final Vertex v = readVertexData(vertexData, vertexAttachMethod);
- if (edgeMaker != null && vertexData.containsKey(GraphSONTokens.OUT_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.OUT))
- readVertexEdges(edgeMaker, vertexData, GraphSONTokens.OUT_E);
+ if (edgeAttachMethod != null && vertexData.containsKey(GraphSONTokens.OUT_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.OUT))
+ readVertexEdges(edgeAttachMethod, vertexData, GraphSONTokens.OUT_E);
- if (edgeMaker != null && vertexData.containsKey(GraphSONTokens.IN_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.IN))
- readVertexEdges(edgeMaker, vertexData, GraphSONTokens.IN_E);
+ if (edgeAttachMethod != null && vertexData.containsKey(GraphSONTokens.IN_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.IN))
+ readVertexEdges(edgeAttachMethod, vertexData, GraphSONTokens.IN_E);
return v;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/86b78b73/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
index d607795..0009432 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
@@ -118,25 +118,25 @@ public class LegacyGraphSONReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@Override
- public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@Override
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker) throws IOException {
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
@Override
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass());
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/86b78b73/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 9279580..95dce2c 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
@@ -63,32 +63,32 @@ public class GryoReader implements GraphReader {
@Override
public Iterator<Vertex> readVertices(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
- return new VertexInputIterator(new Input(inputStream), vertexMaker, attachEdgesOfThisDirection, edgeMaker);
+ return new VertexInputIterator(new Input(inputStream), vertexAttachMethod, attachEdgesOfThisDirection, edgeAttachMethod);
}
@Override
- public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
+ public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException {
final Input input = new Input(inputStream);
readHeader(input);
final Attachable<Edge> attachable = kryo.readObject(input, DetachedEdge.class);
- return edgeMaker.apply(attachable);
+ return edgeAttachMethod.apply(attachable);
}
@Override
- public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexMaker) throws IOException {
- return readVertex(inputStream, vertexMaker, null, null);
+ public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod) throws IOException {
+ return readVertex(inputStream, vertexAttachMethod, null, null);
}
@Override
public Vertex readVertex(final InputStream inputStream,
- final Function<Attachable<Vertex>, Vertex> vertexMaker,
- final Function<Attachable<Edge>, Edge> edgeMaker,
+ final Function<Attachable<Vertex>, Vertex> vertexAttachMethod,
+ final Function<Attachable<Edge>, Edge> edgeAttachMethod,
final Direction attachEdgesOfThisDirection) throws IOException {
final Input input = new Input(inputStream);
- return readVertexInternal(vertexMaker, edgeMaker, attachEdgesOfThisDirection, input);
+ return readVertexInternal(vertexAttachMethod, edgeAttachMethod, attachEdgesOfThisDirection, input);
}
@Override
[3/3] incubator-tinkerpop git commit: Merge branch 'master' into
p-predicate-model
Posted by ok...@apache.org.
Merge branch 'master' into p-predicate-model
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d6788440
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d6788440
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d6788440
Branch: refs/heads/p-predicate-model
Commit: d67884402b30d3c1078b5142a9f14a27eb30f919
Parents: 5ae2fd5 86b78b7
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Apr 24 13:40:56 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Apr 24 13:40:56 2015 -0600
----------------------------------------------------------------------
.../gremlin/structure/io/GraphReader.java | 29 +++++-----
.../structure/io/graphml/GraphMLReader.java | 15 +++---
.../structure/io/graphson/GraphSONReader.java | 31 ++++++-----
.../io/graphson/LegacyGraphSONReader.java | 14 +++--
.../gremlin/structure/io/gryo/GryoReader.java | 44 +++++++++------
.../tinkerpop/gremlin/structure/IoTest.java | 57 ++++++--------------
.../io/graphson/GraphSONRecordReader.java | 2 +-
.../structure/io/gryo/GryoRecordReader.java | 2 +-
8 files changed, 99 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d6788440/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
----------------------------------------------------------------------