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:55 UTC
[1/5] incubator-tinkerpop git commit: work on a 'micro' version of
TinkerGraph called StarGraph for reducing the on heap size of the star graph
for OLAP systems like SparkGraphComptuer and GiraphGraphComputer.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master a05e8e558 -> 97d2badaa
work on a 'micro' version of TinkerGraph called StarGraph for reducing the on heap size of the star graph for OLAP systems like SparkGraphComptuer and GiraphGraphComputer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d0d57813
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d0d57813
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d0d57813
Branch: refs/heads/master
Commit: d0d5781325187f33afe0855bf11edd0c44b94574
Parents: 21c304d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Apr 7 15:13:22 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Apr 7 15:13:22 2015 -0600
----------------------------------------------------------------------
.../computer/util/star/StarAdjacentVertex.java | 98 ++++++++++++
.../process/computer/util/star/StarEdge.java | 67 +++++++++
.../process/computer/util/star/StarElement.java | 66 +++++++++
.../process/computer/util/star/StarGraph.java | 148 +++++++++++++++++++
.../process/computer/util/star/StarInEdge.java | 64 ++++++++
.../computer/util/star/StarInVertex.java | 51 +++++++
.../process/computer/util/star/StarOutEdge.java | 63 ++++++++
.../computer/util/star/StarOutVertex.java | 51 +++++++
.../computer/util/star/StarProperty.java | 68 +++++++++
.../process/computer/util/star/StarVertex.java | 130 ++++++++++++++++
.../computer/util/star/StarVertexProperty.java | 111 ++++++++++++++
.../hadoop/structure/io/VertexWritable.java | 7 +-
.../io/graphson/GraphSONRecordReader.java | 7 +-
.../structure/io/gryo/GryoRecordReader.java | 7 +-
.../tinkergraph/structure/TinkerGraphTest.java | 13 +-
15 files changed, 934 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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
new file mode 100644
index 0000000..6716762
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarAdjacentVertex.java
@@ -0,0 +1,98 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+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.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class StarAdjacentVertex implements Vertex {
+
+ private final Object id;
+ protected final StarVertex starVertex;
+
+ protected StarAdjacentVertex(final Object id, final StarVertex starVertex) {
+ this.id = id;
+ this.starVertex = starVertex;
+ }
+
+ @Override
+ public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
+ throw Element.Exceptions.propertyAdditionNotSupported();
+ }
+
+ @Override
+ public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
+ return Collections.emptyIterator();
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
+ return Collections.emptyIterator();
+ }
+
+ @Override
+ public Object id() {
+ return this.id;
+ }
+
+ @Override
+ public String label() {
+ return Vertex.DEFAULT_LABEL;
+ }
+
+ @Override
+ public Graph graph() {
+ return EmptyGraph.instance();
+ }
+
+ @Override
+ public void remove() {
+ throw Vertex.Exceptions.vertexRemovalNotSupported();
+ }
+
+ @Override
+ public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
+ return Collections.emptyIterator();
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return ElementHelper.areEqual(this, other);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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
new file mode 100644
index 0000000..28fa36d
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarEdge.java
@@ -0,0 +1,67 @@
+/*
+ *
+ * * 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.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 java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class StarEdge extends StarElement implements Edge {
+
+ private Map<String, Object> properties = null;
+
+ public StarEdge(final Object id, final String label) {
+ super(id, label);
+ }
+
+ @Override
+ public <V> Property<V> property(final String key, final V value) {
+ if (null == this.properties)
+ this.properties = new HashMap<>();
+ this.properties.put(key, value);
+ return new StarProperty<>(key, value,this);
+ }
+
+ @Override
+ public <V> Iterator<Property<V>> properties(final String... propertyKeys) {
+ return null == this.properties ?
+ Collections.emptyIterator() :
+ (Iterator) this.properties.entrySet()
+ .stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
+ .map(entry -> new StarProperty<>(entry.getKey(), (V) entry.getValue(),this))
+ .iterator();
+ }
+
+ @Override
+ public void remove() {
+ //TODO: throw Edge.Exceptions.edgeRemovalNotSupported();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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
new file mode 100644
index 0000000..2904c92
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarElement.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * * 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.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.empty.EmptyGraph;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class StarElement implements Element {
+
+ private final Object id;
+ private final String label;
+
+ protected StarElement(final Object id, final String label) {
+ this.id = null == id ? StarGraph.randomId() : id;
+ this.label = label;
+ }
+
+ @Override
+ public Object id() {
+ return this.id;
+ }
+
+ @Override
+ public String label() {
+ return this.label;
+ }
+
+ @Override
+ public Graph graph() {
+ return EmptyGraph.instance();
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return ElementHelper.areEqual(this, other);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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
new file mode 100644
index 0000000..7482290
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarGraph.java
@@ -0,0 +1,148 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.T;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Transaction;
+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.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;
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Stream;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarGraph implements Graph {
+
+ private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration();
+
+ private StarVertex starVertex;
+
+ @Override
+ public Vertex addVertex(final Object... keyValues) {
+ throw Graph.Exceptions.vertexAdditionsNotSupported();
+ }
+
+ @Override
+ public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) throws IllegalArgumentException {
+ throw Graph.Exceptions.graphComputerNotSupported();
+ }
+
+ @Override
+ public GraphComputer compute() throws IllegalArgumentException {
+ throw Graph.Exceptions.graphComputerNotSupported();
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Object... vertexIds) {
+ 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();
+ }
+
+ @Override
+ public Iterator<Edge> edges(final Object... edgeIds) {
+ return null == this.starVertex ?
+ Collections.emptyIterator() :
+ Stream.concat(
+ this.starVertex.inEdges.values().stream(),
+ this.starVertex.outEdges.values().stream())
+ .flatMap(List::stream)
+ .filter(edge -> ElementHelper.idExists(edge.id(), edgeIds))
+ .iterator();
+ }
+
+ @Override
+ public Transaction tx() {
+ throw Graph.Exceptions.transactionsNotSupported();
+ }
+
+ @Override
+ public Variables variables() {
+ throw Graph.Exceptions.variablesNotSupported();
+ }
+
+ @Override
+ public Configuration configuration() {
+ return EMPTY_CONFIGURATION;
+ }
+
+ @Override
+ public void close() throws Exception {
+
+ }
+
+ public static StarGraph open() {
+ return new StarGraph();
+ }
+
+ public static Vertex addTo(final StarGraph graph, final DetachedVertex detachedVertex) {
+ if (null != graph.starVertex)
+ return null;
+
+ graph.starVertex = new StarVertex(detachedVertex.id(), detachedVertex.label());
+ detachedVertex.properties().forEachRemaining(detachedVertexProperty -> {
+ final VertexProperty<?> vertexProperty = graph.starVertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value());
+ detachedVertexProperty.properties().forEachRemaining(detachedVertexPropertyProperty -> {
+ vertexProperty.property(detachedVertexPropertyProperty.key(), detachedVertexPropertyProperty.value());
+ });
+ });
+ return graph.starVertex;
+ }
+
+ 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()));
+ 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()));
+ return inEdge;
+ }
+ }
+
+ protected static Long randomId() {
+ return new Random().nextLong();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
new file mode 100644
index 0000000..82da76e
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import java.util.Iterator;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarInEdge extends StarEdge {
+
+ private final StarOutVertex starOutVertex;
+ private final StarVertex starVertex;
+
+ public StarInEdge(final Object id, final StarOutVertex starOutVertex, final String label, final StarVertex starVertex) {
+ super(id, label);
+ this.starOutVertex = starOutVertex;
+ this.starVertex = starVertex;
+
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction) {
+ if (direction.equals(Direction.OUT))
+ return IteratorUtils.of(this.starOutVertex);
+ else if (direction.equals(Direction.IN))
+ return IteratorUtils.of(this.starVertex);
+ else
+ return IteratorUtils.of(this.starOutVertex, this.starVertex);
+ }
+
+ @Override
+ public Vertex outVertex() {
+ return this.starOutVertex;
+ }
+
+ @Override
+ public Vertex inVertex() {
+ return this.starVertex;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
new file mode 100644
index 0000000..cbdef7e
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarInVertex extends StarAdjacentVertex {
+
+ public StarInVertex(final Object id, final StarVertex starVertex) {
+ super(id, starVertex);
+ }
+
+ @Override
+ public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
+ List<Edge> outE = this.starVertex.outEdges.get(label);
+ if (null == outE) {
+ outE = new ArrayList<>();
+ this.starVertex.outEdges.put(label, outE);
+ }
+ final StarOutEdge outEdge = new StarOutEdge(ElementHelper.getIdValue(keyValues).orElse(null), (StarVertex) inVertex, label, this);
+ outE.add(outEdge);
+ return outEdge;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
new file mode 100644
index 0000000..4a1e795
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
@@ -0,0 +1,63 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import java.util.Iterator;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarOutEdge extends StarEdge {
+
+ private final StarVertex starVertex;
+ private final StarInVertex starInVertex;
+
+ public StarOutEdge(final Object id, final StarVertex starVertex, final String label, final StarInVertex starInVertex) {
+ super(id, label);
+ this.starVertex = starVertex;
+ this.starInVertex = starInVertex;
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction) {
+ if (direction.equals(Direction.OUT))
+ return IteratorUtils.of(this.starVertex);
+ else if (direction.equals(Direction.IN))
+ return IteratorUtils.of(this.starInVertex);
+ else
+ return IteratorUtils.of(this.starVertex, this.starInVertex);
+ }
+
+ @Override
+ public Vertex outVertex() {
+ return this.starVertex;
+ }
+
+ @Override
+ public Vertex inVertex() {
+ return this.starInVertex;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
new file mode 100644
index 0000000..82fdc3a
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarOutVertex extends StarAdjacentVertex {
+
+ public StarOutVertex(final Object id, final StarVertex starVertex) {
+ super(id, starVertex);
+ }
+
+ @Override
+ public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
+ List<Edge> inE = this.starVertex.inEdges.get(label);
+ if (null == inE) {
+ inE = new ArrayList<>();
+ this.starVertex.inEdges.put(label, inE);
+ }
+ final StarInEdge inEdge = new StarInEdge(ElementHelper.getIdValue(keyValues).orElse(null), this, label, (StarVertex) inVertex);
+ inE.add(inEdge);
+ return inEdge;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
new file mode 100644
index 0000000..407ed3e
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
@@ -0,0 +1,68 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+
+import java.util.NoSuchElementException;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarProperty<V> implements Property<V> {
+
+ private final String key;
+ private final V value;
+ private final Element element;
+
+ public StarProperty(final String key, final V value, final Element element) {
+ this.key = key;
+ this.value =value;
+ this.element = element;
+ }
+
+ @Override
+ public String key() {
+ return this.key;
+ }
+
+ @Override
+ public V value() throws NoSuchElementException {
+ return this.value;
+ }
+
+ @Override
+ public boolean isPresent() {
+ return true;
+ }
+
+ @Override
+ public Element element() {
+ return this.element;
+ }
+
+ @Override
+ public void remove() {
+ throw Element.Exceptions.propertyRemovalNotSupported();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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
new file mode 100644
index 0000000..f883809
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertex.java
@@ -0,0 +1,130 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarVertex extends StarElement implements Vertex {
+
+ protected Map<String, List<VertexProperty<?>>> properties = null;
+ protected Map<String, List<Edge>> outEdges = new HashMap<>();
+ protected Map<String, List<Edge>> inEdges = new HashMap<>();
+
+ public StarVertex(final Object id, final String label) {
+ super(id, label);
+ }
+
+ @Override
+ public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
+ List<Edge> outE = this.outEdges.get(label);
+ if (null == outE) {
+ outE = new ArrayList<>();
+ this.outEdges.put(label, outE);
+ }
+ final StarOutEdge outEdge = new StarOutEdge(ElementHelper.getIdValue(keyValues).orElse(null), this, label, (StarInVertex) inVertex);
+ outE.add(outEdge);
+ return outEdge;
+ }
+
+ @Override
+ public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, V value, final Object... keyValues) {
+ if (null == this.properties)
+ 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);
+ list.add(vertexProperty);
+ this.properties.put(key, list);
+ return vertexProperty;
+ }
+
+ @Override
+ public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
+ if (direction.equals(Direction.OUT)) {
+ return this.outEdges.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .iterator();
+ } else if (direction.equals(Direction.IN)) {
+ return this.inEdges.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .iterator();
+ } else {
+ return Stream.concat(this.inEdges.entrySet().stream(), this.outEdges.entrySet().stream())
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .iterator();
+ }
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
+ if (direction.equals(Direction.OUT)) {
+ return this.outEdges.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .map(Edge::inVertex)
+ .iterator();
+ } else if (direction.equals(Direction.IN)) {
+ return this.inEdges.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .map(Edge::outVertex)
+ .iterator();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void remove() {
+
+ }
+
+ @Override
+ public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
+ return null == this.properties ?
+ Collections.emptyIterator() :
+ (Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).flatMap(entry -> entry.getValue().stream()).iterator();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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
new file mode 100644
index 0000000..f06aeee
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertexProperty.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * * 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.process.computer.util.star;
+
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class StarVertexProperty<V> implements VertexProperty<V> {
+
+ private final Object id;
+ private final String key;
+ private final V value;
+ private Map<String, Object> properties = null;
+ private final StarVertex starVertex;
+
+ public StarVertexProperty(final Object id, final String key, final V value, final StarVertex starVertex) {
+ this.id = null == id ? StarGraph.randomId() : id;
+ this.key = key;
+ this.value = value;
+ this.starVertex = starVertex;
+ }
+
+ @Override
+ public String key() {
+ return this.key;
+ }
+
+ @Override
+ public V value() throws NoSuchElementException {
+ return this.value;
+ }
+
+ @Override
+ public boolean isPresent() {
+ return true;
+ }
+
+ @Override
+ public Vertex element() {
+ return this.starVertex;
+ }
+
+ @Override
+ public void remove() {
+ this.starVertex.properties.get(this.key).remove(this);
+ }
+
+ @Override
+ public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
+ return null == this.properties ?
+ Collections.emptyIterator() :
+ (Iterator) this.properties.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
+ .map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
+ .iterator();
+ }
+
+ @Override
+ public Object id() {
+ return this.id;
+ }
+
+ @Override
+ public <U> Property<U> property(final String key, final U value) {
+ if (null == this.properties)
+ this.properties = new HashMap<>();
+ this.properties.put(key, value);
+ return new StarProperty<>(key, value, this);
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return ElementHelper.areEqual(this, other);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode((Element)this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
index 2afe369..af3ceb1 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.hadoop.structure.io;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
+import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -67,10 +68,10 @@ public final class VertexWritable implements Writable, Serializable {
this.vertex = HadoopPools.GRYO_POOL.doWithReader(gryoReader -> {
try {
final ByteArrayInputStream inputStream = new ByteArrayInputStream(WritableUtils.readCompressedByteArray(input));
- final Graph gLocal = TinkerGraph.open();
+ final StarGraph gLocal = StarGraph.open();
return gryoReader.readVertex(inputStream, Direction.BOTH,
- detachedVertex -> DetachedVertex.addTo(gLocal, detachedVertex),
- detachedEdge -> DetachedEdge.addTo(gLocal, detachedEdge));
+ detachedVertex -> StarGraph.addTo(gLocal, detachedVertex),
+ detachedEdge -> StarGraph.addTo(gLocal, detachedEdge));
} catch (final IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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 ec7649c..e77e60f 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
@@ -25,6 +25,7 @@ import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.LineRecordReader;
import org.apache.tinkerpop.gremlin.hadoop.Constants;
import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
+import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -63,9 +64,9 @@ public class GraphSONRecordReader extends RecordReader<NullWritable, VertexWrita
if (!this.lineRecordReader.nextKeyValue())
return false;
- final TinkerGraph gLocal = TinkerGraph.open();
- final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> DetachedVertex.addTo(gLocal, detachedVertex);
- final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> DetachedEdge.addTo(gLocal, detachedEdge);
+ final StarGraph gLocal = StarGraph.open();
+ final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> StarGraph.addTo(gLocal, detachedVertex);
+ final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> StarGraph.addTo(gLocal, detachedEdge);
try (InputStream in = new ByteArrayInputStream(this.lineRecordReader.getCurrentValue().getBytes())) {
this.vertexWritable.set(this.hasEdges ?
this.graphsonReader.readVertex(in, Direction.BOTH, vertexMaker, edgeMaker) :
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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 6422104..4862959 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
@@ -29,6 +29,7 @@ import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.tinkerpop.gremlin.hadoop.Constants;
import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
+import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -130,9 +131,9 @@ public class GryoRecordReader extends RecordReader<NullWritable, VertexWritable>
terminatorLocation = 0;
if (terminatorLocation >= TERMINATOR.length) {
- final Graph gLocal = TinkerGraph.open();
- final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> DetachedVertex.addTo(gLocal, detachedVertex);
- final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> DetachedEdge.addTo(gLocal, detachedEdge);
+ final StarGraph gLocal = StarGraph.open();
+ final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> StarGraph.addTo(gLocal, detachedVertex);
+ final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> StarGraph.addTo(gLocal, detachedEdge);
try (InputStream in = new ByteArrayInputStream(output.toByteArray())) {
this.vertexWritable.set(this.hasEdges ?
this.gryoReader.readVertex(in, Direction.BOTH, vertexMaker, edgeMaker) :
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d0d57813/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 51d1b51..59a0bf4 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
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.commons.io.FileUtils;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.process.traversal.T;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
@@ -141,14 +142,10 @@ public class TinkerGraphTest {
@Test
@Ignore
public void testPlay3() throws Exception {
- Graph graph = TinkerGraph.open();
- GraphTraversalSource g = graph.traversal(GraphTraversalSource.standard());
- final Vertex marko = graph.addVertex("name", "marko", "name", "marko a. rodriguez");
- marko.property(VertexProperty.Cardinality.list, "location", "san diego", "startTime", 1997, "endTime", 2001);
- marko.property(VertexProperty.Cardinality.list, "location", "santa cruz", "startTime", 2001, "endTime", 2004);
- marko.property(VertexProperty.Cardinality.list, "location", "brussels", "startTime", 2004, "endTime", 2005);
- marko.property(VertexProperty.Cardinality.list, "location", "santa fe", "startTime", 2005);
- g.V().valueMap().forEachRemaining(System.out::println);
+ 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);
}
@Test
[3/5] incubator-tinkerpop git commit: fixed an NPE with
StarVertex.vertices(BOTH).
Posted by ok...@apache.org.
fixed an NPE with StarVertex.vertices(BOTH).
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2fc49e1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2fc49e1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2fc49e1b
Branch: refs/heads/master
Commit: 2fc49e1b3045e9ad82410ecfd1141aaa861c96de
Parents: 1478e77
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Apr 7 15:35:54 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Apr 7 15:35:54 2015 -0600
----------------------------------------------------------------------
.../gremlin/process/computer/util/star/StarGraph.java | 11 ++++++++---
.../gremlin/process/computer/util/star/StarInEdge.java | 2 +-
.../gremlin/process/computer/util/star/StarInVertex.java | 2 +-
.../gremlin/process/computer/util/star/StarOutEdge.java | 2 +-
.../process/computer/util/star/StarOutVertex.java | 2 +-
.../gremlin/process/computer/util/star/StarProperty.java | 2 +-
.../gremlin/process/computer/util/star/StarVertex.java | 9 +++++++--
.../process/computer/util/star/StarVertexProperty.java | 2 +-
8 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/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 13c6a81..f9f0941 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
@@ -31,6 +31,7 @@ import org.apache.tinkerpop.gremlin.structure.Transaction;
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.detached.DetachedEdge;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
@@ -43,7 +44,7 @@ import java.util.stream.Stream;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarGraph implements Graph {
+public final class StarGraph implements Graph {
private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration();
@@ -66,7 +67,6 @@ 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(
@@ -116,6 +116,11 @@ public class StarGraph implements Graph {
}
+ @Override
+ public String toString() {
+ return StringFactory.graphString(this, "starOf:" + this.starVertex);
+ }
+
public static StarGraph open() {
return new StarGraph();
}
@@ -129,6 +134,7 @@ public class StarGraph implements Graph {
final VertexProperty<?> vertexProperty = graph.starVertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value());
detachedVertexProperty.properties().forEachRemaining(detachedVertexPropertyProperty -> {
vertexProperty.property(detachedVertexPropertyProperty.key(), detachedVertexPropertyProperty.value());
+ // todo: id of vertex property
});
});
return graph.starVertex;
@@ -150,5 +156,4 @@ public class StarGraph implements Graph {
protected static Long randomId() {
return new Random().nextLong(); // TODO: you shouldn't need this!
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
index 82da76e..5d382a8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
@@ -30,7 +30,7 @@ import java.util.Iterator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarInEdge extends StarEdge {
+public final class StarInEdge extends StarEdge {
private final StarOutVertex starOutVertex;
private final StarVertex starVertex;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
index cbdef7e..b9ea627 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
@@ -31,7 +31,7 @@ import java.util.List;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarInVertex extends StarAdjacentVertex {
+public final class StarInVertex extends StarAdjacentVertex {
public StarInVertex(final Object id, final StarVertex starVertex) {
super(id, starVertex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
index 4a1e795..533bea6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
@@ -30,7 +30,7 @@ import java.util.Iterator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarOutEdge extends StarEdge {
+public final class StarOutEdge extends StarEdge {
private final StarVertex starVertex;
private final StarInVertex starInVertex;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
index 82fdc3a..c6ead65 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
@@ -31,7 +31,7 @@ import java.util.List;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarOutVertex extends StarAdjacentVertex {
+public final class StarOutVertex extends StarAdjacentVertex {
public StarOutVertex(final Object id, final StarVertex starVertex) {
super(id, starVertex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
index 407ed3e..e884f30 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
@@ -29,7 +29,7 @@ import java.util.NoSuchElementException;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarProperty<V> implements Property<V> {
+public final class StarProperty<V> implements Property<V> {
private final String key;
private final V value;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/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 6b99ef2..a66657a 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
@@ -39,7 +39,7 @@ import java.util.stream.Stream;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarVertex extends StarElement implements Vertex {
+public final class StarVertex extends StarElement implements Vertex {
protected Map<String, List<VertexProperty<?>>> properties = null;
protected Map<String, List<Edge>> outEdges = new HashMap<>();
@@ -113,7 +113,12 @@ public class StarVertex extends StarElement implements Vertex {
.map(Edge::outVertex)
.iterator();
} else {
- return null;
+ return Stream.concat(this.outEdges.entrySet().stream(), this.inEdges.entrySet().stream())
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .map(Edge::outVertex)
+ .iterator();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2fc49e1b/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 1e09803..d3e35f5 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
@@ -36,7 +36,7 @@ import java.util.NoSuchElementException;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class StarVertexProperty<V> implements VertexProperty<V> {
+public final class StarVertexProperty<V> implements VertexProperty<V> {
private final Object id;
private final String key;
[2/5] incubator-tinkerpop git commit: StarGraph working with
SparkGraphComputer --- need to test multi-machine and optimize and I think we
have it.
Posted by ok...@apache.org.
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
[5/5] incubator-tinkerpop git commit: Merge branch 'star_graph'
Posted by ok...@apache.org.
Merge branch 'star_graph'
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/97d2bada
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/97d2bada
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/97d2bada
Branch: refs/heads/master
Commit: 97d2badaa505248dd95fb71c0a4d9a77900066bc
Parents: a05e8e5 65b4596
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 10:53:45 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 10:53:45 2015 -0600
----------------------------------------------------------------------
.../gremlin/structure/util/star/StarGraph.java | 639 +++++++++++++++++++
hadoop-gremlin/pom.xml | 5 -
.../process/computer/spark/SparkExecutor.java | 7 +-
.../hadoop/structure/io/VertexWritable.java | 11 +-
.../io/graphson/GraphSONRecordReader.java | 8 +-
.../structure/io/gryo/GryoRecordReader.java | 9 +-
.../structure/io/script/ScriptRecordReader.java | 6 +-
.../tinkergraph/structure/TinkerProperty.java | 3 +
.../tinkergraph/structure/TinkerGraphTest.java | 18 +-
9 files changed, 668 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/97d2bada/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
[4/5] incubator-tinkerpop git commit: StarGraph is now in
structure/util/star and all the tests fully pass for SparkGraphComputer and
GiraphGraphComputer (which leverage it). HadoopGremlin no longer depends on
TinkerGraph as StarGraph has replaced it.
Posted by ok...@apache.org.
StarGraph is now in structure/util/star and all the tests fully pass for SparkGraphComputer and GiraphGraphComputer (which leverage it). HadoopGremlin no longer depends on TinkerGraph as StarGraph has replaced 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/65b4596f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/65b4596f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/65b4596f
Branch: refs/heads/master
Commit: 65b4596f2ca50c6563568c85903d8e33fa9dcb4b
Parents: 2fc49e1
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 10:53:26 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 10:53:26 2015 -0600
----------------------------------------------------------------------
.../computer/util/star/StarAdjacentVertex.java | 104 ---
.../process/computer/util/star/StarEdge.java | 83 ---
.../process/computer/util/star/StarElement.java | 67 --
.../process/computer/util/star/StarGraph.java | 159 -----
.../process/computer/util/star/StarInEdge.java | 64 --
.../computer/util/star/StarInVertex.java | 51 --
.../process/computer/util/star/StarOutEdge.java | 63 --
.../computer/util/star/StarOutVertex.java | 51 --
.../computer/util/star/StarProperty.java | 68 --
.../process/computer/util/star/StarVertex.java | 141 ----
.../computer/util/star/StarVertexProperty.java | 112 ----
.../gremlin/structure/util/star/StarGraph.java | 639 +++++++++++++++++++
hadoop-gremlin/pom.xml | 5 -
.../process/computer/spark/SparkExecutor.java | 7 +-
.../hadoop/structure/io/VertexWritable.java | 12 +-
.../io/graphson/GraphSONRecordReader.java | 9 +-
.../structure/io/gryo/GryoRecordReader.java | 10 +-
.../structure/io/script/ScriptRecordReader.java | 6 +-
.../tinkergraph/structure/TinkerProperty.java | 3 +
.../tinkergraph/structure/TinkerGraphTest.java | 7 +-
20 files changed, 663 insertions(+), 998 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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
deleted file mode 100644
index 61228f0..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarAdjacentVertex.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-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.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;
-import java.util.Iterator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public abstract class StarAdjacentVertex implements Vertex {
-
- private final Object id;
- protected final StarVertex starVertex;
-
- protected StarAdjacentVertex(final Object id, final StarVertex starVertex) {
- this.id = id;
- this.starVertex = starVertex;
- }
-
- @Override
- public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
- throw Element.Exceptions.propertyAdditionNotSupported();
- }
-
- @Override
- public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
- return Collections.emptyIterator();
- }
-
- @Override
- public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
- return Collections.emptyIterator();
- }
-
- @Override
- public Object id() {
- return this.id;
- }
-
- @Override
- public String label() {
- return Vertex.DEFAULT_LABEL;
- }
-
- @Override
- public Graph graph() {
- return EmptyGraph.instance();
- }
-
- @Override
- public void remove() {
- throw Vertex.Exceptions.vertexRemovalNotSupported();
- }
-
- @Override
- public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
- return Collections.emptyIterator();
- }
-
- @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.vertexString(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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
deleted file mode 100644
index 7244610..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarEdge.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- *
- * * 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.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;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public abstract class StarEdge extends StarElement implements Edge {
-
- private Map<String, Object> properties = null;
-
- public StarEdge(final Object id, final String label) {
- super(id, label);
- }
-
- @Override
- public <V> Property<V> property(final String key, final V value) {
- if (null == this.properties)
- this.properties = new HashMap<>();
- this.properties.put(key, value);
- return new StarProperty<>(key, value,this);
- }
-
- @Override
- public <V> Iterator<Property<V>> properties(final String... propertyKeys) {
- return null == this.properties ?
- Collections.emptyIterator() :
- (Iterator) this.properties.entrySet()
- .stream()
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
- .map(entry -> new StarProperty<>(entry.getKey(), (V) entry.getValue(),this))
- .iterator();
- }
-
- @Override
- 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/65b4596f/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
deleted file mode 100644
index 8456ad3..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarElement.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *
- * * 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.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;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public abstract class StarElement implements Element {
-
- private final Object id;
- private final String label;
-
- protected StarElement(final Object id, final String label) {
- this.id = null == id ? StarGraph.randomId() : id;
- this.label = label;
- }
-
- @Override
- public Object id() {
- return this.id;
- }
-
- @Override
- public String label() {
- return this.label;
- }
-
- @Override
- public Graph graph() {
- return EmptyGraph.instance();
- }
-
- @Override
- public boolean equals(final Object other) {
- return ElementHelper.areEqual(this, other);
- }
-
- @Override
- public int hashCode() {
- return ElementHelper.hashCode(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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
deleted file mode 100644
index f9f0941..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarGraph.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
-import org.apache.tinkerpop.gremlin.process.traversal.T;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Transaction;
-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.detached.DetachedEdge;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.stream.Stream;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarGraph implements Graph {
-
- private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration();
-
- private StarVertex starVertex;
-
- @Override
- public Vertex addVertex(final Object... keyValues) {
- throw Graph.Exceptions.vertexAdditionsNotSupported();
- }
-
- @Override
- public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) throws IllegalArgumentException {
- throw Graph.Exceptions.graphComputerNotSupported();
- }
-
- @Override
- public GraphComputer compute() throws IllegalArgumentException {
- throw Graph.Exceptions.graphComputerNotSupported();
- }
-
- @Override
- public Iterator<Vertex> vertices(final Object... vertexIds) {
- return null == this.starVertex ?
- Collections.emptyIterator() :
- Stream.concat(
- Stream.of(this.starVertex),
- 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
- public Iterator<Edge> edges(final Object... edgeIds) {
- return null == this.starVertex ?
- Collections.emptyIterator() :
- Stream.concat(
- this.starVertex.inEdges.values().stream(),
- this.starVertex.outEdges.values().stream())
- .flatMap(List::stream)
- .filter(edge -> ElementHelper.idExists(edge.id(), edgeIds))
- .iterator();
- }
-
- @Override
- public Transaction tx() {
- throw Graph.Exceptions.transactionsNotSupported();
- }
-
- @Override
- public Variables variables() {
- throw Graph.Exceptions.variablesNotSupported();
- }
-
- @Override
- public Configuration configuration() {
- return EMPTY_CONFIGURATION;
- }
-
- @Override
- public void close() throws Exception {
-
- }
-
- @Override
- public String toString() {
- return StringFactory.graphString(this, "starOf:" + this.starVertex);
- }
-
- public static StarGraph open() {
- return new StarGraph();
- }
-
- public static Vertex addTo(final StarGraph graph, final DetachedVertex detachedVertex) {
- if (null != graph.starVertex)
- return null;
-
- graph.starVertex = new StarVertex(detachedVertex.id(), detachedVertex.label());
- detachedVertex.properties().forEachRemaining(detachedVertexProperty -> {
- final VertexProperty<?> vertexProperty = graph.starVertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value());
- detachedVertexProperty.properties().forEachRemaining(detachedVertexPropertyProperty -> {
- vertexProperty.property(detachedVertexPropertyProperty.key(), detachedVertexPropertyProperty.value());
- // todo: id of vertex property
- });
- });
- return graph.starVertex;
- }
-
- 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()));
- 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()));
- return inEdge;
- }
- }
-
- protected static Long randomId() {
- return new Random().nextLong(); // TODO: you shouldn't need this!
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
deleted file mode 100644
index 5d382a8..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInEdge.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-
-import java.util.Iterator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarInEdge extends StarEdge {
-
- private final StarOutVertex starOutVertex;
- private final StarVertex starVertex;
-
- public StarInEdge(final Object id, final StarOutVertex starOutVertex, final String label, final StarVertex starVertex) {
- super(id, label);
- this.starOutVertex = starOutVertex;
- this.starVertex = starVertex;
-
- }
-
- @Override
- public Iterator<Vertex> vertices(final Direction direction) {
- if (direction.equals(Direction.OUT))
- return IteratorUtils.of(this.starOutVertex);
- else if (direction.equals(Direction.IN))
- return IteratorUtils.of(this.starVertex);
- else
- return IteratorUtils.of(this.starOutVertex, this.starVertex);
- }
-
- @Override
- public Vertex outVertex() {
- return this.starOutVertex;
- }
-
- @Override
- public Vertex inVertex() {
- return this.starVertex;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
deleted file mode 100644
index b9ea627..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarInVertex.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarInVertex extends StarAdjacentVertex {
-
- public StarInVertex(final Object id, final StarVertex starVertex) {
- super(id, starVertex);
- }
-
- @Override
- public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
- List<Edge> outE = this.starVertex.outEdges.get(label);
- if (null == outE) {
- outE = new ArrayList<>();
- this.starVertex.outEdges.put(label, outE);
- }
- final StarOutEdge outEdge = new StarOutEdge(ElementHelper.getIdValue(keyValues).orElse(null), (StarVertex) inVertex, label, this);
- outE.add(outEdge);
- return outEdge;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
deleted file mode 100644
index 533bea6..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutEdge.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-
-import java.util.Iterator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarOutEdge extends StarEdge {
-
- private final StarVertex starVertex;
- private final StarInVertex starInVertex;
-
- public StarOutEdge(final Object id, final StarVertex starVertex, final String label, final StarInVertex starInVertex) {
- super(id, label);
- this.starVertex = starVertex;
- this.starInVertex = starInVertex;
- }
-
- @Override
- public Iterator<Vertex> vertices(final Direction direction) {
- if (direction.equals(Direction.OUT))
- return IteratorUtils.of(this.starVertex);
- else if (direction.equals(Direction.IN))
- return IteratorUtils.of(this.starInVertex);
- else
- return IteratorUtils.of(this.starVertex, this.starInVertex);
- }
-
- @Override
- public Vertex outVertex() {
- return this.starVertex;
- }
-
- @Override
- public Vertex inVertex() {
- return this.starInVertex;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
deleted file mode 100644
index c6ead65..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarOutVertex.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarOutVertex extends StarAdjacentVertex {
-
- public StarOutVertex(final Object id, final StarVertex starVertex) {
- super(id, starVertex);
- }
-
- @Override
- public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
- List<Edge> inE = this.starVertex.inEdges.get(label);
- if (null == inE) {
- inE = new ArrayList<>();
- this.starVertex.inEdges.put(label, inE);
- }
- final StarInEdge inEdge = new StarInEdge(ElementHelper.getIdValue(keyValues).orElse(null), this, label, (StarVertex) inVertex);
- inE.add(inEdge);
- return inEdge;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
deleted file mode 100644
index e884f30..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarProperty.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.Property;
-
-import java.util.NoSuchElementException;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarProperty<V> implements Property<V> {
-
- private final String key;
- private final V value;
- private final Element element;
-
- public StarProperty(final String key, final V value, final Element element) {
- this.key = key;
- this.value =value;
- this.element = element;
- }
-
- @Override
- public String key() {
- return this.key;
- }
-
- @Override
- public V value() throws NoSuchElementException {
- return this.value;
- }
-
- @Override
- public boolean isPresent() {
- return true;
- }
-
- @Override
- public Element element() {
- return this.element;
- }
-
- @Override
- public void remove() {
- throw Element.Exceptions.propertyRemovalNotSupported();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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
deleted file mode 100644
index a66657a..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertex.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Direction;
-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;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Stream;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarVertex extends StarElement implements Vertex {
-
- protected Map<String, List<VertexProperty<?>>> properties = null;
- protected Map<String, List<Edge>> outEdges = new HashMap<>();
- protected Map<String, List<Edge>> inEdges = new HashMap<>();
-
- public StarVertex(final Object id, final String label) {
- super(id, label);
- }
-
- @Override
- public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
- List<Edge> outE = this.outEdges.get(label);
- if (null == outE) {
- outE = new ArrayList<>();
- this.outEdges.put(label, outE);
- }
- final StarOutEdge outEdge = new StarOutEdge(ElementHelper.getIdValue(keyValues).orElse(null), this, label, (StarInVertex) inVertex);
- outE.add(outEdge);
- return outEdge;
- }
-
- @Override
- public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, V value, final Object... keyValues) {
- if (null == this.properties)
- 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, keyValues);
- list.add(vertexProperty);
- this.properties.put(key, list);
- return vertexProperty;
- }
-
- @Override
- public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
- if (direction.equals(Direction.OUT)) {
- return this.outEdges.entrySet().stream()
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
- .map(Map.Entry::getValue)
- .flatMap(List::stream)
- .iterator();
- } else if (direction.equals(Direction.IN)) {
- return this.inEdges.entrySet().stream()
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
- .map(Map.Entry::getValue)
- .flatMap(List::stream)
- .iterator();
- } else {
- return Stream.concat(this.inEdges.entrySet().stream(), this.outEdges.entrySet().stream())
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
- .map(Map.Entry::getValue)
- .flatMap(List::stream)
- .iterator();
- }
- }
-
- @Override
- public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
- if (direction.equals(Direction.OUT)) {
- return this.outEdges.entrySet().stream()
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
- .map(Map.Entry::getValue)
- .flatMap(List::stream)
- .map(Edge::inVertex)
- .iterator();
- } else if (direction.equals(Direction.IN)) {
- return this.inEdges.entrySet().stream()
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
- .map(Map.Entry::getValue)
- .flatMap(List::stream)
- .map(Edge::outVertex)
- .iterator();
- } else {
- return Stream.concat(this.outEdges.entrySet().stream(), this.inEdges.entrySet().stream())
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
- .map(Map.Entry::getValue)
- .flatMap(List::stream)
- .map(Edge::outVertex)
- .iterator();
- }
- }
-
- @Override
- public void remove() {
-
- }
-
- @Override
- public String toString() {
- return StringFactory.vertexString(this);
- }
-
- @Override
- public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
- return null == this.properties ?
- Collections.emptyIterator() :
- (Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).flatMap(entry -> entry.getValue().stream()).iterator();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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
deleted file mode 100644
index d3e35f5..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/star/StarVertexProperty.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- *
- * * 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.process.computer.util.star;
-
-import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class StarVertexProperty<V> implements VertexProperty<V> {
-
- private final Object id;
- private final String key;
- private final V value;
- private Map<String, Object> properties = null;
- private 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
- public String key() {
- return this.key;
- }
-
- @Override
- public V value() throws NoSuchElementException {
- return this.value;
- }
-
- @Override
- public boolean isPresent() {
- return true;
- }
-
- @Override
- public Vertex element() {
- return this.starVertex;
- }
-
- @Override
- public void remove() {
- this.starVertex.properties.get(this.key).remove(this);
- }
-
- @Override
- public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
- return null == this.properties ?
- Collections.emptyIterator() :
- (Iterator) this.properties.entrySet().stream()
- .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
- .map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
- .iterator();
- }
-
- @Override
- public Object id() {
- return this.id;
- }
-
- @Override
- public <U> Property<U> property(final String key, final U value) {
- if (null == this.properties)
- this.properties = new HashMap<>();
- this.properties.put(key, value);
- return new StarProperty<>(key, value, this);
- }
-
- @Override
- public boolean equals(final Object other) {
- return ElementHelper.areEqual(this, other);
- }
-
- @Override
- public int hashCode() {
- return ElementHelper.hashCode((Element)this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
new file mode 100644
index 0000000..fc01dbc
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -0,0 +1,639 @@
+/*
+ *
+ * * 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.util.star;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.T;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Transaction;
+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.detached.DetachedEdge;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+import java.util.stream.Stream;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class StarGraph implements Graph {
+
+ private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration();
+ private StarVertex starVertex = null;
+
+ @Override
+ public Vertex addVertex(final Object... keyValues) {
+ return null == this.starVertex ?
+ this.starVertex = new StarVertex(ElementHelper.getIdValue(keyValues).get(), ElementHelper.getLabelValue(keyValues).get()) :
+ new StarAdjacentVertex(ElementHelper.getIdValue(keyValues).get());
+ }
+
+ @Override
+ public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) throws IllegalArgumentException {
+ throw Graph.Exceptions.graphComputerNotSupported();
+ }
+
+ @Override
+ public GraphComputer compute() throws IllegalArgumentException {
+ throw Graph.Exceptions.graphComputerNotSupported();
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Object... vertexIds) {
+ if (null == this.starVertex)
+ return Collections.emptyIterator();
+ else if (ElementHelper.idExists(this.starVertex.id(), vertexIds))
+ return IteratorUtils.of(this.starVertex);
+ else
+ return Collections.emptyIterator();
+ // TODO: is this the semantics we want? the only "real vertex" is star vertex.
+ /*return null == this.starVertex ?
+ Collections.emptyIterator() :
+ Stream.concat(
+ Stream.of(this.starVertex),
+ 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
+ public Iterator<Edge> edges(final Object... edgeIds) {
+ return null == this.starVertex ?
+ Collections.emptyIterator() :
+ Stream.concat(
+ this.starVertex.inEdges.values().stream(),
+ this.starVertex.outEdges.values().stream())
+ .flatMap(List::stream)
+ .filter(edge -> ElementHelper.idExists(edge.id(), edgeIds))
+ .iterator();
+ }
+
+ @Override
+ public Transaction tx() {
+ throw Graph.Exceptions.transactionsNotSupported();
+ }
+
+ @Override
+ public Variables variables() {
+ throw Graph.Exceptions.variablesNotSupported();
+ }
+
+ @Override
+ public Configuration configuration() {
+ return EMPTY_CONFIGURATION;
+ }
+
+ @Override
+ public void close() throws Exception {
+
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.graphString(this, "starOf:" + this.starVertex);
+ }
+
+ public static StarGraph open() {
+ return new StarGraph();
+ }
+
+ public static Vertex addTo(final StarGraph graph, final DetachedVertex detachedVertex) {
+ if (null != graph.starVertex)
+ return null;
+
+ graph.addVertex(T.id, detachedVertex.id(), T.label, detachedVertex.label());
+ detachedVertex.properties().forEachRemaining(detachedVertexProperty -> {
+ final List<Object> keyValues = new ArrayList<>();
+ keyValues.add(T.id);
+ keyValues.add(detachedVertexProperty.id());
+ detachedVertexProperty.properties().forEachRemaining(detachedVertexPropertyProperty -> {
+ keyValues.add(detachedVertexPropertyProperty.key());
+ keyValues.add(detachedVertexPropertyProperty.value());
+ });
+ graph.starVertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value(), keyValues.toArray(new Object[keyValues.size()]));
+ });
+ return graph.starVertex;
+ }
+
+ public static Edge addTo(final StarGraph graph, final DetachedEdge edge) {
+ final List<Object> keyValues = new ArrayList<>();
+ keyValues.add(T.id);
+ keyValues.add(edge.id());
+ edge.properties().forEachRemaining(property -> {
+ keyValues.add(property.key());
+ keyValues.add(property.value());
+ });
+ return !graph.starVertex.id().equals(edge.inVertex().id()) ?
+ graph.starVertex.addOutEdge(edge.label(), edge.inVertex(), keyValues.toArray(new Object[keyValues.size()])) :
+ graph.starVertex.addInEdge(edge.label(), edge.outVertex(), keyValues.toArray(new Object[keyValues.size()]));
+ }
+
+ ///////////////////////
+ //// STAR ELEMENT ////
+ //////////////////////
+
+ public abstract class StarElement implements Element {
+
+ protected final Object id;
+ protected final String label;
+
+ protected StarElement(final Object id, final String label) {
+ this.id = id;
+ this.label = label;
+ }
+
+ @Override
+ public Object id() {
+ return this.id;
+ }
+
+ @Override
+ public String label() {
+ return this.label;
+ }
+
+ @Override
+ public Graph graph() {
+ return StarGraph.this;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return ElementHelper.areEqual(this, other);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode(this);
+ }
+ }
+
+ //////////////////////
+ //// STAR VERTEX ////
+ /////////////////////
+
+ public final class StarVertex extends StarElement implements Vertex {
+
+ private Map<String, List<Edge>> outEdges = new HashMap<>();
+ private Map<String, List<Edge>> inEdges = new HashMap<>();
+ private Map<String, List<VertexProperty>> vertexProperties = new HashMap<>();
+
+ public StarVertex(final Object id, final String label) {
+ super(id, label);
+ }
+
+ public void dropEdges() {
+ this.outEdges.clear();
+ this.inEdges.clear();
+ }
+
+ @Override
+ public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
+ return this.addOutEdge(label, inVertex, keyValues);
+ }
+
+ protected Edge addOutEdge(final String label, final Vertex inVertex, final Object... keyValues) {
+ List<Edge> outE = this.outEdges.get(label);
+ if (null == outE) {
+ outE = new ArrayList<>();
+ this.outEdges.put(label, outE);
+ }
+ final StarEdge outEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(UUID.randomUUID()), label, inVertex.id(), Direction.OUT);
+ ElementHelper.attachProperties(outEdge, keyValues);
+ outE.add(outEdge);
+ return outEdge;
+ }
+
+ protected Edge addInEdge(final String label, final Vertex outVertex, final Object... keyValues) {
+ List<Edge> inE = this.inEdges.get(label);
+ if (null == inE) {
+ inE = new ArrayList<>();
+ this.inEdges.put(label, inE);
+ }
+ final StarEdge inEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(UUID.randomUUID()), label, outVertex.id(), Direction.IN);
+ ElementHelper.attachProperties(inEdge, keyValues);
+ inE.add(inEdge);
+ return inEdge;
+ }
+
+ @Override
+ public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, V value, final Object... keyValues) {
+ final List<VertexProperty> list = cardinality.equals(VertexProperty.Cardinality.single) ? new ArrayList<>(1) : this.vertexProperties.getOrDefault(key, new ArrayList<>());
+ final VertexProperty<V> vertexProperty = new StarVertexProperty<>(ElementHelper.getIdValue(keyValues).orElse(UUID.randomUUID()), key, value);
+ ElementHelper.attachProperties(vertexProperty, keyValues);
+ list.add(vertexProperty);
+ this.vertexProperties.put(key, list);
+ return vertexProperty;
+ }
+
+ @Override
+ public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
+ if (direction.equals(Direction.OUT)) {
+ return this.outEdges.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .iterator();
+ } else if (direction.equals(Direction.IN)) {
+ return this.inEdges.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .iterator();
+ } else {
+ return Stream.concat(this.inEdges.entrySet().stream(), this.outEdges.entrySet().stream())
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .iterator();
+ }
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
+ if (direction.equals(Direction.OUT)) {
+ return IteratorUtils.map(this.edges(direction, edgeLabels), Edge::inVertex);
+ } else if (direction.equals(Direction.IN)) {
+ return IteratorUtils.map(this.edges(direction, edgeLabels), Edge::outVertex);
+ } else {
+ return IteratorUtils.<Vertex>concat(
+ IteratorUtils.map(this.edges(Direction.IN, edgeLabels), Edge::outVertex),
+ IteratorUtils.map(this.edges(Direction.OUT, edgeLabels), Edge::inVertex));
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new IllegalStateException("The star vertex can not be removed from the StarGraph: " + this);
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.vertexString(this);
+ }
+
+ @Override
+ public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
+ if (this.vertexProperties.isEmpty())
+ return Collections.emptyIterator();
+ else if (propertyKeys.length == 0)
+ return (Iterator) this.vertexProperties.entrySet().stream()
+ .flatMap(entry -> entry.getValue().stream())
+ .iterator();
+ else if (propertyKeys.length == 1)
+ return (Iterator) this.vertexProperties.getOrDefault(propertyKeys[0], Collections.emptyList()).iterator();
+ else
+ return (Iterator) this.vertexProperties.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
+ .flatMap(entry -> entry.getValue().stream())
+ .iterator();
+ }
+ }
+
+ ///////////////////////////////
+ //// STAR VERTEX PROPERTY ////
+ //////////////////////////////
+
+ public final class StarVertexProperty<V> extends StarElement implements VertexProperty<V> {
+
+ private final V value;
+ private Map<String, Object> metaProperties = null;
+
+ public StarVertexProperty(final Object id, final String key, final V value) {
+ super(id, key);
+ this.value = value;
+ }
+
+ @Override
+ public String key() {
+ return this.label;
+ }
+
+ @Override
+ public V value() throws NoSuchElementException {
+ return this.value;
+ }
+
+ @Override
+ public boolean isPresent() {
+ return true;
+ }
+
+ @Override
+ public Vertex element() {
+ return starVertex;
+ }
+
+ @Override
+ public void remove() {
+ StarGraph.this.starVertex.vertexProperties.get(this.label).remove(this);
+ }
+
+ @Override
+ public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
+ if (null == this.metaProperties)
+ return Collections.emptyIterator();
+ else if (propertyKeys.length == 0)
+ return (Iterator) this.metaProperties.entrySet().stream()
+ .map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
+ .iterator();
+ else if (propertyKeys.length == 1) {
+ final Object v = this.metaProperties.get(propertyKeys[0]);
+ return null == v ?
+ Collections.emptyIterator() :
+ (Iterator) IteratorUtils.of(new StarProperty<>(propertyKeys[0], v, this));
+ } else {
+ return (Iterator) this.metaProperties.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
+ .map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
+ .iterator();
+ }
+ }
+
+ @Override
+ public Object id() {
+ return this.id;
+ }
+
+ @Override
+ public <U> Property<U> property(final String key, final U value) {
+ if (null == this.metaProperties)
+ this.metaProperties = new HashMap<>();
+ this.metaProperties.put(key, value);
+ return new StarProperty<>(key, value, this);
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return ElementHelper.areEqual(this, other);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode((Element) this);
+ }
+ }
+
+
+ ///////////////////////////////
+ //// STAR ADJACENT VERTEX ////
+ //////////////////////////////
+
+ public class StarAdjacentVertex implements Vertex {
+
+ private final Object id;
+
+ protected StarAdjacentVertex(final Object id) {
+ this.id = id;
+ }
+
+ @Override
+ public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
+ if (!ElementHelper.areEqual(starVertex, inVertex))
+ throw new IllegalStateException("An adjacent vertex can only connect to the star vertex: " + starVertex);
+ return starVertex.addInEdge(label, this, keyValues);
+ }
+
+ @Override
+ public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
+ throw Element.Exceptions.propertyAdditionNotSupported();
+ }
+
+ @Override
+ public Iterator<Edge> edges(final Direction direction, final String... edgeLabels) {
+ return Collections.emptyIterator(); // TODO: just return to starVertex?
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
+ return Collections.emptyIterator(); // TODO: just return star vertex?
+ }
+
+ @Override
+ public Object id() {
+ return this.id;
+ }
+
+ @Override
+ public String label() {
+ return Vertex.DEFAULT_LABEL;
+ }
+
+ @Override
+ public Graph graph() {
+ return StarGraph.this;
+ }
+
+ @Override
+ public void remove() {
+ throw Vertex.Exceptions.vertexRemovalNotSupported();
+ }
+
+ @Override
+ public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
+ return Collections.emptyIterator();
+ }
+
+ @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.vertexString(this);
+ }
+ }
+
+ ////////////////////
+ //// STAR EDGE ////
+ ///////////////////
+
+ public final class StarEdge extends StarElement implements Edge {
+
+ private final Object otherId;
+ private final Direction direction;
+ private Map<String, Object> edgeProperties = null;
+
+ public StarEdge(final Object id, final String label, final Object otherId, final Direction direction) {
+ super(id, label);
+ this.otherId = otherId;
+ this.direction = direction;
+ }
+
+ @Override
+ public Iterator<Vertex> vertices(final Direction direction) {
+ if (direction.equals(Direction.OUT))
+ return IteratorUtils.of(this.outVertex());
+ else if (direction.equals(Direction.IN))
+ return IteratorUtils.of(this.inVertex());
+ else
+ return this.direction.equals(Direction.OUT) ?
+ IteratorUtils.of(starVertex, new StarAdjacentVertex(this.otherId)) :
+ IteratorUtils.of(new StarAdjacentVertex(this.otherId), starVertex);
+ }
+
+ public Vertex outVertex() {
+ return this.direction.equals(Direction.OUT) ? starVertex : new StarAdjacentVertex(this.otherId);
+ }
+
+ public Vertex inVertex() {
+ return this.direction.equals(Direction.OUT) ? new StarAdjacentVertex(this.otherId) : starVertex;
+ }
+
+ @Override
+ public <V> Property<V> property(final String key, final V value) {
+ if (null == this.edgeProperties)
+ this.edgeProperties = new HashMap<>();
+ this.edgeProperties.put(key, value);
+ return new StarProperty<>(key, value, this);
+ }
+
+ @Override
+ public <V> Iterator<Property<V>> properties(final String... propertyKeys) {
+ if (null == this.edgeProperties)
+ return Collections.emptyIterator();
+ else if (propertyKeys.length == 0)
+ return (Iterator) this.edgeProperties.entrySet().stream()
+ .map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
+ .iterator();
+ else if (propertyKeys.length == 1) {
+ final Object v = this.edgeProperties.get(propertyKeys[0]);
+ return null == v ?
+ Collections.emptyIterator() :
+ (Iterator) IteratorUtils.of(new StarProperty<>(propertyKeys[0], v, this));
+ } else {
+ return (Iterator) this.edgeProperties.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
+ .map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
+ .iterator();
+ }
+ }
+
+ @Override
+ 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);
+ }
+ }
+
+ ////////////////////////
+ //// STAR PROPERTY ////
+ ///////////////////////
+
+ public final class StarProperty<V> implements Property<V> {
+
+ private final String key;
+ private final V value;
+ private final Element element;
+
+ public StarProperty(final String key, final V value, final Element element) {
+ this.key = key;
+ this.value = value;
+ this.element = element;
+ }
+
+ @Override
+ public String key() {
+ return this.key;
+ }
+
+ @Override
+ public V value() throws NoSuchElementException {
+ return this.value;
+ }
+
+ @Override
+ public boolean isPresent() {
+ return true;
+ }
+
+ @Override
+ public Element element() {
+ return this.element;
+ }
+
+ @Override
+ public void remove() {
+ throw Element.Exceptions.propertyRemovalNotSupported();
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.propertyString(this);
+ }
+
+ @Override
+ public boolean equals(final Object object) {
+ return ElementHelper.areEqual(this, object);
+ }
+
+ @Override
+ public int hashCode() {
+ return ElementHelper.hashCode(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/hadoop-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/pom.xml b/hadoop-gremlin/pom.xml
index 28c6c02..1bb9c4d 100644
--- a/hadoop-gremlin/pom.xml
+++ b/hadoop-gremlin/pom.xml
@@ -37,11 +37,6 @@ limitations under the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.tinkerpop</groupId>
- <artifactId>tinkergraph-gremlin</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>${hadoop.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkExecutor.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkExecutor.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkExecutor.java
index 00ae3ab..1ff6552 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkExecutor.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkExecutor.java
@@ -41,8 +41,7 @@ import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.MessageCombiner;
import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
import org.apache.tinkerpop.gremlin.process.computer.util.ComputerGraph;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
@@ -140,13 +139,13 @@ public final class SparkExecutor {
public static <M> JavaPairRDD<Object, VertexWritable> prepareGraphRDDForMapReduce(final JavaPairRDD<Object, VertexWritable> graphRDD, final JavaPairRDD<Object, ViewIncomingPayload<M>> viewIncomingRDD) {
return (null == viewIncomingRDD) ?
graphRDD.mapValues(vertexWritable -> {
- vertexWritable.get().edges(Direction.BOTH).forEachRemaining(Edge::remove);
+ ((StarGraph.StarVertex)vertexWritable.get()).dropEdges();
return vertexWritable;
}) :
graphRDD.leftOuterJoin(viewIncomingRDD)
.mapValues(tuple -> {
final Vertex vertex = tuple._1().get();
- vertex.edges(Direction.BOTH).forEachRemaining(Edge::remove);
+ ((StarGraph.StarVertex)vertex).dropEdges();
final List<DetachedVertexProperty<Object>> view = tuple._2().isPresent() ? tuple._2().get().getView() : Collections.emptyList();
view.forEach(property -> DetachedVertexProperty.addTo(vertex, property));
return tuple._1();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
index af3ceb1..fad244b 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
@@ -20,14 +20,10 @@ package org.apache.tinkerpop.gremlin.hadoop.structure.io;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
-import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
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.tinkergraph.structure.TinkerGraph;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -68,10 +64,10 @@ public final class VertexWritable implements Writable, Serializable {
this.vertex = HadoopPools.GRYO_POOL.doWithReader(gryoReader -> {
try {
final ByteArrayInputStream inputStream = new ByteArrayInputStream(WritableUtils.readCompressedByteArray(input));
- final StarGraph gLocal = StarGraph.open();
+ final StarGraph starGraph = StarGraph.open();
return gryoReader.readVertex(inputStream, Direction.BOTH,
- detachedVertex -> StarGraph.addTo(gLocal, detachedVertex),
- detachedEdge -> StarGraph.addTo(gLocal, detachedEdge));
+ detachedVertex -> StarGraph.addTo(starGraph, detachedVertex),
+ detachedEdge -> StarGraph.addTo(starGraph, detachedEdge));
} catch (final IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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 e77e60f..87cfbb8 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
@@ -25,14 +25,13 @@ import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.LineRecordReader;
import org.apache.tinkerpop.gremlin.hadoop.Constants;
import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
-import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -64,9 +63,9 @@ public class GraphSONRecordReader extends RecordReader<NullWritable, VertexWrita
if (!this.lineRecordReader.nextKeyValue())
return false;
- final StarGraph gLocal = StarGraph.open();
- final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> StarGraph.addTo(gLocal, detachedVertex);
- final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> StarGraph.addTo(gLocal, detachedEdge);
+ final StarGraph starGraph = StarGraph.open();
+ final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> StarGraph.addTo(starGraph, detachedVertex);
+ final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> StarGraph.addTo(starGraph, detachedEdge);
try (InputStream in = new ByteArrayInputStream(this.lineRecordReader.getCurrentValue().getBytes())) {
this.vertexWritable.set(this.hasEdges ?
this.graphsonReader.readVertex(in, Direction.BOTH, vertexMaker, edgeMaker) :
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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 4862959..6a74f1e 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
@@ -29,16 +29,14 @@ import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.tinkerpop.gremlin.hadoop.Constants;
import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
-import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
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;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -131,9 +129,9 @@ public class GryoRecordReader extends RecordReader<NullWritable, VertexWritable>
terminatorLocation = 0;
if (terminatorLocation >= TERMINATOR.length) {
- final StarGraph gLocal = StarGraph.open();
- final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> StarGraph.addTo(gLocal, detachedVertex);
- final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> StarGraph.addTo(gLocal, detachedEdge);
+ final StarGraph starGraph = StarGraph.open();
+ final Function<DetachedVertex, Vertex> vertexMaker = detachedVertex -> StarGraph.addTo(starGraph, detachedVertex);
+ final Function<DetachedEdge, Edge> edgeMaker = detachedEdge -> StarGraph.addTo(starGraph, detachedEdge);
try (InputStream in = new ByteArrayInputStream(output.toByteArray())) {
this.vertexWritable.set(this.hasEdges ?
this.gryoReader.readVertex(in, Direction.BOTH, vertexMaker, edgeMaker) :
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
index 62d8e68..c9e2c94 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
@@ -32,7 +32,7 @@ import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
import org.apache.tinkerpop.gremlin.process.traversal.T;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import javax.script.Bindings;
import javax.script.ScriptEngine;
@@ -115,10 +115,10 @@ public class ScriptRecordReader extends RecordReader<NullWritable, VertexWritabl
protected class ScriptElementFactory {
- private final TinkerGraph graph;
+ private final StarGraph graph;
public ScriptElementFactory() {
- this.graph = TinkerGraph.open();
+ this.graph = StarGraph.open();
}
public Vertex vertex(final Object id) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerProperty.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerProperty.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerProperty.java
index c886b1e..28259ac 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerProperty.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerProperty.java
@@ -59,14 +59,17 @@ public class TinkerProperty<V> implements Property<V> {
return null != this.value;
}
+ @Override
public String toString() {
return StringFactory.propertyString(this);
}
+ @Override
public boolean equals(final Object object) {
return ElementHelper.areEqual(this, object);
}
+ @Override
public int hashCode() {
return ElementHelper.hashCode(this);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/65b4596f/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 23933f6..5e08a00 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
@@ -21,7 +21,7 @@ package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.commons.io.FileUtils;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.TestHelper;
-import org.apache.tinkerpop.gremlin.process.computer.util.star.StarGraph;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
import org.apache.tinkerpop.gremlin.process.traversal.T;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
@@ -30,7 +30,6 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Operator;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLWriter;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
@@ -38,7 +37,6 @@ 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;
import org.junit.Test;
@@ -146,8 +144,9 @@ public class TinkerGraphTest {
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)));
+ tg.vertices(1).next().edges(Direction.BOTH).forEachRemaining(e -> StarGraph.addTo(sg, DetachedFactory.detach(e, true)));
sg.vertices().forEachRemaining(System.out::println);
+ sg.edges().forEachRemaining(System.out::println);
}
@Test