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/08/13 22:03:36 UTC
[19/22] incubator-tinkerpop git commit: Now successfully passing all
IODataGeneration tests - including and especially those tests which write out
legacy TP2 GraphSON in both vertices/edges- and adjacency list (as output by
Faunus during export to GraphS
Now successfully passing all IODataGeneration tests - including and especially those tests which write out legacy TP2 GraphSON in both vertices/edges- and adjacency list (as output by Faunus during export to GraphSON) format flavors.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/456f844e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/456f844e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/456f844e
Branch: refs/heads/tp30-legson
Commit: 456f844e945254aba1e17c39c89595289ea4c331
Parents: aee3822
Author: ebice <eb...@behaviormatrix.com>
Authored: Thu Jul 9 11:24:26 2015 -0400
Committer: ebice <eb...@behaviormatrix.com>
Committed: Thu Jul 9 11:24:26 2015 -0400
----------------------------------------------------------------------
.../io/graphson/FaunusGraphSONUtility.java | 46 +++++++++++++++-----
.../io/graphson/GraphSONLegacyWriter.java | 32 +++++---------
.../io/graphson/TP2GraphSONUtility.java | 23 +++++-----
.../GraphSONLegacyRecordReaderTest.java | 2 +-
4 files changed, 60 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/456f844e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
index e40a77f..e455d5e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.tinkerpop.gremlin.structure.io.graphson;
import org.apache.tinkerpop.gremlin.structure.Direction;
@@ -92,27 +110,31 @@ public class FaunusGraphSONUtility {
public static JSONObject toJSON(final Vertex vertex) throws IOException {
try {
- final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, getElementPropertyKeys(vertex, false), GraphSONMode.COMPACT);
+ //final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, getElementPropertyKeys(vertex, false), GraphSONMode.COMPACT);
+ final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, null, GraphSONMode.COMPACT);
// force the ID to long. with blueprints, most implementations will send back a long, but
// some like TinkerGraph will return a string. the same is done for edges below
object.put(GraphSONTokensTP2._ID, Long.valueOf(object.remove(GraphSONTokensTP2._ID).toString()));
- List<Edge> edges = (List<Edge>) vertex.edges(OUT);
+ List<Edge> edges = new ArrayList<Edge>();
+ vertex.edges(OUT).forEachRemaining(edges::add);
if (!edges.isEmpty()) {
final JSONArray outEdgesArray = new JSONArray();
for (final Edge outEdge : edges) {
- final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, getElementPropertyKeys(outEdge, true), GraphSONMode.COMPACT);
+ //final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, getElementPropertyKeys(outEdge, true), GraphSONMode.COMPACT);
+ final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, null, GraphSONMode.COMPACT);
outEdgesArray.put(edgeObject);
}
object.put(GraphSONTokensTP2._OUT_E, outEdgesArray);
}
- edges = (List<Edge>) vertex.edges(IN);
+ vertex.edges(IN).forEachRemaining(edges::add);
if (!edges.isEmpty()) {
final JSONArray inEdgesArray = new JSONArray();
for (final Edge inEdge : edges) {
- final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, getElementPropertyKeys(inEdge, false), GraphSONMode.COMPACT);
+ //final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, getElementPropertyKeys(inEdge, false), GraphSONMode.COMPACT);
+ final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, null, GraphSONMode.COMPACT);
inEdgesArray.put(edgeObject);
}
object.put(GraphSONTokensTP2._IN_E, inEdgesArray);
@@ -126,21 +148,21 @@ public class FaunusGraphSONUtility {
private static Set<String> getElementPropertyKeys(final Element element, final boolean edgeIn) {
final Set<String> elementPropertyKeys = new HashSet<String>(element.keys()); // .getPropertyKeys());
- elementPropertyKeys.add(GraphSONTokensTP2._ID);
+ // exclude reserved keys? not really properties?
+ /*elementPropertyKeys.add(GraphSONTokens.ID);
if (element instanceof Edge) {
if (edgeIn) {
- elementPropertyKeys.add(GraphSONTokensTP2._IN_V);
+ elementPropertyKeys.add(GraphSONTokens.IN);
} else {
- elementPropertyKeys.add(GraphSONTokensTP2._OUT_V);
+ elementPropertyKeys.add(GraphSONTokens.OUT);
}
- elementPropertyKeys.add(GraphSONTokensTP2._LABEL);
- }
-
+ elementPropertyKeys.add(GraphSONTokens.LABEL);
+ }*/
return elementPropertyKeys;
}
- private static class MyElementFactory implements ElementFactory<Vertex, Edge> {
+ public static class MyElementFactory implements ElementFactory<Vertex, Edge> {
@Override
public Edge createEdge(final Object id, final Vertex out, final Vertex in, final String label) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/456f844e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
index b032a85..f10d040 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
@@ -26,10 +26,9 @@ import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.GraphSONMode;
+import org.codehaus.jettison.json.JSONException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import java.io.*;
import java.util.*;
/**
@@ -135,26 +134,19 @@ public class GraphSONLegacyWriter {
private void outputAdjListGraph(final OutputStream jsonOutputStream, final Set<String> vertexPropertyKeys,
final Set<String> edgePropertyKeys, final GraphSONMode mode, final boolean normalize) throws IOException {
-
- final JsonGenerator jg = jsonFactory.createGenerator(jsonOutputStream);
-
- // don't let the JsonGenerator close the underlying stream...leave that to the client passing in the stream
- jg.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
-
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, null,
- ElementPropertyConfig.includeProperties(vertexPropertyKeys, edgePropertyKeys, normalize));
-
- //jg.writeStartObject();
-
+ final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(jsonOutputStream));
final Iterable<Vertex> vertices = vertices(normalize);
for (Vertex v : vertices) {
- jg.writeTree(graphson.objectNodeFromElement(v));
+ try {
+ FaunusGraphSONUtility.toJSON(v).write(writer);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ throw new IOException(e);
+ }
+ writer.newLine();
}
-
- //jg.writeEndObject();
-
- jg.flush();
- jg.close();
+ writer.flush();
+ writer.close();
}
public void outputGraph(final OutputStream jsonOutputStream, final Set<String> vertexPropertyKeys,
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/456f844e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
index e331f1c..33be1d0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
@@ -273,13 +273,13 @@ public class TP2GraphSONUtility {
final ObjectNode jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig, normalized), propertyKeys, showTypes);
- if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) {
- putObject(jsonElement, GraphSONTokensTP2._ID, element.id());
- }
+ //if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) {
+ // putObject(jsonElement, GraphSONTokensTP2._ID, element.id());
+ //}
// it's important to keep the order of these straight. check Edge first and then Vertex because there
// are graph implementations that have Edge extend from Vertex
- if (element instanceof Edge) {
+ if (isEdge) { //element instanceof Edge) {
final Edge edge = (Edge) element;
if (this.includeReservedEdgeId) {
@@ -439,8 +439,9 @@ public class TP2GraphSONUtility {
*/
public static JSONObject jsonFromElement(final Element element, final Set<String> propertyKeys,
final GraphSONMode mode) throws JSONException {
- final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, null, null, propertyKeys)
- : new TP2GraphSONUtility(mode, null, propertyKeys, null);
+ ElementFactory factory = new FaunusGraphSONUtility.MyElementFactory();
+ final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propertyKeys)
+ : new TP2GraphSONUtility(mode, factory, propertyKeys, null);
return graphson.jsonFromElement(element);
}
@@ -452,15 +453,17 @@ public class TP2GraphSONUtility {
* @param mode The type of GraphSON to generate.
*/
public static ObjectNode objectNodeFromElement(final Element element, final Set<String> propertyKeys, final GraphSONMode mode) {
- final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, null, null, propertyKeys)
- : new TP2GraphSONUtility(mode, null, propertyKeys, null);
+ ElementFactory factory = new FaunusGraphSONUtility.MyElementFactory();
+ final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propertyKeys)
+ : new TP2GraphSONUtility(mode, factory, propertyKeys, null);
return graphson.objectNodeFromElement(element);
}
private static ObjectNode objectNodeFromElement(final Element element, final List<String> propertyKeys, final GraphSONMode mode) {
+ ElementFactory factory = new FaunusGraphSONUtility.MyElementFactory();
Set<String> propKeySet = (propertyKeys!=null)? new HashSet<String>(propertyKeys) : null;
- final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, null, null, propKeySet)
- : new TP2GraphSONUtility(mode, null, propKeySet, null);
+ final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propKeySet)
+ : new TP2GraphSONUtility(mode, factory, propKeySet, null);
return graphson.objectNodeFromElement(element);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/456f844e/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONLegacyRecordReaderTest.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONLegacyRecordReaderTest.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONLegacyRecordReaderTest.java
index 618c414..4a1926e 100644
--- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONLegacyRecordReaderTest.java
+++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/graphson/GraphSONLegacyRecordReaderTest.java
@@ -32,7 +32,7 @@ public class GraphSONLegacyRecordReaderTest extends RecordReaderWriterTest {
@Override
protected String getInputFilename() {
- return "grateful-dead-tp2.json";
+ return "tinkerpop2adj-classic.json";
}
@Override