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/04/28 13:24:38 UTC
incubator-tinkerpop git commit: Remove some dead code in
GraphSONReader and add test for readVertices.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 40629d93d -> 18131fb5c
Remove some dead code in GraphSONReader and add test for readVertices.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/18131fb5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/18131fb5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/18131fb5
Branch: refs/heads/master
Commit: 18131fb5c3e95216e03b0ea0fd31114653fd3d6d
Parents: 40629d9
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Apr 28 07:24:11 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Apr 28 07:24:11 2015 -0400
----------------------------------------------------------------------
.../structure/io/graphson/GraphSONReader.java | 67 ++------------------
.../tinkerpop/gremlin/structure/IoTest.java | 27 ++++++++
2 files changed, 32 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/18131fb5/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 9ec1419..fad958a 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
@@ -18,9 +18,6 @@
*/
package org.apache.tinkerpop.gremlin.structure.io.graphson;
-import com.fasterxml.jackson.core.JsonFactory;
-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;
@@ -33,11 +30,8 @@ import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.util.Attachable;
import org.apache.tinkerpop.gremlin.structure.util.batch.BatchGraph;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.util.function.FunctionUtils;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.apache.tinkerpop.shaded.kryo.io.Input;
import org.javatuples.Pair;
import java.io.BufferedReader;
@@ -45,18 +39,13 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
/**
* A @{link GraphReader} that constructs a graph from a JSON-based representation of a graph and its elements.
@@ -71,18 +60,13 @@ import java.util.stream.Stream;
public class GraphSONReader implements GraphReader {
private final ObjectMapper mapper;
private final long batchSize;
- private final String vertexIdKey;
- private final String edgeIdKey;
final TypeReference<Map<String, Object>> mapTypeReference = new TypeReference<Map<String, Object>>() {
};
- public GraphSONReader(final GraphSONMapper mapper, final long batchSize,
- final String vertexIdKey, final String edgeIdKey) {
+ public GraphSONReader(final GraphSONMapper mapper, final long batchSize) {
this.mapper = mapper.createMapper();
this.batchSize = batchSize;
- this.vertexIdKey = vertexIdKey;
- this.edgeIdKey = edgeIdKey;
}
@Override
@@ -158,17 +142,10 @@ public class GraphSONReader implements GraphReader {
return mapper.readValue(inputStream, clazz);
}
- private static void createVertexProperty(final Graph graphToWriteTo, final Vertex v, final VertexProperty<Object> p) {
- final List<Object> propertyArgs = new ArrayList<>();
- if (graphToWriteTo.features().vertex().properties().supportsUserSuppliedIds())
- propertyArgs.addAll(Arrays.asList(T.id, p.id()));
- p.properties().forEachRemaining(it -> propertyArgs.addAll(Arrays.asList(it.key(), it.value())));
- v.property(VertexProperty.Cardinality.list, p.key(), p.value(), propertyArgs.toArray());
- }
-
private static void readAdjacentVertexEdges(final Function<Attachable<Edge>, Edge> edgeMaker,
- final StarGraph starGraph,
- final Map<String, Object> vertexData, final String direction) throws IOException {
+ final StarGraph starGraph,
+ final Map<String, Object> vertexData,
+ final String direction) throws IOException {
final Map<String, List<Map<String,Object>>> edgeDatas = (Map<String, List<Map<String,Object>>>) vertexData.get(direction);
for (Map.Entry<String, List<Map<String,Object>>> edgeData : edgeDatas.entrySet()) {
for (Map<String,Object> inner : edgeData.getValue()) {
@@ -190,18 +167,6 @@ public class GraphSONReader implements GraphReader {
}
}
- private static Edge readEdgeData(final Map<String, Object> edgeData, final Function<Attachable<Edge>, Edge> edgeMaker) throws IOException {
- final Map<String, Object> properties = (Map<String, Object>) edgeData.get(GraphSONTokens.PROPERTIES);
-
- final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokens.ID),
- edgeData.get(GraphSONTokens.LABEL).toString(),
- properties,
- 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);
- }
-
private static StarGraph readStarGraphData(final Map<String, Object> vertexData) throws IOException {
final StarGraph starGraph = StarGraph.open();
starGraph.addVertex(T.id, vertexData.get(GraphSONTokens.ID), T.label, vertexData.get(GraphSONTokens.LABEL));
@@ -230,8 +195,6 @@ public class GraphSONReader implements GraphReader {
public static class Builder implements ReaderBuilder<GraphSONReader> {
private long batchSize = BatchGraph.DEFAULT_BUFFER_SIZE;
- private String vertexIdKey = T.id.getAccessor();
- private String edgeIdKey = T.id.getAccessor();
private GraphSONMapper mapper = GraphSONMapper.build().create();
@@ -239,26 +202,6 @@ public class GraphSONReader implements GraphReader {
}
/**
- * The name of the key to supply to
- * {@link org.apache.tinkerpop.gremlin.structure.util.batch.BatchGraph.Builder#vertexIdKey} when reading data into
- * the {@link Graph}.
- */
- public Builder vertexIdKey(final String vertexIdKey) {
- this.vertexIdKey = vertexIdKey;
- return this;
- }
-
- /**
- * The name of the key to supply to
- * {@link org.apache.tinkerpop.gremlin.structure.util.batch.BatchGraph.Builder#edgeIdKey} when reading data into
- * the {@link Graph}.
- */
- public Builder edgeIdKey(final String edgeIdKey) {
- this.edgeIdKey = edgeIdKey;
- return this;
- }
-
- /**
* Number of mutations to perform before a commit is executed.
*/
public Builder batchSize(final long batchSize) {
@@ -277,7 +220,7 @@ public class GraphSONReader implements GraphReader {
}
public GraphSONReader create() {
- return new GraphSONReader(mapper, batchSize, vertexIdKey, edgeIdKey);
+ return new GraphSONReader(mapper, batchSize);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/18131fb5/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 c6dd688..ede8355 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
@@ -1319,6 +1319,33 @@ public class IoTest extends AbstractGremlinTest {
}
@Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldReadWriteVerticesNoEdgesToGraphSON() throws Exception {
+ try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+ final GraphSONWriter writer = graph.io(graphson).writer().create();
+ writer.writeVertices(os, g.V().has("age", P.gt(30)));
+
+ final AtomicInteger called = new AtomicInteger(0);
+ final GraphSONReader reader = graph.io(graphson).reader().create();
+
+ try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
+ final Iterator<Vertex> itty = reader.readVertices(bais,
+ attachable -> {
+ final Vertex detachedVertex = attachable.get();
+ called.incrementAndGet();
+ return detachedVertex;
+ }, null, null);
+
+ assertNotNull(itty.next());
+ assertNotNull(itty.next());
+ assertFalse(itty.hasNext());
+ }
+
+ assertEquals(2, called.get());
+ }
+ }
+
+ @Test
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
public void shouldReadWriteVerticesNoEdgesToGraphSONManual() throws Exception {
try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {