fix dir bug for in direction edge
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/1f48e7b5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/1f48e7b5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/1f48e7b5 Branch: refs/heads/master Commit: 1f48e7b5cdcc407e8ac739b798ab547369b6594a Parents: a68e194 Author: daewon <dae...@apache.org> Authored: Thu Apr 5 15:49:39 2018 +0900 Committer: daewon <dae...@apache.org> Committed: Thu Apr 5 15:49:39 2018 +0900 ---------------------------------------------------------------------- .../scala/org/apache/s2graph/core/S2Edge.scala | 28 ++++++++++++++++++-- .../org/apache/s2graph/core/S2EdgeBuilder.scala | 4 +++ .../org/apache/s2graph/core/S2EdgeLike.scala | 4 +++ .../s2graph/graphql/bind/Unmarshaller.scala | 6 +++-- .../graphql/repository/GraphRepository.scala | 2 +- .../apache/s2graph/graphql/types/S2Type.scala | 2 +- 6 files changed, 40 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1f48e7b5/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala index f52acf3..3323c4a 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala @@ -41,7 +41,7 @@ import scala.util.hashing.MurmurHash3 object SnapshotEdge { def apply(e: S2EdgeLike): SnapshotEdge = { - val (smaller, larger) = (e.srcForVertex, e.tgtForVertex) + val (smaller, larger) = (e.srcForVertexInner, e.tgtForVertexInner) val snapshotEdge = SnapshotEdge(e.innerGraph, smaller, larger, e.innerLabel, GraphUtil.directions("out"), e.getOp(), e.getVersion(), e.getPropsWithTs(), @@ -814,6 +814,30 @@ object S2Edge { def srcForVertex(e: S2EdgeLike): S2VertexLike = { val belongLabelIds = Seq(e.getLabelId()) + + val column = if (e.getDir() == GraphUtil.directions("in")) { + getServiceColumn(e.tgtVertex, e.innerLabel.tgtColumn) + } else { + getServiceColumn(e.srcVertex, e.innerLabel.srcColumn) + } + + e.innerGraph.elementBuilder.newVertex(VertexId(column, e.srcVertex.innerId), e.srcVertex.ts, e.srcVertex.props, belongLabelIds = belongLabelIds) + } + + def tgtForVertex(e: S2EdgeLike): S2VertexLike = { + val belongLabelIds = Seq(e.getLabelId()) + + val column = if (e.getDir() == GraphUtil.directions("in")) { + getServiceColumn(e.srcVertex, e.innerLabel.srcColumn) + } else { + getServiceColumn(e.tgtVertex, e.innerLabel.tgtColumn) + } + + e.innerGraph.elementBuilder.newVertex(VertexId(column, e.tgtVertex.innerId), e.tgtVertex.ts, e.tgtVertex.props, belongLabelIds = belongLabelIds) + } + + def srcForVertexInner(e: S2EdgeLike): S2VertexLike = { + val belongLabelIds = Seq(e.getLabelId()) if (e.getDir() == GraphUtil.directions("in")) { val tgtColumn = getServiceColumn(e.tgtVertex, e.innerLabel.tgtColumn) e.innerGraph.elementBuilder.newVertex(VertexId(tgtColumn, e.tgtVertex.innerId), e.tgtVertex.ts, e.tgtVertex.props, belongLabelIds = belongLabelIds) @@ -823,7 +847,7 @@ object S2Edge { } } - def tgtForVertex(e: S2EdgeLike): S2VertexLike = { + def tgtForVertexInner(e: S2EdgeLike): S2VertexLike = { val belongLabelIds = Seq(e.getLabelId()) if (e.getDir() == GraphUtil.directions("in")) { val srcColumn = getServiceColumn(e.srcVertex, e.innerLabel.srcColumn) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1f48e7b5/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeBuilder.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeBuilder.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeBuilder.scala index 85321d3..5e8d094 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeBuilder.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeBuilder.scala @@ -31,6 +31,10 @@ class S2EdgeBuilder(edge: S2EdgeLike) { def tgtForVertex = S2Edge.tgtForVertex(edge) + def srcForVertexInner = S2Edge.srcForVertexInner(edge) + + def tgtForVertexInner = S2Edge.tgtForVertexInner(edge) + def duplicateEdge = reverseSrcTgtEdge.reverseDirEdge def reverseDirEdge = copyEdge(dir = GraphUtil.toggleDir(edge.getDir)) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1f48e7b5/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeLike.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeLike.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeLike.scala index f2ea4ad..3740f28 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeLike.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2EdgeLike.scala @@ -123,6 +123,10 @@ trait S2EdgeLike extends Edge with GraphElement { def tgtForVertex = builder.tgtForVertex + def srcForVertexInner = builder.srcForVertexInner + + def tgtForVertexInner = builder.tgtForVertexInner + def duplicateEdge = builder.duplicateEdge def reverseDirEdge = builder.reverseDirEdge http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1f48e7b5/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala index f7a360a..4308e2e 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/bind/Unmarshaller.scala @@ -144,9 +144,11 @@ object Unmarshaller { (vertices, canSkipFetch) } - def serviceColumnFieldOnLabel(column: ServiceColumn, c: Context[GraphRepository, Any]): (S2VertexLike, Boolean) = { + def serviceColumnFieldOnLabel(c: Context[GraphRepository, Any]): (S2VertexLike, Boolean) = { val edge = c.value.asInstanceOf[S2EdgeLike] - val vertex = if (edge.getDirection() == "in") edge.srcForVertex else edge.tgtForVertex + + val vertex = edge.tgtForVertex + val column = vertex.serviceColumn val selectedFields = AstHelper.selectedFields(c.astFields) val columnFields = column.metasInvMap.keySet http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1f48e7b5/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala index 4a3e8ea..d5b4aa8 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala @@ -92,7 +92,7 @@ class GraphRepository(val graph: S2GraphLike) { def getEdges(vertex: S2VertexLike, label: Label, _dir: String): Future[Seq[S2EdgeLike]] = { val dir = GraphUtil.directions(_dir) val labelWithDir = LabelWithDirection(label.id.get, dir) - val step = Step(Seq(QueryParam(labelWithDir).copy(limit = 100))) + val step = Step(Seq(QueryParam(labelWithDir).copy(limit = 2, includeDegree = false))) val q = Query(Seq(vertex), steps = Vector(step)) graph.getEdges(q).map(_.edgeWithScores.map(_.edge)) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/1f48e7b5/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala index eff0350..ca98df2 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala @@ -184,7 +184,7 @@ object S2Type { lazy val serviceColumnField: Field[GraphRepository, Any] = Field(column.columnName, labelColumnType, resolve = c => { implicit val ec = c.ctx.ec - val (vertex, canSkipFetchVertex) = Unmarshaller.serviceColumnFieldOnLabel(column, c) + val (vertex, canSkipFetchVertex) = Unmarshaller.serviceColumnFieldOnLabel(c) if (canSkipFetchVertex) Future.successful(vertex) else c.ctx.getVertices(Seq(vertex)).map(_.head) // fill props