add optimization parameter for S2Graph#vertices.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/42e4fa13 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/42e4fa13 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/42e4fa13 Branch: refs/heads/master Commit: 42e4fa1311a9bf883919a0f96d97e81bccb5cd3b Parents: 7310631 Author: DO YUNG YOON <steams...@apache.org> Authored: Mon Nov 28 23:52:58 2016 +0900 Committer: DO YUNG YOON <steams...@apache.org> Committed: Mon Nov 28 23:52:58 2016 +0900 ---------------------------------------------------------------------- .../scala/org/apache/s2graph/core/S2Graph.scala | 26 ++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/42e4fa13/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala index 51a80f9..b3f3ac8 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala @@ -1336,17 +1336,33 @@ class S2Graph(_config: Config)(implicit val ec: ExecutionContext) extends Graph } } + /** + * used by graph.traversal().V() + * @param vertexIds: array of VertexId values. note that last parameter can be used to control if actually fetch vertices from storage or not. + * since S2Graph use user-provided id as part of edge, it is possible to + * fetch edge without fetch start vertex. default is false which means we are not fetching vertices from storage. + * @return + */ override def vertices(vertexIds: AnyRef*): util.Iterator[structure.Vertex] = { + val fetchVertices = vertexIds.lastOption.map { lastParam => + if (lastParam.isInstanceOf[Boolean]) lastParam.asInstanceOf[Boolean] + else false + }.getOrElse(false) + val vertices = for { vertexId <- vertexIds if vertexId.isInstanceOf[VertexId] } yield newVertex(vertexId.asInstanceOf[VertexId]) - val future = getVertices(vertices).map { vs => - val ls = new util.ArrayList[structure.Vertex]() - ls.addAll(vs) - ls.iterator() + if (fetchVertices) { + val future = getVertices(vertices).map { vs => + val ls = new util.ArrayList[structure.Vertex]() + ls.addAll(vs) + ls.iterator() + } + Await.result(future, WaitTimeout) + } else { + vertices.iterator } - Await.result(future, WaitTimeout) } override def tx(): Transaction = ???