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/08 18:53:56 UTC
[2/5] incubator-tinkerpop git commit: StarGraph working with
SparkGraphComputer --- need to test multi-machine and optimize and I think we
have it.
StarGraph working with SparkGraphComputer --- need to test multi-machine and optimize and I think we have it.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/1478e778
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/1478e778
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/1478e778
Branch: refs/heads/master
Commit: 1478e778d2ffc0de1791323dcb8f7e8473bf75b2
Parents: d0d5781
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Apr 7 15:31:27 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Apr 7 15:31:27 2015 -0600
----------------------------------------------------------------------
.../computer/util/star/StarAdjacentVertex.java | 6 ++++
.../process/computer/util/star/StarEdge.java | 16 ++++++++++
.../process/computer/util/star/StarElement.java | 1 +
.../process/computer/util/star/StarGraph.java | 32 ++++++++++++--------
.../process/computer/util/star/StarVertex.java | 8 ++++-
.../computer/util/star/StarVertexProperty.java | 3 +-
.../tinkergraph/structure/TinkerGraphTest.java | 10 +++---
7 files changed, 57 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1478e778/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarAdjacentVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarAdjacentVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarAdjacentVertex.java
index 6716762..61228f0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarAdjacentVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarAdjacentVertex.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import java.util.Collections;
@@ -95,4 +96,9 @@ public abstract class StarAdjacentVertex implements Vertex {
public int hashCode() {
return ElementHelper.hashCode(this);
}
+
+ @Override
+ public String toString() {
+ return StringFactory.vertexString(this);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1478e778/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarEdge.java
index 28fa36d..7244610 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarEdge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarEdge.java
@@ -24,6 +24,7 @@ package org.apache.tinkerpop.gremlin.process.computer.util.star;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.Collections;
import java.util.HashMap;
@@ -64,4 +65,19 @@ public abstract class StarEdge extends StarElement implements Edge {
public void remove() {
//TODO: throw Edge.Exceptions.edgeRemovalNotSupported();
}
+
+ @Override
+ public boolean equals(final Object other) {
+ return ElementHelper.areEqual(this, other);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode(this);
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.edgeString(this);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1478e778/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarElement.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarElement.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarElement.java
index 2904c92..8456ad3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarElement.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarElement.java
@@ -24,6 +24,7 @@ package org.apache.tinkerpop.gremlin.process.computer.util.star;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
/**
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1478e778/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarGraph.java
index 7482290..13c6a81 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarGraph.java
@@ -33,7 +33,6 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import java.util.Collections;
import java.util.Iterator;
@@ -67,15 +66,22 @@ public class StarGraph implements Graph {
@Override
public Iterator<Vertex> vertices(final Object... vertexIds) {
+ System.out.println(this.starVertex.outEdges);
return null == this.starVertex ?
Collections.emptyIterator() :
Stream.concat(
Stream.of(this.starVertex),
- this.starVertex.outEdges.values()
- .stream()
- .flatMap(List::stream)
- .map(Edge::inVertex))
- .filter(vertex -> ElementHelper.idExists(vertex.id(), vertexIds)).iterator();
+ Stream.concat(
+ this.starVertex.outEdges.values()
+ .stream()
+ .flatMap(List::stream)
+ .map(Edge::inVertex),
+ this.starVertex.inEdges.values()
+ .stream()
+ .flatMap(List::stream)
+ .map(Edge::outVertex)))
+ .filter(vertex -> ElementHelper.idExists(vertex.id(), vertexIds))
+ .iterator();
}
@Override
@@ -129,20 +135,20 @@ public class StarGraph implements Graph {
}
public static Edge addTo(final StarGraph graph, final DetachedEdge edge) {
- final Object id = edge.inVertex().id();
- if(graph.starVertex.id().equals(id)) {
- final Edge outEdge = graph.starVertex.addEdge(edge.label(),new StarInVertex(edge.inVertex().id(),graph.starVertex),new Object[]{T.id,edge.id()});
- edge.properties().forEachRemaining(property -> outEdge.property(property.key(),property.value()));
+ final Object id = edge.inVertex().id();
+ if (!graph.starVertex.id().equals(id)) {
+ final Edge outEdge = graph.starVertex.addEdge(edge.label(), new StarInVertex(edge.inVertex().id(), graph.starVertex), new Object[]{T.id, edge.id()});
+ edge.properties().forEachRemaining(property -> outEdge.property(property.key(), property.value()));
return outEdge;
} else {
- final Edge inEdge = new StarOutVertex(edge.outVertex().id(),graph.starVertex).addEdge(edge.label(),graph.starVertex,new Object[]{T.id,edge.id()});
- edge.properties().forEachRemaining(property -> inEdge.property(property.key(),property.value()));
+ final Edge inEdge = new StarOutVertex(edge.outVertex().id(), graph.starVertex).addEdge(edge.label(), graph.starVertex, new Object[]{T.id, edge.id()});
+ edge.properties().forEachRemaining(property -> inEdge.property(property.key(), property.value()));
return inEdge;
}
}
protected static Long randomId() {
- return new Random().nextLong();
+ return new Random().nextLong(); // TODO: you shouldn't need this!
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1478e778/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertex.java
index f883809..6b99ef2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertex.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.ArrayList;
import java.util.Collections;
@@ -66,7 +67,7 @@ public class StarVertex extends StarElement implements Vertex {
this.properties = new HashMap<>();
final List<VertexProperty<?>> list = cardinality.equals(VertexProperty.Cardinality.single) ? new ArrayList<>(1) : this.properties.getOrDefault(key, new ArrayList<>());
- final VertexProperty<V> vertexProperty = new StarVertexProperty<>(ElementHelper.getIdValue(keyValues).orElse(null), key, value, this);
+ final VertexProperty<V> vertexProperty = new StarVertexProperty<>(ElementHelper.getIdValue(keyValues).orElse(null), key, value, this, keyValues);
list.add(vertexProperty);
this.properties.put(key, list);
return vertexProperty;
@@ -122,6 +123,11 @@ public class StarVertex extends StarElement implements Vertex {
}
@Override
+ public String toString() {
+ return StringFactory.vertexString(this);
+ }
+
+ @Override
public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
return null == this.properties ?
Collections.emptyIterator() :
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1478e778/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertexProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertexProperty.java
index f06aeee..1e09803 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertexProperty.java
@@ -44,11 +44,12 @@ public class StarVertexProperty<V> implements VertexProperty<V> {
private Map<String, Object> properties = null;
private final StarVertex starVertex;
- public StarVertexProperty(final Object id, final String key, final V value, final StarVertex starVertex) {
+ public StarVertexProperty(final Object id, final String key, final V value, final StarVertex starVertex, final Object... keyValues) {
this.id = null == id ? StarGraph.randomId() : id;
this.key = key;
this.value = value;
this.starVertex = starVertex;
+ ElementHelper.attachProperties(this,keyValues);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1478e778/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index 59a0bf4..23933f6 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -37,6 +37,7 @@ import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
import org.apache.tinkerpop.gremlin.util.StreamFactory;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -142,10 +143,11 @@ public class TinkerGraphTest {
@Test
@Ignore
public void testPlay3() throws Exception {
- StarGraph graph = StarGraph.open();
- Vertex a = graph.addVertex(T.id,1,"name","marko");
- Vertex b = graph.addVertex(T.id,2,"firstname","stephen");
- graph.vertices().forEachRemaining(System.out::println);
+ TinkerGraph tg = TinkerFactory.createModern();
+ StarGraph sg = StarGraph.open();
+ tg.vertices().forEachRemaining(v -> StarGraph.addTo(sg, DetachedFactory.detach(v,true)));
+ tg.vertices(1).next().edges(Direction.BOTH).forEachRemaining(e -> StarGraph.addTo(sg,DetachedFactory.detach(e,true)));
+ sg.vertices().forEachRemaining(System.out::println);
}
@Test