You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/04/09 16:11:58 UTC
[01/15] 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/TINKERPOP3-581 0a2274514 -> 59028c8ad
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/TINKERPOP3-581
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
[03/15] incubator-tinkerpop git commit: fixed an NPE with
StarVertex.vertices(BOTH).
Posted by sp...@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/TINKERPOP3-581
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;
[09/15] incubator-tinkerpop git commit: If an ID does not exist use
an incrementing Long.
Posted by sp...@apache.org.
If an ID does not exist use an incrementing Long.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/11dbf0c3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/11dbf0c3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/11dbf0c3
Branch: refs/heads/TINKERPOP3-581
Commit: 11dbf0c3aa7ba14be45193981482a8661dafed96
Parents: fecf6e6
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 13:40:17 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 13:40:17 2015 -0600
----------------------------------------------------------------------
.../gremlin/structure/util/star/StarGraph.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/11dbf0c3/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
index fc01dbc..84e59e3 100644
--- 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
@@ -46,7 +46,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
-import java.util.UUID;
+import java.util.Random;
import java.util.stream.Stream;
/**
@@ -56,6 +56,7 @@ public final class StarGraph implements Graph {
private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration();
private StarVertex starVertex = null;
+ private Long nextId = 0l;
@Override
public Vertex addVertex(final Object... keyValues) {
@@ -172,6 +173,10 @@ public final class StarGraph implements Graph {
graph.starVertex.addInEdge(edge.label(), edge.outVertex(), keyValues.toArray(new Object[keyValues.size()]));
}
+ protected Long generateId() {
+ return this.nextId++;
+ }
+
///////////////////////
//// STAR ELEMENT ////
//////////////////////
@@ -242,7 +247,7 @@ public final class StarGraph implements Graph {
outE = new ArrayList<>();
this.outEdges.put(label, outE);
}
- final StarEdge outEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(UUID.randomUUID()), label, inVertex.id(), Direction.OUT);
+ final StarEdge outEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(generateId()), label, inVertex.id(), Direction.OUT);
ElementHelper.attachProperties(outEdge, keyValues);
outE.add(outEdge);
return outEdge;
@@ -254,7 +259,7 @@ public final class StarGraph implements Graph {
inE = new ArrayList<>();
this.inEdges.put(label, inE);
}
- final StarEdge inEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(UUID.randomUUID()), label, outVertex.id(), Direction.IN);
+ final StarEdge inEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(generateId()), label, outVertex.id(), Direction.IN);
ElementHelper.attachProperties(inEdge, keyValues);
inE.add(inEdge);
return inEdge;
@@ -263,7 +268,7 @@ public final class StarGraph implements Graph {
@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);
+ final VertexProperty<V> vertexProperty = new StarVertexProperty<>(ElementHelper.getIdValue(keyValues).orElse(generateId()), key, value);
ElementHelper.attachProperties(vertexProperty, keyValues);
list.add(vertexProperty);
this.vertexProperties.put(key, list);
[12/15] incubator-tinkerpop git commit: StarGraph edges and vertex
properties have half the number of references.
Posted by sp...@apache.org.
StarGraph edges and vertex properties have half the number of references.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/aabc66fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/aabc66fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/aabc66fa
Branch: refs/heads/TINKERPOP3-581
Commit: aabc66fa0a2929129e32f6fc53d8aaeaa6441473
Parents: d8fdf79
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 15:24:14 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 15:24:14 2015 -0600
----------------------------------------------------------------------
.../gremlin/structure/util/star/StarGraph.java | 137 +++++++++++--------
1 file changed, 83 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/aabc66fa/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
index a153d7f..fd9b52a 100644
--- 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
@@ -53,10 +53,16 @@ import java.util.stream.Stream;
*/
public final class StarGraph implements Graph {
- private static final Configuration EMPTY_CONFIGURATION = new BaseConfiguration();
+ private static final Configuration STAR_GRAPH_CONFIGURATION = new BaseConfiguration();
+ static {
+ STAR_GRAPH_CONFIGURATION.setProperty(Graph.GRAPH, StarGraph.class.getCanonicalName());
+ }
private StarVertex starVertex = null;
private Long nextId = 0l;
+ private final Map<Object, Map<String, Object>> edgeProperties = new HashMap<>();
+ private final Map<Object, Map<String, Object>> metaProperties = new HashMap<>();
+
@Override
public Vertex addVertex(final Object... keyValues) {
return null == this.starVertex ?
@@ -124,7 +130,7 @@ public final class StarGraph implements Graph {
@Override
public Configuration configuration() {
- return EMPTY_CONFIGURATION;
+ return STAR_GRAPH_CONFIGURATION;
}
@Override
@@ -154,7 +160,7 @@ public final class StarGraph implements Graph {
keyValues.add(detachedVertexPropertyProperty.key());
keyValues.add(detachedVertexPropertyProperty.value());
});
- graph.starVertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value(), keyValues.toArray(new Object[keyValues.size()]));
+ graph.starVertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value(), keyValues.toArray());
});
return graph.starVertex;
}
@@ -168,8 +174,8 @@ public final class StarGraph implements Graph {
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()]));
+ graph.starVertex.addOutEdge(edge.label(), edge.inVertex(), keyValues.toArray()) :
+ graph.starVertex.addInEdge(edge.label(), edge.outVertex(), keyValues.toArray());
}
protected Long generateId() {
@@ -246,7 +252,7 @@ public final class StarGraph implements Graph {
outE = new ArrayList<>();
this.outEdges.put(label, outE);
}
- final StarEdge outEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(generateId()), label, inVertex.id(), Direction.OUT);
+ final StarEdge outEdge = new StarOutEdge(ElementHelper.getIdValue(keyValues).orElse(generateId()), label, inVertex.id());
ElementHelper.attachProperties(outEdge, keyValues);
outE.add(outEdge);
return outEdge;
@@ -258,7 +264,7 @@ public final class StarGraph implements Graph {
inE = new ArrayList<>();
this.inEdges.put(label, inE);
}
- final StarEdge inEdge = new StarEdge(ElementHelper.getIdValue(keyValues).orElse(generateId()), label, outVertex.id(), Direction.IN);
+ final StarEdge inEdge = new StarInEdge(ElementHelper.getIdValue(keyValues).orElse(generateId()), label, outVertex.id());
ElementHelper.attachProperties(inEdge, keyValues);
inE.add(inEdge);
return inEdge;
@@ -345,7 +351,6 @@ public final class StarGraph implements Graph {
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);
@@ -379,19 +384,20 @@ public final class StarGraph implements Graph {
@Override
public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
- if (null == this.metaProperties)
+ final Map<String, Object> properties = metaProperties.get(this.id);
+ if (null == properties || properties.isEmpty())
return Collections.emptyIterator();
else if (propertyKeys.length == 0)
- return (Iterator) this.metaProperties.entrySet().stream()
+ return (Iterator) properties.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]);
+ final Object v = properties.get(propertyKeys[0]);
return null == v ?
Collections.emptyIterator() :
(Iterator) IteratorUtils.of(new StarProperty<>(propertyKeys[0], v, this));
} else {
- return (Iterator) this.metaProperties.entrySet().stream()
+ return (Iterator) properties.entrySet().stream()
.filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
.map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
.iterator();
@@ -399,15 +405,13 @@ public final class StarGraph implements Graph {
}
@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);
+ Map<String, Object> properties = metaProperties.get(this.id);
+ if (null == properties) {
+ properties = new HashMap<>();
+ metaProperties.put(this.id, properties);
+ }
+ properties.put(key, value);
return new StarProperty<>(key, value, this);
}
@@ -502,61 +506,42 @@ public final class StarGraph implements Graph {
//// STAR EDGE ////
///////////////////
- public final class StarEdge extends StarElement implements Edge {
+ public abstract class StarEdge extends StarElement implements Edge {
- private final Object otherId;
- private final Direction direction;
- private Map<String, Object> edgeProperties = null;
+ protected final Object otherId;
- public StarEdge(final Object id, final String label, final Object otherId, final Direction direction) {
+ public StarEdge(final Object id, final String label, final Object otherId) {
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);
+ Map<String, Object> properties = edgeProperties.get(this.id);
+ if (null == properties) {
+ properties = new HashMap<>();
+ edgeProperties.put(this.id, properties);
+ }
+ properties.put(key, value);
return new StarProperty<>(key, value, this);
}
@Override
public <V> Iterator<Property<V>> properties(final String... propertyKeys) {
- if (null == this.edgeProperties)
+ Map<String, Object> properties = edgeProperties.get(this.id);
+ if (null == properties || properties.isEmpty())
return Collections.emptyIterator();
else if (propertyKeys.length == 0)
- return (Iterator) this.edgeProperties.entrySet().stream()
+ return (Iterator) properties.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]);
+ final Object v = properties.get(propertyKeys[0]);
return null == v ?
Collections.emptyIterator() :
(Iterator) IteratorUtils.of(new StarProperty<>(propertyKeys[0], v, this));
} else {
- return (Iterator) this.edgeProperties.entrySet().stream()
+ return (Iterator) properties.entrySet().stream()
.filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys))
.map(entry -> new StarProperty<>(entry.getKey(), entry.getValue(), this))
.iterator();
@@ -564,8 +549,18 @@ public final class StarGraph implements Graph {
}
@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 IteratorUtils.of(this.outVertex(), this.inVertex());
+ }
+
+ @Override
public void remove() {
- //TODO: throw Edge.Exceptions.edgeRemovalNotSupported();
+ throw Edge.Exceptions.edgeRemovalNotSupported();
}
@Override
@@ -584,6 +579,40 @@ public final class StarGraph implements Graph {
}
}
+ public final class StarOutEdge extends StarEdge {
+
+ public StarOutEdge(final Object id, final String label, final Object otherId) {
+ super(id, label, otherId);
+ }
+
+ @Override
+ public Vertex outVertex() {
+ return starVertex;
+ }
+
+ @Override
+ public Vertex inVertex() {
+ return new StarAdjacentVertex(this.otherId);
+ }
+ }
+
+ public final class StarInEdge extends StarEdge {
+
+ public StarInEdge(final Object id, final String label, final Object otherId) {
+ super(id, label, otherId);
+ }
+
+ @Override
+ public Vertex outVertex() {
+ return new StarAdjacentVertex(this.otherId);
+ }
+
+ @Override
+ public Vertex inVertex() {
+ return starVertex;
+ }
+ }
+
////////////////////////
//// STAR PROPERTY ////
///////////////////////
[05/15] incubator-tinkerpop git commit: Merge branch 'TINKERPOP3-615'
of https://github.com/RedSeal-co/incubator-tinkerpop
Posted by sp...@apache.org.
Merge branch 'TINKERPOP3-615' of https://github.com/RedSeal-co/incubator-tinkerpop
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a05e8e55
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a05e8e55
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a05e8e55
Branch: refs/heads/TINKERPOP3-581
Commit: a05e8e5589d449fea001f6cfacdb85918e5d6d1f
Parents: 22f1752 116cdaf
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 08:41:16 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 08:41:16 2015 -0600
----------------------------------------------------------------------
.../gremlin/process/traversal/dsl/graph/GraphTraversal.java | 4 ++--
.../tinkerpop/gremlin/process/traversal/dsl/graph/__.java | 4 ++--
.../traversal/step/sideEffect/SideEffectCapStep.java | 9 +++++----
.../tinkerpop/gremlin/process/TraversalPerformanceTest.java | 4 ++--
.../gremlin/tinkergraph/structure/TinkerGraphTest.java | 2 +-
5 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
[13/15] incubator-tinkerpop git commit: if no edge labels are
required for Vertex.edges(), then use a faster iterator model than Streaming.
Posted by sp...@apache.org.
if no edge labels are required for Vertex.edges(), then use a faster iterator model than Streaming.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/c26342a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/c26342a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/c26342a7
Branch: refs/heads/TINKERPOP3-581
Commit: c26342a77f101f06d557068abdcac96509b23b4c
Parents: aabc66f
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 16:08:14 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 16:08:14 2015 -0600
----------------------------------------------------------------------
.../gremlin/structure/util/star/StarGraph.java | 46 ++++++++++----------
.../computer/spark/SparkGraphComputer.java | 3 --
2 files changed, 22 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c26342a7/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
index fd9b52a..0af926f 100644
--- 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
@@ -54,9 +54,11 @@ import java.util.stream.Stream;
public final class StarGraph implements Graph {
private static final Configuration STAR_GRAPH_CONFIGURATION = new BaseConfiguration();
+
static {
STAR_GRAPH_CONFIGURATION.setProperty(Graph.GRAPH, StarGraph.class.getCanonicalName());
}
+
private StarVertex starVertex = null;
private Long nextId = 0l;
@@ -283,37 +285,33 @@ public final class StarGraph implements Graph {
@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();
+ return edgeLabels.length == 0 ?
+ IteratorUtils.flatMap(this.outEdges.values().iterator(), List::iterator) :
+ 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();
- }
+ return edgeLabels.length == 0 ?
+ IteratorUtils.flatMap(this.inEdges.values().iterator(), List::iterator) :
+ this.inEdges.entrySet().stream()
+ .filter(entry -> ElementHelper.keyExists(entry.getKey(), edgeLabels))
+ .map(Map.Entry::getValue)
+ .flatMap(List::stream)
+ .iterator();
+ } else
+ return IteratorUtils.concat(this.edges(Direction.IN, edgeLabels), this.edges(Direction.OUT, edgeLabels));
}
@Override
public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels) {
- if (direction.equals(Direction.OUT)) {
+ if (direction.equals(Direction.OUT))
return IteratorUtils.map(this.edges(direction, edgeLabels), Edge::inVertex);
- } else if (direction.equals(Direction.IN)) {
+ 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));
- }
+ else
+ return IteratorUtils.concat(this.vertices(Direction.IN, edgeLabels), this.vertices(Direction.OUT, edgeLabels));
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c26342a7/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
index 9f3fd78..4b063bb 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
@@ -206,10 +206,7 @@ public final class SparkGraphComputer implements GraphComputer {
if (!this.mapReducers.isEmpty()) {
// drop all edges and messages in the graphRDD as they are no longer needed for the map reduce jobs
final JavaPairRDD<Object, VertexWritable> mapReduceGraphRDD = SparkExecutor.prepareGraphRDDForMapReduce(graphRDD, viewIncomingRDD).setName("mapReduceGraphRDD").cache();
- // TODO: boolean first = true;
for (final MapReduce mapReduce : this.mapReducers) {
- // TODO: if (first) first = false;
- // TODO: else graphRDD.unpersist(); // the original graphRDD is no longer needed so free up its memory
// execute the map reduce job
final HadoopConfiguration newApacheConfiguration = new HadoopConfiguration(apacheConfiguration);
mapReduce.storeState(newApacheConfiguration);
[15/15] incubator-tinkerpop git commit: Still trying to get all tests
to run after enforcing id types in TinkerGraph.
Posted by sp...@apache.org.
Still trying to get all tests to run after enforcing id types in TinkerGraph.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/59028c8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/59028c8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/59028c8a
Branch: refs/heads/TINKERPOP3-581
Commit: 59028c8ad18f23609e31220a59717a2bc05b78af
Parents: 53a06b7
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 9 10:10:59 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 9 10:10:59 2015 -0400
----------------------------------------------------------------------
.../traversal/step/sideEffect/GraphStep.java | 18 +--
.../apache/tinkerpop/gremlin/LoadGraphWith.java | 4 +-
.../process/traversal/CoreTraversalTest.java | 2 +-
.../tinkerpop/gremlin/structure/EdgeTest.java | 2 +-
.../tinkerpop/gremlin/structure/VertexTest.java | 11 +-
.../tinkergraph/structure/TinkerGraph.java | 135 ++++++++++++-------
.../tinkergraph/structure/TinkerHelper.java | 43 +++++-
.../tinkergraph/structure/TinkerVertex.java | 15 ++-
.../structure/TinkerVertexProperty.java | 13 +-
9 files changed, 158 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
index bb78fbe..832100e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GraphStep.java
@@ -50,24 +50,10 @@ public class GraphStep<S extends Element> extends StartStep<S> implements Engine
super(traversal);
this.returnClass = returnClass;
this.ids = ids;
- //validate that all elements are either ids or elements. mixed is not supported.
- boolean foundElements = false;
- for (Object id : this.ids) {
- boolean idIsElement = id instanceof Element;
- if (foundElements && !idIsElement) {
- throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
- } else {
- foundElements = foundElements || idIsElement;
- }
- }
- if (foundElements) {
- List<S> elementList = Arrays.asList(this.ids).stream().map(id->(S)id).collect(Collectors.toList());
- this.iteratorSupplier = elementList::iterator;
- } else {
- this.iteratorSupplier = () -> (Iterator<S>) (Vertex.class.isAssignableFrom(this.returnClass) ?
+
+ this.iteratorSupplier = () -> (Iterator<S>) (Vertex.class.isAssignableFrom(this.returnClass) ?
this.getTraversal().getGraph().get().vertices(this.ids) :
this.getTraversal().getGraph().get().edges(this.ids));
- }
}
public String toString() {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
index b893891..20dac12 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/LoadGraphWith.java
@@ -93,7 +93,7 @@ public @interface LoadGraphWith {
add(FeatureRequirement.Factory.create(FEATURE_MULTI_PROPERTIES, Graph.Features.VertexFeatures.class));
}};
- private static final List<FeatureRequirement> featuresRequiredByClassicDouble = new ArrayList<FeatureRequirement>() {{
+ private static final List<FeatureRequirement> featuresRequiredByModern = new ArrayList<FeatureRequirement>() {{
add(FeatureRequirement.Factory.create(FEATURE_STRING_VALUES, VertexPropertyFeatures.class));
add(FeatureRequirement.Factory.create(FEATURE_INTEGER_VALUES, VertexPropertyFeatures.class));
add(FeatureRequirement.Factory.create(FEATURE_DOUBLE_VALUES, EdgePropertyFeatures.class));
@@ -126,7 +126,7 @@ public @interface LoadGraphWith {
case CREW:
return featuresRequiredByCrew;
case MODERN:
- return featuresRequiredByClassicDouble;
+ return featuresRequiredByModern;
case GRATEFUL:
return featuresRequiredByGrateful;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
index b208290..75216a1 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
@@ -81,7 +81,7 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
- public void shouldLoadEdgesViaVertices() {
+ public void shouldLoadEdgesViaEdges() {
List<Edge> edges = g.E().toList();
List<Edge> edgesReloaded = g.E(edges.toArray()).toList();
assertEquals(edges.size(), edgesReloaded.size());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
index 35b427b..67eedf3 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/EdgeTest.java
@@ -120,7 +120,7 @@ public class EdgeTest {
@Test(expected = NoSuchElementException.class)
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldThrowNoSuchElementExceptionIfEdgeWithIdNotPresent() {
- g.E("this-id-should-not-be-in-the-modern-graph").next();
+ g.E(graphProvider.convertId(100)).next();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
index 7821601..c281e27 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/VertexTest.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.FeatureRequirement;
import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
import org.apache.tinkerpop.gremlin.GraphManager;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.traversal.FastNoSuchElementException;
import org.apache.tinkerpop.gremlin.process.traversal.T;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures;
@@ -136,14 +137,8 @@ public class VertexTest {
@Test(expected = NoSuchElementException.class)
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldThrowNoSuchElementExceptionIfVertexWithIdNotPresentViaTraversal() {
- graph.vertices("this-id-should-not-be-in-the-modern-graph").next();
- }
-
- @Test(expected = NoSuchElementException.class)
- @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldThrowNoSuchElementExceptionIfVertexWithIdNotPresentViaIterators() {
- graph.vertices("this-id-should-not-be-in-the-modern-graph").next();
+ public void shouldThrowNoSuchElementExceptionIfVertexWithIdNotPresent() {
+ graph.vertices(graphProvider.convertId(100)).next();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index 730c7ea..71d3eba 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@ -84,9 +84,9 @@ public class TinkerGraph implements Graph {
private final static TinkerGraph EMPTY_GRAPH = new TinkerGraph();
- private Class<?> vertexIdClass = null;
- private Class<?> edgeIdClass = null;
- private Class<?> vertexPropertyIdClass = null;
+ protected Class<?> vertexIdClass = null;
+ protected Class<?> edgeIdClass = null;
+ protected Class<?> vertexPropertyIdClass = null;
/**
* An empty private constructor that initializes {@link TinkerGraph}.
@@ -141,11 +141,13 @@ public class TinkerGraph implements Graph {
if (this.vertices.containsKey(idValue))
throw Exceptions.vertexWithIdAlreadyExists(idValue);
} else {
- idValue = TinkerHelper.getNextId(this);
+ idValue = TinkerHelper.getNextId(this, Vertex.class);
}
// todo: enforce vertex id consistency with tests
- if (vertexIdClass == null)
+ // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
+ // if there is a value, ensure that the expected type matches what was provided.
+ if (null == vertexIdClass)
vertexIdClass = idValue.getClass();
else if (!idValue.getClass().equals(vertexIdClass)) {
throw new IllegalStateException(String.format("Expecting a vertex identifier of %s but was %s", vertexIdClass, idValue.getClass()));
@@ -208,6 +210,7 @@ public class TinkerGraph implements Graph {
@Override
public Iterator<Vertex> vertices(final Object... vertexIds) {
+ // todo: this code looks a lot like edges() code - better reuse here somewhere?
if (0 == vertexIds.length) {
return this.vertices.values().iterator();
} else if (1 == vertexIds.length) {
@@ -242,50 +245,40 @@ public class TinkerGraph implements Graph {
}
}
- private UnaryOperator<Object> convertToId(final Object id, final Class<?> elementIdClass) {
- if (id instanceof Number) {
- if (elementIdClass != null) {
- if (elementIdClass.equals(Long.class)) {
- return o -> ((Number) o).longValue();
- } else if (elementIdClass.equals(Integer.class)) {
- return o -> ((Number) o).intValue();
- } else if (elementIdClass.equals(Double.class)) {
- return o -> ((Number) o).doubleValue();
- } else if (elementIdClass.equals(Float.class)) {
- return o -> ((Number) o).floatValue();
- } else if (elementIdClass.equals(String.class)) {
- return o -> o.toString();
- }
- }
- } else if (id instanceof String) {
- if (elementIdClass != null) {
- final String s = (String) id;
- if (elementIdClass.equals(Long.class)) {
- return o -> Long.parseLong(s);
- } else if (elementIdClass.equals(Integer.class)) {
- return o -> Integer.parseInt(s);
- } else if (elementIdClass.equals(Double.class)) {
- return o -> Double.parseDouble(s);
- } else if (elementIdClass.equals(Float.class)) {
- return o -> Float.parseFloat(s);
- } else if (elementIdClass.equals(UUID.class)) {
- return o -> UUID.fromString(s);
- }
- }
- }
-
- return UnaryOperator.identity();
- }
-
@Override
public Iterator<Edge> edges(final Object... edgeIds) {
if (0 == edgeIds.length) {
return this.edges.values().iterator();
} else if (1 == edgeIds.length) {
- final Edge edge = this.edges.get(edgeIds[0]);
- return null == edge ? Collections.emptyIterator() : IteratorUtils.of(edge);
- } else
- return Stream.of(edgeIds).map(this.edges::get).filter(Objects::nonNull).iterator();
+ if (edgeIds[0] instanceof Edge) {
+ // no need to get the edge again, so just flip it back - some implementation may want to treat this
+ // as a refresh operation. that's not necessary for tinkergraph.
+ return IteratorUtils.of((Edge) edgeIds[0]);
+ } else {
+ // convert the id to the expected data type and lookup the vertex
+ final UnaryOperator<Object> conversionFunction = convertToId(edgeIds[0], edgeIdClass);
+ final Edge edge = this.edges.get(conversionFunction.apply(edgeIds[0]));
+ return null == edge ? Collections.emptyIterator() : IteratorUtils.of(edge);
+ }
+ } else {
+ // base the conversion function on the first item in the id list as the expectation is that these
+ // id values will be a uniform list
+ if (edgeIds[0] instanceof Edge) {
+ // based on the first item assume all vertices in the argument list
+ if (!Stream.of(edgeIds).allMatch(id -> id instanceof Edge))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
+
+ // no need to get the vertices again, so just flip it back - some implementation may want to treat this
+ // as a refresh operation. that's not necessary for tinkergraph.
+ return Stream.of(edgeIds).map(id -> (Edge) id).iterator();
+ } else {
+ final Class<?> firstClass = edgeIds[0].getClass();
+ if (!Stream.of(edgeIds).map(Object::getClass).allMatch(firstClass::equals))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); // todo: change exception to be ids of the same type
+ final UnaryOperator<Object> conversionFunction = convertToId(edgeIds[0], vertexIdClass);
+ return Stream.of(edgeIds).map(conversionFunction).map(this.edges::get).filter(Objects::nonNull).iterator();
+ }
+ }
}
/**
@@ -325,11 +318,11 @@ public class TinkerGraph implements Graph {
public String toString() {
return StringFactory.featureString(this);
}
- }
+ }
public static class TinkerGraphVertexFeatures implements Features.VertexFeatures {
- static final TinkerGraphVertexFeatures INSTANCE = new TinkerGraphVertexFeatures();
+ static final TinkerGraphVertexFeatures INSTANCE = new TinkerGraphVertexFeatures();
private TinkerGraphVertexFeatures() {
}
@@ -337,11 +330,11 @@ public class TinkerGraph implements Graph {
public boolean supportsCustomIds() {
return false;
}
- }
+ }
public static class TinkerGraphEdgeFeatures implements Features.EdgeFeatures {
- static final TinkerGraphEdgeFeatures INSTANCE = new TinkerGraphEdgeFeatures();
+ static final TinkerGraphEdgeFeatures INSTANCE = new TinkerGraphEdgeFeatures();
private TinkerGraphEdgeFeatures() {
}
@@ -349,11 +342,11 @@ public class TinkerGraph implements Graph {
public boolean supportsCustomIds() {
return false;
}
- }
+ }
public static class TinkerGraphGraphFeatures implements Features.GraphFeatures {
- static final TinkerGraphGraphFeatures INSTANCE = new TinkerGraphGraphFeatures();
+ static final TinkerGraphGraphFeatures INSTANCE = new TinkerGraphGraphFeatures();
private TinkerGraphGraphFeatures() {
}
@@ -371,6 +364,7 @@ public class TinkerGraph implements Graph {
public boolean supportsThreadedTransactions() {
return false;
}
+
}
///////////// GRAPH SPECIFIC INDEXING METHODS ///////////////
@@ -429,4 +423,45 @@ public class TinkerGraph implements Graph {
throw new IllegalArgumentException("Class is not indexable: " + elementClass);
}
}
+
+ ///////////// HELPERS METHODS ///////////////
+
+ /**
+ * Function to coerce a provided identifier to a different type given the expected id type of an element.
+ * This allows something like {@code g.V(1,2,3)} and {@code g.V(1l,2l,3l)} to both mean the same thing.
+ */
+ private UnaryOperator<Object> convertToId(final Object id, final Class<?> elementIdClass) {
+ if (id instanceof Number) {
+ if (elementIdClass != null) {
+ if (elementIdClass.equals(Long.class)) {
+ return o -> ((Number) o).longValue();
+ } else if (elementIdClass.equals(Integer.class)) {
+ return o -> ((Number) o).intValue();
+ } else if (elementIdClass.equals(Double.class)) {
+ return o -> ((Number) o).doubleValue();
+ } else if (elementIdClass.equals(Float.class)) {
+ return o -> ((Number) o).floatValue();
+ } else if (elementIdClass.equals(String.class)) {
+ return o -> o.toString();
+ }
+ }
+ } else if (id instanceof String) {
+ if (elementIdClass != null) {
+ final String s = (String) id;
+ if (elementIdClass.equals(Long.class)) {
+ return o -> Long.parseLong(s);
+ } else if (elementIdClass.equals(Integer.class)) {
+ return o -> Integer.parseInt(s);
+ } else if (elementIdClass.equals(Double.class)) {
+ return o -> Double.parseDouble(s);
+ } else if (elementIdClass.equals(Float.class)) {
+ return o -> Float.parseFloat(s);
+ } else if (elementIdClass.equals(UUID.class)) {
+ return o -> UUID.fromString(s);
+ }
+ }
+ }
+
+ return UnaryOperator.identity();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
index c84d37c..1b1311e 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
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;
@@ -46,8 +47,35 @@ public final class TinkerHelper {
private TinkerHelper() {
}
- protected final synchronized static long getNextId(final TinkerGraph graph) {
- return Stream.generate(() -> (++graph.currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+ protected final synchronized static Number getNextId(final TinkerGraph graph, final Class<? extends Element> element) {
+ final Class<?> idClass;
+ if (Vertex.class.isAssignableFrom(element))
+ idClass = graph.vertexIdClass;
+ else if (Edge.class.isAssignableFrom(element))
+ idClass = graph.edgeIdClass;
+ else if (VertexProperty.class.isAssignableFrom(element))
+ idClass = graph.vertexPropertyIdClass;
+ else
+ throw new IllegalArgumentException(String.format("Unexpected request for id for %s", element));
+
+ final Number next = Stream.generate(() -> (++graph.currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+
+ // the class hasn't been set yet so assume Long - the class should be set by the caller after this
+ // value is returned
+ if (null == idClass)
+ return next.longValue();
+
+ if (idClass.equals(Long.class))
+ return next.longValue();
+ else if (idClass.equals(Integer.class))
+ return next.intValue();
+ else if (idClass.equals(Double.class))
+ return next.doubleValue();
+ else if (idClass.equals(Float.class))
+ return next.floatValue();
+ else
+ throw new IllegalStateException(String.format("TinkerGraph generates numeric identifiers, but this instance has already been initialized a identifier of type %s for %s", idClass, element));
+
}
protected static Edge addEdge(final TinkerGraph graph, final TinkerVertex outVertex, final TinkerVertex inVertex, final String label, final Object... keyValues) {
@@ -61,7 +89,16 @@ public final class TinkerHelper {
if (graph.edges.containsKey(idValue))
throw Graph.Exceptions.edgeWithIdAlreadyExists(idValue);
} else {
- idValue = TinkerHelper.getNextId(graph);
+ idValue = TinkerHelper.getNextId(graph, Edge.class);
+ }
+
+ // todo: enforce edge id consistency with tests
+ // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
+ // if there is a value, ensure that the expected type matches what was provided.
+ if (null == graph.edgeIdClass)
+ graph.edgeIdClass = idValue.getClass();
+ else if (!idValue.getClass().equals(graph.edgeIdClass)) {
+ throw new IllegalStateException(String.format("Expecting a edge identifier of %s but was %s", graph.edgeIdClass, idValue.getClass()));
}
edge = new TinkerEdge(idValue, outVertex, label, inVertex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
index 9cdc7db..a5713cc 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
@@ -96,9 +96,18 @@ public class TinkerVertex extends TinkerElement implements Vertex {
ElementHelper.attachProperties(vertexProperty, keyValues);
return vertexProperty;
} else {
- final VertexProperty<V> vertexProperty = optionalId.isPresent() ?
- new TinkerVertexProperty<V>(optionalId.get(), this, key, value) :
- new TinkerVertexProperty<V>(this, key, value);
+ final Object idValue = optionalId.isPresent() ? optionalId.get() : TinkerHelper.getNextId(graph, VertexProperty.class);
+
+ // todo: enforce vertexproperty id consistency with tests
+ // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
+ // if there is a value, ensure that the expected type matches what was provided.
+ if (null == graph.vertexPropertyIdClass)
+ graph.vertexPropertyIdClass = idValue.getClass();
+ else if (!idValue.getClass().equals(graph.vertexPropertyIdClass))
+ throw new IllegalStateException(String.format("Expecting a vertex identifier of %s but was %s", graph.vertexPropertyIdClass, idValue.getClass()));
+
+ final VertexProperty<V> vertexProperty = new TinkerVertexProperty<V>(idValue, this, key, value);
+
if (null == this.properties) this.properties = new HashMap<>();
final List<VertexProperty> list = this.properties.getOrDefault(key, new ArrayList<>());
list.add(vertexProperty);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/59028c8a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
index 66f15ea..2470733 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
@@ -19,11 +19,13 @@
package org.apache.tinkerpop.gremlin.tinkergraph.structure;
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.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.tinkergraph.process.computer.TinkerGraphView;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import java.util.Collections;
@@ -44,8 +46,13 @@ public class TinkerVertexProperty<V> extends TinkerElement implements VertexProp
private final String key;
private final V value;
+ /**
+ * This constructor will not validate the ID type against the {@link Graph}. It will always just use a
+ * {@code Long} for its identifier. This is useful for constructing a {@link VertexProperty} for usage
+ * with {@link TinkerGraphView}.
+ */
public TinkerVertexProperty(final TinkerVertex vertex, final String key, final V value, final Object... propertyKeyValues) {
- super(TinkerHelper.getNextId((TinkerGraph) vertex.graph()), key);
+ super(TinkerHelper.getNextId((TinkerGraph) vertex.graph(), VertexProperty.class), key);
this.vertex = vertex;
this.key = key;
this.value = value;
@@ -53,6 +60,10 @@ public class TinkerVertexProperty<V> extends TinkerElement implements VertexProp
ElementHelper.attachProperties(this, propertyKeyValues);
}
+ /**
+ * Use this constructor to construct {@link VertexProperty} instances for {@link TinkerGraph} where the {@code id}
+ * can be explicitly set and validated against the expected data type.
+ */
public TinkerVertexProperty(final Object id, final TinkerVertex vertex, final String key, final V value, final Object... propertyKeyValues) {
super(id, key);
this.vertex = vertex;
[06/15] 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 sp...@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/TINKERPOP3-581
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
[02/15] incubator-tinkerpop git commit: StarGraph working with
SparkGraphComputer --- need to test multi-machine and optimize and I think we
have it.
Posted by sp...@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/TINKERPOP3-581
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
[10/15] incubator-tinkerpop git commit: If an ID does not exist use
an incrementing Long.
Posted by sp...@apache.org.
If an ID does not exist use an incrementing Long.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/19ca8b69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/19ca8b69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/19ca8b69
Branch: refs/heads/TINKERPOP3-581
Commit: 19ca8b6951536a79f38bbe8cab80e1dd154d5de1
Parents: 11dbf0c
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 13:40:41 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 13:40:41 2015 -0600
----------------------------------------------------------------------
.../org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/19ca8b69/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
index 84e59e3..a153d7f 100644
--- 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
@@ -46,7 +46,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
-import java.util.Random;
import java.util.stream.Stream;
/**
[11/15] incubator-tinkerpop git commit: CHANGELOG is now M9 ready.
Added updates.
Posted by sp...@apache.org.
CHANGELOG is now M9 ready. Added updates.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d8fdf796
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d8fdf796
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d8fdf796
Branch: refs/heads/TINKERPOP3-581
Commit: d8fdf796527c59b08fd009bb6d22d13cd7f44c89
Parents: 19ca8b6
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 14:13:10 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 14:13:10 2015 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d8fdf796/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 129bccf..ad60aa3 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -22,6 +22,12 @@ TinkerPop 3.0.0 (A Gremlin Rāga in 7/16 Time)
image::http://www.tinkerpop.com/docs/current/images/gremlin-hindu.png[width=225]
+TinkerPop 3.0.0.M9 (NOT OFFICIALLY RELEASED YET)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* Added `StarGraph` which is a head efficient representation of a vertex and its incident edges (useful for `GraphComputer` implementations).
+* `TraverserSet` uses a `FastNoSuchElementException` on `remove()` for increased performance.
+
TinkerPop 3.0.0.M8 (Release Date: April 6, 2015)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[08/15] incubator-tinkerpop git commit: fixed a bug in
TraverserSet.remove() around iterator.remove(). Added setName() calls to RDDs
in SparkGraphComputer and SparkExecutor. However,
I don't see any difference in the Spark Server WebUI.
Posted by sp...@apache.org.
fixed a bug in TraverserSet.remove() around iterator.remove(). Added setName() calls to RDDs in SparkGraphComputer and SparkExecutor. However, I don't see any difference in the Spark Server WebUI.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/fecf6e6d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/fecf6e6d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/fecf6e6d
Branch: refs/heads/TINKERPOP3-581
Commit: fecf6e6db49d25ce49cdba546a16156f7a20a0e0
Parents: 97d2bad
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 8 13:08:18 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 8 13:08:18 2015 -0600
----------------------------------------------------------------------
.../process/traversal/traverser/util/TraverserSet.java | 6 ++----
.../gremlin/hadoop/process/computer/spark/SparkExecutor.java | 6 +++---
.../hadoop/process/computer/spark/SparkGraphComputer.java | 7 ++++---
3 files changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fecf6e6d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
index 9b6562d..f598a40 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
@@ -97,11 +97,9 @@ public class TraverserSet<S> extends AbstractSet<Traverser.Admin<S>> implements
@Override
public Traverser.Admin<S> remove() { // pop, exception if empty
final Iterator<Traverser.Admin<S>> iterator = this.map.values().iterator();
- if (!iterator.hasNext()) {
- throw FastNoSuchElementException.instance();
- }
+ if (!iterator.hasNext()) throw FastNoSuchElementException.instance();
Traverser.Admin<S> next = iterator.next();
- iterator.remove();
+ this.map.remove(next);
return next;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fecf6e6d/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 1ff6552..af5a9ff 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
@@ -71,7 +71,7 @@ public final class SparkExecutor {
final SparkMemory memory,
final Configuration apacheConfiguration) {
- final JavaPairRDD<Object, ViewOutgoingPayload<M>> viewOutgoingRDD = ((null == viewIncomingRDD) ?
+ final JavaPairRDD<Object, ViewOutgoingPayload<M>> viewOutgoingRDD = (((null == viewIncomingRDD) ?
graphRDD.mapValues(vertexWritable -> new Tuple2<>(vertexWritable, Optional.<ViewIncomingPayload<M>>absent())) : // first iteration will not have any views or messages
graphRDD.leftOuterJoin(viewIncomingRDD)) // every other iteration may have views and messages
// for each partition of vertices
@@ -98,7 +98,7 @@ public final class SparkExecutor {
workerVertexProgram.workerIterationEnd(memory); // if no more vertices in the partition, end the worker's iteration
return new Tuple2<>(vertex.id(), new ViewOutgoingPayload<>(nextView, outgoingMessages));
});
- });
+ })).setName("viewOutgoingRDD");
// "message pass" by reducing on the vertex object id of the view and message payloads
final MessageCombiner<M> messageCombiner = VertexProgram.<VertexProgram<M>>createVertexProgram(apacheConfiguration).getMessageCombiner().orElse(null);
@@ -126,7 +126,7 @@ public final class SparkExecutor {
(ViewIncomingPayload<M>) payload : // this happens if there is a vertex with incoming messages
new ViewIncomingPayload<>((ViewPayload) payload)); // this happens if there is a vertex with no incoming messages
- newViewIncomingRDD
+ newViewIncomingRDD.setName("viewIncomingRDD")
.foreachPartition(partitionIterator -> {
}); // need to complete a task so its BSP and the memory for this iteration is updated
return newViewIncomingRDD;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fecf6e6d/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
index 1df99d3..9f3fd78 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/spark/SparkGraphComputer.java
@@ -164,6 +164,7 @@ public final class SparkGraphComputer implements GraphComputer {
VertexWritable.class)
.mapToPair(tuple -> new Tuple2<>(tuple._2().get().id(), new VertexWritable(tuple._2().get())))
.reduceByKey((a, b) -> a) // TODO: why is this necessary?
+ .setName("graphRDD")
.cache(); // partition the graph across the cluster
JavaPairRDD<Object, ViewIncomingPayload<Object>> viewIncomingRDD = null;
@@ -204,7 +205,7 @@ public final class SparkGraphComputer implements GraphComputer {
//////////////////////////////
if (!this.mapReducers.isEmpty()) {
// drop all edges and messages in the graphRDD as they are no longer needed for the map reduce jobs
- final JavaPairRDD<Object, VertexWritable> mapReduceGraphRDD = SparkExecutor.prepareGraphRDDForMapReduce(graphRDD, viewIncomingRDD).cache();
+ final JavaPairRDD<Object, VertexWritable> mapReduceGraphRDD = SparkExecutor.prepareGraphRDDForMapReduce(graphRDD, viewIncomingRDD).setName("mapReduceGraphRDD").cache();
// TODO: boolean first = true;
for (final MapReduce mapReduce : this.mapReducers) {
// TODO: if (first) first = false;
@@ -213,10 +214,10 @@ public final class SparkGraphComputer implements GraphComputer {
final HadoopConfiguration newApacheConfiguration = new HadoopConfiguration(apacheConfiguration);
mapReduce.storeState(newApacheConfiguration);
// map
- final JavaPairRDD mapRDD = SparkExecutor.executeMap((JavaPairRDD) mapReduceGraphRDD, mapReduce, newApacheConfiguration);
+ final JavaPairRDD mapRDD = SparkExecutor.executeMap((JavaPairRDD) mapReduceGraphRDD, mapReduce, newApacheConfiguration).setName("mapRDD");
// combine TODO? is this really needed
// reduce
- final JavaPairRDD reduceRDD = (mapReduce.doStage(MapReduce.Stage.REDUCE)) ? SparkExecutor.executeReduce(mapRDD, mapReduce, newApacheConfiguration) : null;
+ final JavaPairRDD reduceRDD = (mapReduce.doStage(MapReduce.Stage.REDUCE)) ? SparkExecutor.executeReduce(mapRDD, mapReduce, newApacheConfiguration).setName("reduceRDD") : null;
// write the map reduce output back to disk (memory)
SparkExecutor.saveMapReduceRDD(null == reduceRDD ? mapRDD : reduceRDD, mapReduce, finalMemory, hadoopConfiguration);
}
[14/15] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/master' into TINKERPOP3-581
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/master' into TINKERPOP3-581
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/53a06b7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/53a06b7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/53a06b7c
Branch: refs/heads/TINKERPOP3-581
Commit: 53a06b7c263077527230a28e3c47256fd8321928
Parents: 0a22745 c26342a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 9 08:24:52 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 9 08:24:52 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 6 +
.../traversal/dsl/graph/GraphTraversal.java | 4 +-
.../gremlin/process/traversal/dsl/graph/__.java | 4 +-
.../step/sideEffect/SideEffectCapStep.java | 9 +-
.../traversal/traverser/util/TraverserSet.java | 6 +-
.../gremlin/structure/util/star/StarGraph.java | 670 +++++++++++++++++++
.../process/TraversalPerformanceTest.java | 4 +-
hadoop-gremlin/pom.xml | 5 -
.../process/computer/spark/SparkExecutor.java | 13 +-
.../computer/spark/SparkGraphComputer.java | 10 +-
.../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 | 20 +-
16 files changed, 726 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
[07/15] incubator-tinkerpop git commit: Merge branch 'star_graph'
Posted by sp...@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/TINKERPOP3-581
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
----------------------------------------------------------------------
[04/15] incubator-tinkerpop git commit: TINKERPOP3-615 cap(String,
String...) to require at least one side effect key
Posted by sp...@apache.org.
TINKERPOP3-615 cap(String, String...) to require at least one side effect key
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/116cdaf2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/116cdaf2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/116cdaf2
Branch: refs/heads/TINKERPOP3-581
Commit: 116cdaf27c9bd04a6df26a818ff92c4e85b2c6ba
Parents: 7163400
Author: mfrantz <mf...@redsealnetworks.com>
Authored: Tue Apr 7 16:37:50 2015 -0700
Committer: mfrantz <mf...@redsealnetworks.com>
Committed: Tue Apr 7 16:40:13 2015 -0700
----------------------------------------------------------------------
.../gremlin/process/traversal/dsl/graph/GraphTraversal.java | 4 ++--
.../tinkerpop/gremlin/process/traversal/dsl/graph/__.java | 4 ++--
.../traversal/step/sideEffect/SideEffectCapStep.java | 9 +++++----
.../tinkerpop/gremlin/process/TraversalPerformanceTest.java | 4 ++--
.../gremlin/tinkergraph/structure/TinkerGraphTest.java | 2 +-
5 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/116cdaf2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 6208468..acfd01a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -594,8 +594,8 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
return this.asAdmin().addStep(new LambdaSideEffectStep<>(this.asAdmin(), consumer));
}
- public default <E2> GraphTraversal<S, E2> cap(final String... sideEffectKeys) {
- return this.asAdmin().addStep(new SideEffectCapStep<>(this.asAdmin(), sideEffectKeys));
+ public default <E2> GraphTraversal<S, E2> cap(final String sideEffectKey, final String... sideEffectKeys) {
+ return this.asAdmin().addStep(new SideEffectCapStep<>(this.asAdmin(), sideEffectKey, sideEffectKeys));
}
public default GraphTraversal<S, Edge> subgraph(final String sideEffectKey) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/116cdaf2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
index 926968e..f34ba71 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
@@ -449,8 +449,8 @@ public class __ {
return __.<A>start().sideEffect(consumer);
}
- public static <A, E2> GraphTraversal<A, E2> cap(final String... sideEffectKeys) {
- return __.<A>start().cap(sideEffectKeys);
+ public static <A, E2> GraphTraversal<A, E2> cap(final String sideEffectKey, String... sideEffectKeys) {
+ return __.<A>start().cap(sideEffectKey, sideEffectKeys);
}
public static <A> GraphTraversal<A, Edge> subgraph(final String sideEffectKey) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/116cdaf2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
index 28f1cf0..32e7d86 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.SupplyingBarrier
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
@@ -42,11 +43,11 @@ public final class SideEffectCapStep<S, E> extends SupplyingBarrierStep<S, E> {
private List<String> sideEffectKeys;
- public SideEffectCapStep(final Traversal.Admin traversal, final String... sideEffectKeys) {
+ public SideEffectCapStep(final Traversal.Admin traversal, final String sideEffectKey, final String... sideEffectKeys) {
super(traversal);
- if (0 == sideEffectKeys.length)
- throw new IllegalArgumentException("At least one sideEffect key must be provided to " + this.getClass().getSimpleName());
- this.sideEffectKeys = Arrays.asList(sideEffectKeys);
+ this.sideEffectKeys = new ArrayList(1 + sideEffectKeys.length);
+ this.sideEffectKeys.add(sideEffectKey);
+ this.sideEffectKeys.addAll(Arrays.asList(sideEffectKeys));
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/116cdaf2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalPerformanceTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalPerformanceTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalPerformanceTest.java
index 5bf7542..2953464 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalPerformanceTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalPerformanceTest.java
@@ -108,7 +108,7 @@ public class TraversalPerformanceTest extends AbstractGremlinTest {
@LoadGraphWith(LoadGraphWith.GraphData.GRATEFUL)
@Test
public void g_V_label_groupCount_cap() throws Exception {
- g.V().label().groupCount().cap().iterate();
+ g.V().label().groupCount("x").cap("x").iterate();
}
@BenchmarkOptions(benchmarkRounds = DEFAULT_BENCHMARK_ROUNDS, warmupRounds = DEFAULT_WARMUP_ROUNDS, concurrency = BenchmarkOptions.CONCURRENCY_SEQUENTIAL)
@@ -127,4 +127,4 @@ public class TraversalPerformanceTest extends AbstractGremlinTest {
public void g_E_hasLabelXwrittenByX_hasNotXinV_inEXsungByXX_subgraphXsgX() throws Exception {
g.E().hasLabel("writtenBy").hasNot(__.inV().inE("sungBy")).subgraph("sg").iterate();
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/116cdaf2/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..4e0cc00 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
@@ -187,7 +187,7 @@ public class TinkerGraphTest {
@Ignore
public void testPlayDK() throws Exception {
GraphTraversalSource g = TinkerFactory.createModern().traversal();
- Traversal t = g.V().hasLabel("person").as("person").local(bothE().label().groupCount().cap()).as("relations").select().by("name").by();
+ Traversal t = g.V().hasLabel("person").as("person").local(bothE().label().groupCount("x").cap("x")).as("relations").select().by("name").by();
t.forEachRemaining(System.out::println);
System.out.println("--");