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 2016/08/23 18:12:27 UTC
[1/3] tinkerpop git commit: Turned on more IO tests for graphson 2.0
in test suite.
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1278 8e04a6529 -> e5801281f
Turned on more IO tests for graphson 2.0 in test suite.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f7b9b1a0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f7b9b1a0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f7b9b1a0
Branch: refs/heads/TINKERPOP-1278
Commit: f7b9b1a0218fb0555915abc2f3293c4806540169
Parents: e6f4cfd
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 13:35:38 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 13:35:38 2016 -0400
----------------------------------------------------------------------
.../io/graphson/AbstractObjectDeserializer.java | 4 +-
.../structure/io/graphson/GraphSONModule.java | 76 ++++++++++----------
.../structure/io/graphson/GraphSONReader.java | 50 ++++++++-----
.../io/graphson/GraphSONSerializersV2d0.java | 14 ++--
.../GraphSONTraversalSerializersV2d0.java | 2 +-
.../gremlin/structure/io/IoCustomTest.java | 19 +++--
.../gremlin/structure/io/IoEdgeTest.java | 13 +++-
.../gremlin/structure/io/IoPropertyTest.java | 13 +++-
.../tinkerpop/gremlin/structure/io/IoTest.java | 2 +-
.../gremlin/structure/io/IoVertexTest.java | 13 +++-
.../gremlin/structure/io/util/CustomId.java | 75 ++++++++++++++++++-
.../tinkergraph/TinkerGraphProvider.java | 30 +++++---
12 files changed, 222 insertions(+), 89 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
index 5087113..bd7f4b6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractObjectDeserializer.java
@@ -31,7 +31,7 @@ import java.util.Map;
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-abstract class AbstractObjectDeserializer<T> extends StdDeserializer<T> {
+public abstract class AbstractObjectDeserializer<T> extends StdDeserializer<T> {
protected AbstractObjectDeserializer(final Class<T> clazz) {
super(clazz);
@@ -47,5 +47,5 @@ abstract class AbstractObjectDeserializer<T> extends StdDeserializer<T> {
return createObject(mapData);
}
- abstract T createObject(final Map<String, Object> data);
+ public abstract T createObject(final Map<String, Object> data);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index 21a48f3..e332834 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -40,6 +40,8 @@ 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.util.star.DirectionalStarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONDeserializer;
import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV1d0;
import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV2d0;
import org.apache.tinkerpop.gremlin.util.function.Lambda;
@@ -58,6 +60,7 @@ import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -82,42 +85,43 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
*/
static final class GraphSONModuleV2d0 extends GraphSONModule {
- private static final LinkedHashMap<Class, String> TYPE_DEFINITIONS = new LinkedHashMap<Class, String>() {{
- // Those don't have deserializers because handled by Jackson,
- // but we still want to rename them in GraphSON
- put(ByteBuffer.class, "bytebuffer");
- put(Short.class, "int16");
- put(Integer.class, "int32");
- put(Long.class, "int64");
- put(Double.class, "double");
- put(Float.class, "float");
-
- // Time serializers/deserializers
- put(Duration.class, "duration");
- put(Instant.class, "instant");
- put(LocalDate.class, "localdate");
- put(LocalDateTime.class, "localdatetime");
- put(LocalTime.class, "localtime");
- put(MonthDay.class, "monthday");
- put(OffsetDateTime.class, "offsetdatetime");
- put(OffsetTime.class, "offsettime");
- put(Period.class, "period");
- put(Year.class, "year");
- put(YearMonth.class, "yearmonth");
- put(ZonedDateTime.class, "zoneddatetime");
- put(ZoneOffset.class, "zoneoffset");
-
- // Tinkerpop Graph objects
- put(Vertex.class, "vertex");
- put(Edge.class, "edge");
- put(Property.class, "property");
- put(Path.class, "path");
- put(VertexProperty.class, "vertexproperty");
- put(Metrics.class, "metrics");
- put(TraversalMetrics.class, "traversalmetrics");
- put(Traverser.class, "traverser");
- put(Tree.class, "tree");
- }};
+ private static final Map<Class, String> TYPE_DEFINITIONS = Collections.unmodifiableMap(
+ new LinkedHashMap<Class, String>() {{
+ // Those don't have deserializers because handled by Jackson,
+ // but we still want to rename them in GraphSON
+ put(ByteBuffer.class, "bytebuffer");
+ put(Short.class, "int16");
+ put(Integer.class, "int32");
+ put(Long.class, "int64");
+ put(Double.class, "double");
+ put(Float.class, "float");
+
+ // Time serializers/deserializers
+ put(Duration.class, "duration");
+ put(Instant.class, "instant");
+ put(LocalDate.class, "localdate");
+ put(LocalDateTime.class, "localdatetime");
+ put(LocalTime.class, "localtime");
+ put(MonthDay.class, "monthday");
+ put(OffsetDateTime.class, "offsetdatetime");
+ put(OffsetTime.class, "offsettime");
+ put(Period.class, "period");
+ put(Year.class, "year");
+ put(YearMonth.class, "yearmonth");
+ put(ZonedDateTime.class, "zoneddatetime");
+ put(ZoneOffset.class, "zoneoffset");
+
+ // Tinkerpop Graph objects
+ put(Vertex.class, "vertex");
+ put(Edge.class, "edge");
+ put(Property.class, "property");
+ put(Path.class, "path");
+ put(VertexProperty.class, "vertexproperty");
+ put(Metrics.class, "metrics");
+ put(TraversalMetrics.class, "traversalmetrics");
+ put(Traverser.class, "traverser");
+ put(Tree.class, "tree");
+ }});
/**
* Constructs a new object.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/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 0b27c61..667aa86 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
@@ -71,6 +71,7 @@ import java.util.stream.Stream;
public final class GraphSONReader implements GraphReader {
private final ObjectMapper mapper;
private final long batchSize;
+ private final GraphSONVersion version;
private boolean unwrapAdjacencyList = false;
final TypeReference<Map<String, Object>> mapTypeReference = new TypeReference<Map<String, Object>>() {
@@ -80,6 +81,7 @@ public final class GraphSONReader implements GraphReader {
mapper = builder.mapper.createMapper();
batchSize = builder.batchSize;
unwrapAdjacencyList = builder.unwrapAdjacencyList;
+ version = ((GraphSONMapper)builder.mapper).getVersion();
}
/**
@@ -191,17 +193,21 @@ public final class GraphSONReader implements GraphReader {
*/
@Override
public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException {
- final Map<String, Object> edgeData = mapper.readValue(inputStream, mapTypeReference);
+ if (version == GraphSONVersion.V1_0) {
+ final Map<String, Object> edgeData = mapper.readValue(inputStream, mapTypeReference);
- final Map<String,Object> edgeProperties = edgeData.containsKey(GraphSONTokens.PROPERTIES) ?
- (Map<String, Object>) edgeData.get(GraphSONTokens.PROPERTIES) : Collections.EMPTY_MAP;
- final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokens.ID),
- edgeData.get(GraphSONTokens.LABEL).toString(),
- edgeProperties,
- Pair.with(edgeData.get(GraphSONTokens.OUT), edgeData.get(GraphSONTokens.OUT_LABEL).toString()),
- Pair.with(edgeData.get(GraphSONTokens.IN), edgeData.get(GraphSONTokens.IN_LABEL).toString()));
+ final Map<String, Object> edgeProperties = edgeData.containsKey(GraphSONTokens.PROPERTIES) ?
+ (Map<String, Object>) edgeData.get(GraphSONTokens.PROPERTIES) : Collections.EMPTY_MAP;
+ final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokens.ID),
+ edgeData.get(GraphSONTokens.LABEL).toString(),
+ edgeProperties,
+ 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 edgeAttachMethod.apply(edge);
+ return edgeAttachMethod.apply(edge);
+ } else {
+ return edgeAttachMethod.apply((DetachedEdge) mapper.readValue(inputStream, Edge.class));
+ }
}
/**
@@ -217,12 +223,16 @@ public final class GraphSONReader implements GraphReader {
@Override
public VertexProperty readVertexProperty(final InputStream inputStream,
final Function<Attachable<VertexProperty>, VertexProperty> vertexPropertyAttachMethod) throws IOException {
- final Map<String, Object> vpData = mapper.readValue(inputStream, mapTypeReference);
- final Map<String, Object> metaProperties = (Map<String, Object>) vpData.get(GraphSONTokens.PROPERTIES);
- final DetachedVertexProperty vp = new DetachedVertexProperty(vpData.get(GraphSONTokens.ID),
- vpData.get(GraphSONTokens.LABEL).toString(),
- vpData.get(GraphSONTokens.VALUE), metaProperties);
- return vertexPropertyAttachMethod.apply(vp);
+ if (version == GraphSONVersion.V1_0) {
+ final Map<String, Object> vpData = mapper.readValue(inputStream, mapTypeReference);
+ final Map<String, Object> metaProperties = (Map<String, Object>) vpData.get(GraphSONTokens.PROPERTIES);
+ final DetachedVertexProperty vp = new DetachedVertexProperty(vpData.get(GraphSONTokens.ID),
+ vpData.get(GraphSONTokens.LABEL).toString(),
+ vpData.get(GraphSONTokens.VALUE), metaProperties);
+ return vertexPropertyAttachMethod.apply(vp);
+ } else {
+ return vertexPropertyAttachMethod.apply((DetachedVertexProperty) mapper.readValue(inputStream, VertexProperty.class));
+ }
}
/**
@@ -236,9 +246,13 @@ public final class GraphSONReader implements GraphReader {
@Override
public Property readProperty(final InputStream inputStream,
final Function<Attachable<Property>, Property> propertyAttachMethod) throws IOException {
- final Map<String, Object> propertyData = mapper.readValue(inputStream, mapTypeReference);
- final DetachedProperty p = new DetachedProperty(propertyData.get(GraphSONTokens.KEY).toString(), propertyData.get(GraphSONTokens.VALUE));
- return propertyAttachMethod.apply(p);
+ if (version == GraphSONVersion.V1_0) {
+ final Map<String, Object> propertyData = mapper.readValue(inputStream, mapTypeReference);
+ final DetachedProperty p = new DetachedProperty(propertyData.get(GraphSONTokens.KEY).toString(), propertyData.get(GraphSONTokens.VALUE));
+ return propertyAttachMethod.apply(p);
+ } else {
+ return propertyAttachMethod.apply((DetachedProperty) mapper.readValue(inputStream, Property.class));
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
index 4e522aa..31ca6a2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializersV2d0.java
@@ -424,7 +424,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- Vertex createObject(final Map<String, Object> vertexData) {
+ public Vertex createObject(final Map<String, Object> vertexData) {
return new DetachedVertex(
vertexData.get(GraphSONTokens.ID),
vertexData.get(GraphSONTokens.LABEL).toString(),
@@ -440,7 +440,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- Edge createObject(final Map<String, Object> edgeData) {
+ public Edge createObject(final Map<String, Object> edgeData) {
return new DetachedEdge(
edgeData.get(GraphSONTokens.ID),
edgeData.get(GraphSONTokens.LABEL).toString(),
@@ -458,7 +458,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- Property createObject(final Map<String, Object> propData) {
+ public Property createObject(final Map<String, Object> propData) {
return new DetachedProperty(
(String) propData.get(GraphSONTokens.KEY),
propData.get(GraphSONTokens.VALUE));
@@ -472,7 +472,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- Path createObject(final Map<String, Object> pathData) {
+ public Path createObject(final Map<String, Object> pathData) {
final Path p = MutablePath.make();
final List labels = (List) pathData.get(GraphSONTokens.LABELS);
@@ -492,7 +492,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- VertexProperty createObject(final Map<String, Object> propData) {
+ public VertexProperty createObject(final Map<String, Object> propData) {
return new DetachedVertexProperty(
propData.get(GraphSONTokens.ID),
(String) propData.get(GraphSONTokens.LABEL),
@@ -508,7 +508,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- Metrics createObject(final Map<String, Object> metricsData) {
+ public Metrics createObject(final Map<String, Object> metricsData) {
final MutableMetrics m = new MutableMetrics((String)metricsData.get(GraphSONTokens.ID), (String)metricsData.get(GraphSONTokens.NAME));
m.setDuration(Math.round((Double) metricsData.get(GraphSONTokens.DURATION) * 1000000), TimeUnit.NANOSECONDS);
@@ -532,7 +532,7 @@ class GraphSONSerializersV2d0 {
}
@Override
- TraversalMetrics createObject(final Map<String, Object> traversalMetricsData) {
+ public TraversalMetrics createObject(final Map<String, Object> traversalMetricsData) {
return new DefaultTraversalMetrics(
Math.round((Double) traversalMetricsData.get(GraphSONTokens.DURATION) * 1000000),
(List<MutableMetrics>) traversalMetricsData.get(GraphSONTokens.METRICS)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
index d768d8e..080f64d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
@@ -403,7 +403,7 @@ final class GraphSONTraversalSerializersV2d0 {
}
@Override
- Traverser createObject(final Map<String, Object> data) {
+ public Traverser createObject(final Map<String, Object> data) {
return new DefaultRemoteTraverser<>(data.get(GraphSONTokens.VALUE), (Long) data.get(GraphSONTokens.BULK));
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
index 699cb11..d89f97e 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCustomTest.java
@@ -25,6 +25,9 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
import org.apache.tinkerpop.gremlin.structure.io.util.CustomId;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule;
@@ -52,13 +55,18 @@ public class IoCustomTest extends AbstractGremlinTest {
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
- final SimpleModule module = new SimpleModule();
- module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializer());
+ final SimpleModule moduleV1d0 = new SimpleModule();
+ moduleV1d0.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializerV1d0());
+
+ final SimpleModule moduleV2d0 = new CustomId.CustomIdTinkerPopJacksonModule();
return Arrays.asList(new Object[][]{
- {"graphson-embedded", true,
- (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().addCustomModule(module).embedTypes(true).create()).create(),
- (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().addCustomModule(module).embedTypes(true).create()).create()},
+ {"graphson-v1-embedded", true,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().addCustomModule(moduleV1d0).embedTypes(true).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().addCustomModule(moduleV1d0).embedTypes(true).create()).create()},
+ {"graphson-v2-embedded", true,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().addCustomModule(moduleV2d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().addCustomModule(moduleV2d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
{"gryo", true,
(Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().mapper(g.io(IoCore.gryo()).mapper().addCustom(CustomId.class).create()).create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().mapper(g.io(IoCore.gryo()).mapper().addCustom(CustomId.class).create()).create()}
@@ -77,7 +85,6 @@ public class IoCustomTest extends AbstractGremlinTest {
@Parameterized.Parameter(value = 3)
public Function<Graph, GraphWriter> writerMaker;
-
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
index e8db127..8d2a58a 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoEdgeTest.java
@@ -24,6 +24,9 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.junit.Test;
@@ -51,12 +54,18 @@ public class IoEdgeTest extends AbstractGremlinTest {
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
- {"graphson", false, false,
+ {"graphson-v1", false, false,
(Function<Graph,GraphReader>) g -> g.io(IoCore.graphson()).reader().create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().create()},
- {"graphson-embedded", true, true,
+ {"graphson-v1-embedded", true, true,
(Function<Graph,GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create()},
+ {"graphson-v2", false, false,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
+ {"graphson-v2-embedded", true, true,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
{"gryo", true, true,
(Function<Graph,GraphReader>) g -> g.io(IoCore.gryo()).reader().create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().create()}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
index 4077f23..3a3d6f0 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoPropertyTest.java
@@ -23,6 +23,9 @@ import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,12 +49,18 @@ public class IoPropertyTest extends AbstractGremlinTest {
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
- {"graphson", false, false,
+ {"graphson-v1", false, false,
(Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().create()},
- {"graphson-embedded", true, true,
+ {"graphson-v1-embedded", true, true,
(Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create()},
+ {"graphson-v2", false, false,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
+ {"graphson-v2-embedded", true, true,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
{"gryo", true, true,
(Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().create()}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
index 5a624f4..6d21c2b 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
@@ -384,7 +384,7 @@ public class IoTest {
graph.addVertex(T.id, new CustomId("vertex", id));
final SimpleModule module = new SimpleModule();
- module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializer());
+ module.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializerV1d0());
final GraphWriter writer = graph.io(graphson).writer().mapper(
graph.io(graphson).mapper().addCustomModule(module).embedTypes(true).create()).create();
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
index d457bc5..6e692c4 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoVertexTest.java
@@ -29,6 +29,9 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
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.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
import org.apache.tinkerpop.gremlin.structure.io.gryo.VertexByteArrayInputStream;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -68,12 +71,18 @@ public class IoVertexTest extends AbstractGremlinTest {
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
- {"graphson", false, false,
+ {"graphson-v1", false, false,
(Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().create()},
- {"graphson-embedded", true, false,
+ {"graphson-v1-embedded", true, false,
(Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(IoCore.graphson()).mapper().embedTypes(true).create()).create()},
+ {"graphson-v2", false, false,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
+ {"graphson-v2-embedded", true, false,
+ (Function<Graph, GraphReader>) g -> g.io(IoCore.graphson()).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
+ (Function<Graph, GraphWriter>) g -> g.io(IoCore.graphson()).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
{"gryo", true, true,
(Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().create(),
(Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().create()}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
index 05752a6..2277247 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/CustomId.java
@@ -18,7 +18,9 @@
*/
package org.apache.tinkerpop.gremlin.structure.io.util;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.AbstractObjectDeserializer;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TinkerPopJacksonModule;
import org.apache.tinkerpop.shaded.jackson.core.JsonGenerationException;
import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException;
@@ -27,6 +29,10 @@ import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeSerializer;
import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.UUID;
/**
@@ -60,8 +66,8 @@ public class CustomId {
return cluster + ":" + elementId;
}
- public static class CustomIdJacksonSerializer extends StdSerializer<CustomId> {
- public CustomIdJacksonSerializer() {
+ public static class CustomIdJacksonSerializerV1d0 extends StdSerializer<CustomId> {
+ public CustomIdJacksonSerializerV1d0() {
super(CustomId.class);
}
@@ -88,4 +94,69 @@ public class CustomId {
jsonGenerator.writeEndObject();
}
}
+
+ public static class CustomIdJacksonSerializerV2d0 extends StdSerializer<CustomId> {
+ public CustomIdJacksonSerializerV2d0() {
+ super(CustomId.class);
+ }
+
+ @Override
+ public void serialize(final CustomId customId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException, JsonGenerationException {
+ // when types are not embedded, stringify or resort to JSON primitive representations of the
+ // type so that non-jvm languages can better interoperate with the TinkerPop stack.
+ jsonGenerator.writeString(customId.toString());
+ }
+
+ @Override
+ public void serializeWithType(final CustomId customId, final JsonGenerator jsonGenerator,
+ final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException, JsonProcessingException {
+ // when the type is included add "class" as a key and then try to utilize as much of the
+ // default serialization provided by jackson data-bind as possible. for example, write
+ // the uuid as an object so that when jackson serializes it, it uses the uuid serializer
+ // to write it out with the type. in this way, data-bind should be able to deserialize
+ // it back when types are embedded.
+ typeSerializer.writeTypePrefixForScalar(customId, jsonGenerator);
+ final Map<String, Object> m = new HashMap<>();
+ m.put("cluster", customId.getCluster());
+ m.put("elementId", customId.getElementId());
+ jsonGenerator.writeObject(m);
+ typeSerializer.writeTypeSuffixForScalar(customId, jsonGenerator);
+ }
+ }
+
+ public static class CustomIdJacksonDeserializerV2d0 extends AbstractObjectDeserializer<CustomId> {
+ public CustomIdJacksonDeserializerV2d0() {
+ super(CustomId.class);
+ }
+
+ @Override
+ public CustomId createObject(final Map data) {
+ return new CustomId((String) data.get("cluster"), (UUID) data.get("elementId"));
+ }
+ }
+
+ public static class CustomIdTinkerPopJacksonModule extends TinkerPopJacksonModule {
+
+ private static final Map<Class, String> TYPE_DEFINITIONS = Collections.unmodifiableMap(
+ new LinkedHashMap<Class, String>() {{
+ put(CustomId.class, "id");
+ }});
+
+ public CustomIdTinkerPopJacksonModule() {
+ super("custom");
+ addSerializer(CustomId.class, new CustomIdJacksonSerializerV2d0());
+ addDeserializer(CustomId.class, new CustomIdJacksonDeserializerV2d0());
+ }
+
+ @Override
+ public Map<Class, String> getTypeDefinitions() {
+ return TYPE_DEFINITIONS;
+ }
+
+ @Override
+ public String getTypeNamespace() {
+ return "simple";
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7b9b1a0/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
index fcb5fe6..d6dd562 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
@@ -151,22 +151,32 @@ public class TinkerGraphProvider extends AbstractGraphProvider {
return TinkerGraph.DefaultIdManager.UUID;
} else if (test.equals(IoEdgeTest.class)) {
final Set<String> testsThatNeedLongIdManager = new HashSet<String>(){{
- add("shouldReadWriteEdge[graphson]");
- add("shouldReadWriteDetachedEdgeAsReference[graphson]");
- add("shouldReadWriteDetachedEdge[graphson]");
+ add("shouldReadWriteEdge[graphson-v1]");
+ add("shouldReadWriteDetachedEdgeAsReference[graphson-v1]");
+ add("shouldReadWriteDetachedEdge[graphson-v1]");
+ add("shouldReadWriteEdge[graphson-v2]");
+ add("shouldReadWriteDetachedEdgeAsReference[graphson-v2]");
+ add("shouldReadWriteDetachedEdge[graphson-v2]");
}};
if (testsThatNeedLongIdManager.contains(testMethodName))
return TinkerGraph.DefaultIdManager.LONG;
} else if (test.equals(IoVertexTest.class)) {
final Set<String> testsThatNeedLongIdManager = new HashSet<String>(){{
- add("shouldReadWriteVertexWithBOTHEdges[graphson]");
- add("shouldReadWriteVertexWithINEdges[graphson]");
- add("shouldReadWriteVertexWithOUTEdges[graphson]");
- add("shouldReadWriteVertexNoEdges[graphson]");
- add("shouldReadWriteDetachedVertexNoEdges[graphson]");
- add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson]");
- add("shouldReadWriteVertexMultiPropsNoEdges[graphson]");
+ add("shouldReadWriteVertexWithBOTHEdges[graphson-v1]");
+ add("shouldReadWriteVertexWithINEdges[graphson-v1]");
+ add("shouldReadWriteVertexWithOUTEdges[graphson-v1]");
+ add("shouldReadWriteVertexNoEdges[graphson-v1]");
+ add("shouldReadWriteDetachedVertexNoEdges[graphson-v1]");
+ add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson-v1]");
+ add("shouldReadWriteVertexMultiPropsNoEdges[graphson-v1]");
+ add("shouldReadWriteVertexWithBOTHEdges[graphson-v2]");
+ add("shouldReadWriteVertexWithINEdges[graphson-v2]");
+ add("shouldReadWriteVertexWithOUTEdges[graphson-v2]");
+ add("shouldReadWriteVertexNoEdges[graphson-v2]");
+ add("shouldReadWriteDetachedVertexNoEdges[graphson-v2]");
+ add("shouldReadWriteDetachedVertexAsReferenceNoEdges[graphson-v2]");
+ add("shouldReadWriteVertexMultiPropsNoEdges[graphson-v2]");
}};
if (testsThatNeedLongIdManager.contains(testMethodName))
[2/3] tinkerpop git commit: Merge remote-tracking branch
'origin/TINKERPOP-1278' into TINKERPOP-1278
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/TINKERPOP-1278' into TINKERPOP-1278
Conflicts:
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/41bb1f73
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/41bb1f73
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/41bb1f73
Branch: refs/heads/TINKERPOP-1278
Commit: 41bb1f73bf08704bb10ad50f7e26e6ef830be80c
Parents: f7b9b1a 1cdf2d9
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 14:01:19 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 14:01:19 2016 -0400
----------------------------------------------------------------------
.../structure/io/graphson/GraphSONModule.java | 59 +++--
.../structure/io/graphson/GraphSONTokens.java | 12 +-
.../GraphSONTraversalSerializersV2d0.java | 245 +++++++------------
.../process/traversal/step/filter/IsTest.java | 4 +-
.../io/graphson/GraphSONTranslator.java | 6 +-
5 files changed, 143 insertions(+), 183 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41bb1f73/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index e332834,0265cd2..b7678fc
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@@ -60,9 -60,9 +62,10 @@@ import java.time.Year
import java.time.YearMonth;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
+ import java.util.stream.Stream;
/**
* The set of serializers that handle the core graph interfaces. These serializers support normalization which
@@@ -85,43 -85,57 +88,58 @@@ abstract class GraphSONModule extends T
*/
static final class GraphSONModuleV2d0 extends GraphSONModule {
- private static final LinkedHashMap<Class, String> TYPE_DEFINITIONS = new LinkedHashMap<Class, String>() {{
- // Those don't have deserializers because handled by Jackson,
- // but we still want to rename them in GraphSON
- put(ByteBuffer.class, "bytebuffer");
- put(Short.class, "int16");
- put(Integer.class, "int32");
- put(Long.class, "int64");
- put(Double.class, "double");
- put(Float.class, "float");
+ private static final Map<Class, String> TYPE_DEFINITIONS = Collections.unmodifiableMap(
+ new LinkedHashMap<Class, String>() {{
+ // Those don't have deserializers because handled by Jackson,
+ // but we still want to rename them in GraphSON
+ put(ByteBuffer.class, "bytebuffer");
+ put(Short.class, "int16");
+ put(Integer.class, "int32");
+ put(Long.class, "int64");
+ put(Double.class, "double");
+ put(Float.class, "float");
- // Time serializers/deserializers
- put(Duration.class, "duration");
- put(Instant.class, "instant");
- put(LocalDate.class, "localdate");
- put(LocalDateTime.class, "localdatetime");
- put(LocalTime.class, "localtime");
- put(MonthDay.class, "monthday");
- put(OffsetDateTime.class, "offsetdatetime");
- put(OffsetTime.class, "offsettime");
- put(Period.class, "period");
- put(Year.class, "year");
- put(YearMonth.class, "yearmonth");
- put(ZonedDateTime.class, "zoneddatetime");
- put(ZoneOffset.class, "zoneoffset");
+ // Time serializers/deserializers
+ put(Duration.class, "duration");
+ put(Instant.class, "instant");
+ put(LocalDate.class, "localdate");
+ put(LocalDateTime.class, "localdatetime");
+ put(LocalTime.class, "localtime");
+ put(MonthDay.class, "monthday");
+ put(OffsetDateTime.class, "offsetdatetime");
+ put(OffsetTime.class, "offsettime");
+ put(Period.class, "period");
+ put(Year.class, "year");
+ put(YearMonth.class, "yearmonth");
+ put(ZonedDateTime.class, "zoneddatetime");
+ put(ZoneOffset.class, "zoneoffset");
- // Tinkerpop Graph objects
- put(Vertex.class, "vertex");
- put(Edge.class, "edge");
- put(Property.class, "property");
- put(Path.class, "path");
- put(VertexProperty.class, "vertexproperty");
- put(Metrics.class, "metrics");
- put(TraversalMetrics.class, "traversalmetrics");
- put(Traverser.class, "traverser");
- put(Tree.class, "tree");
- put(Bytecode.class, "bytecode");
- put(Bytecode.Binding.class, "binding");
- put(AndP.class, "P");
- put(OrP.class, "P");
- put(P.class, "P");
- Stream.of(
- VertexProperty.Cardinality.values(),
- Column.values(),
- Direction.values(),
- //Operator.values(),
- Order.values(),
- Pop.values(),
- SackFunctions.Barrier.values(),
- Scope.values(),
- T.values()).flatMap(Stream::of).forEach(e -> put(e.getClass(), e.getDeclaringClass().getSimpleName()));
- }};
+ // Tinkerpop Graph objects
+ put(Vertex.class, "vertex");
+ put(Edge.class, "edge");
+ put(Property.class, "property");
+ put(Path.class, "path");
+ put(VertexProperty.class, "vertexproperty");
+ put(Metrics.class, "metrics");
+ put(TraversalMetrics.class, "traversalmetrics");
+ put(Traverser.class, "traverser");
+ put(Tree.class, "tree");
++ put(Bytecode.class, "bytecode");
++ put(Bytecode.Binding.class, "binding");
++ put(AndP.class, "P");
++ put(OrP.class, "P");
++ put(P.class, "P");
++ Stream.of(
++ VertexProperty.Cardinality.values(),
++ Column.values(),
++ Direction.values(),
++ //Operator.values(),
++ Order.values(),
++ Pop.values(),
++ SackFunctions.Barrier.values(),
++ Scope.values(),
++ T.values()).flatMap(Stream::of).forEach(e -> put(e.getClass(), e.getDeclaringClass().getSimpleName()));
+ }});
/**
* Constructs a new object.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41bb1f73/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
index 080f64d,89f4662..a9c1731
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
@@@ -220,67 -220,19 +220,19 @@@ final class GraphSONTraversalSerializer
super(Bytecode.class);
}
- private static void processInstruction(final JsonNode instruction, final ObjectCodec oc, final Bytecode bytecode, final boolean source) throws IOException {
- final String operator = instruction.get(0).textValue();
- final List<Object> arguments = new ArrayList<>();
- for (int j = 1; j < instruction.size(); j++) {
- final JsonNode argument = instruction.get(j);
- if (argument.getNodeType().equals(JsonNodeType.OBJECT)) {
- if (argument.has(GraphSONTokens.VALUETYPE)) {
- final String type = argument.get(GraphSONTokens.VALUETYPE).textValue();
- if (type.equals("Bytecode"))
- arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class));
- else if (type.equals("Binding"))
- arguments.add(oc.readValue(argument.traverse(oc), Bytecode.Binding.class));
- else if (type.equals("P"))
- arguments.add(oc.readValue(argument.traverse(oc), P.class));
- else if (type.equals("Lambda"))
- arguments.add(oc.readValue(argument.traverse(oc), Lambda.class));
- else
- arguments.add(oc.readValue(argument.traverse(oc), Enum.class));
- } else {
- arguments.add(oc.readValue(argument.traverse(oc), Object.class)); // TODO: vertices/edges/etc. don't get processed correctly
- }
- } else if (argument.getNodeType().equals(JsonNodeType.NUMBER)) {
- arguments.add(argument.asInt()); // TODO
- } else if (argument.getNodeType().equals(JsonNodeType.STRING)) {
- arguments.add(argument.textValue());
- } else if (argument.getNodeType().equals(JsonNodeType.BOOLEAN)) {
- arguments.add(argument.booleanValue());
- } else if (argument.getNodeType().equals(JsonNodeType.ARRAY)) {
- final List<Object> list = new ArrayList<>();
- for (int k = 0; k < argument.size(); k++) {
- list.add(oc.readValue(argument.get(k).traverse(oc), Object.class));
- //list.add(argument.get(k).textValue());
- }
- arguments.add(list);
- } else {
- throw new IOException("Unknown argument: " + argument);
- }
- }
- if (source)
- bytecode.addSource(operator, arguments.toArray());
- else
- bytecode.addStep(operator, arguments.toArray());
- }
-
@Override
- public Bytecode deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
- Bytecode createObject(final Map<String, Object> data) {
++ public Bytecode createObject(final Map<String, Object> data) {
final Bytecode bytecode = new Bytecode();
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Bytecode");
- if (node.has("source")) {
- final JsonNode source = node.get("source");
- for (int i = 0; i < source.size(); i++) {
- processInstruction(source.get(i), oc, bytecode, true);
+ if (data.containsKey(GraphSONTokens.SOURCE)) {
+ final List<List<Object>> instructions = (List) data.get(GraphSONTokens.SOURCE);
+ for (final List<Object> instruction : instructions) {
+ bytecode.addSource((String) instruction.get(0), Arrays.copyOfRange(instruction.toArray(), 1, instruction.size()));
}
}
- if (node.has("step")) {
- final JsonNode step = node.get("step");
- for (int i = 0; i < step.size(); i++) {
- processInstruction(step.get(i), oc, bytecode, false);
-
+ if (data.containsKey(GraphSONTokens.STEP)) {
+ final List<List<Object>> instructions = (List) data.get(GraphSONTokens.STEP);
+ for (final List<Object> instruction : instructions) {
+ bytecode.addStep((String) instruction.get(0), Arrays.copyOfRange(instruction.toArray(), 1, instruction.size()));
}
}
return bytecode;
@@@ -330,24 -267,16 +267,16 @@@
}
@Override
- public P deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
-
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("P");
- final JsonNode predicate = node.get("predicate");
- if (predicate.textValue().equals("and") || predicate.textValue().equals("or")) {
- final List<P<?>> arguments = new ArrayList<>();
- for (int i = 0; i < node.get(GraphSONTokens.VALUE).size(); i++) {
- arguments.add(oc.readValue(node.get(GraphSONTokens.VALUE).get(i).traverse(oc), P.class));
- }
- return predicate.textValue().equals("and") ? new AndP(arguments) : new OrP(arguments);
- P createObject(final Map<String, Object> data) {
++ public P createObject(final Map<String, Object> data) {
+ final String predicate = (String) data.get(GraphSONTokens.PREDICATE);
+ final Object value = data.get(GraphSONTokens.VALUE);
+ if (predicate.equals(GraphSONTokens.AND) || predicate.equals(GraphSONTokens.OR)) {
+ return predicate.equals(GraphSONTokens.AND) ? new AndP((List<P>) value) : new OrP((List<P>) value);
} else {
try {
- final Object argument = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc), Object.class);
- return (P) P.class.getMethod(predicate.textValue(), argument instanceof Collection ? Collection.class : Object.class).invoke(null, argument); // TODO: number stuff, eh?
+ return (P) P.class.getMethod(predicate, value instanceof Collection ? Collection.class : Object.class).invoke(null, value); // TODO: number stuff, eh?
} catch (final Exception e) {
- throw new IOException(e.getMessage(), e);
+ throw new IllegalStateException(e.getMessage(), e);
}
}
}
@@@ -360,22 -289,19 +289,19 @@@
}
@Override
- public Lambda deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
-
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Lambda");
- final String lambdaScript = node.get(GraphSONTokens.VALUE).textValue();
- final String lambdaLanguage = node.get("language").textValue();
- final int lambdaArguments = node.get("arguments").intValue();
- if (-1 == lambdaArguments || lambdaArguments > 2)
- return new Lambda.UnknownArgLambda(lambdaScript, lambdaLanguage, lambdaArguments);
- else if (0 == lambdaArguments)
- return new Lambda.ZeroArgLambda<>(lambdaScript, lambdaLanguage);
- else if (1 == lambdaArguments)
- return new Lambda.OneArgLambda<>(lambdaScript, lambdaLanguage);
- Lambda createObject(final Map<String, Object> data) {
++ public Lambda createObject(final Map<String, Object> data) {
+ final String script = (String) data.get(GraphSONTokens.SCRIPT);
+ final String language = (String) data.get(GraphSONTokens.LANGUAGE);
+ final int arguments = ((Number) data.getOrDefault(GraphSONTokens.ARGUMENTS, -1)).intValue();
+ //
+ if (-1 == arguments || arguments > 2)
+ return new Lambda.UnknownArgLambda(script, language, arguments);
+ else if (0 == arguments)
+ return new Lambda.ZeroArgLambda<>(script, language);
+ else if (1 == arguments)
+ return new Lambda.OneArgLambda<>(script, language);
else
- return new Lambda.TwoArgLambda<>(lambdaScript, lambdaLanguage);
+ return new Lambda.TwoArgLambda<>(script, language);
}
}
@@@ -386,13 -312,8 +312,8 @@@
}
@Override
- public Bytecode.Binding deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
- final ObjectCodec oc = jsonParser.getCodec();
- final JsonNode node = oc.readTree(jsonParser);
- assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Binding");
- final String variable = node.get("variable").textValue();
- final Object value = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc), Object.class);
- return new Bytecode.Binding<>(variable, value);
- Bytecode.Binding createObject(final Map<String, Object> data) {
++ public Bytecode.Binding createObject(final Map<String, Object> data) {
+ return new Bytecode.Binding<>((String) data.get(GraphSONTokens.KEY), data.get(GraphSONTokens.VALUE));
}
}
[3/3] tinkerpop git commit: Merge remote-tracking branch
'origin/TINKERPOP-1278' into TINKERPOP-1278
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/TINKERPOP-1278' into TINKERPOP-1278
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e5801281
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e5801281
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e5801281
Branch: refs/heads/TINKERPOP-1278
Commit: e5801281f78d3bf773e528a1444064deeee53a55
Parents: 41bb1f7 8e04a65
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 14:01:32 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 14:01:32 2016 -0400
----------------------------------------------------------------------
.../structure/io/gryo/GryoSerializers.java | 3 ++-
.../python/TraversalSourceGenerator.groovy | 12 ++++-----
.../jython/gremlin_python/process/graphson.py | 28 +++++++++++---------
.../jython/gremlin_python/process/traversal.py | 10 +++----
.../jsr223/PythonGraphSONJavaTranslator.java | 5 +++-
5 files changed, 30 insertions(+), 28 deletions(-)
----------------------------------------------------------------------