You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by st...@apache.org on 2017/07/01 15:28:21 UTC

[30/46] incubator-s2graph git commit: Change EdgeId.

Change EdgeId.


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/ed035a32
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/ed035a32
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/ed035a32

Branch: refs/heads/master
Commit: ed035a3231e1dcc97f2de4f44f58ed12fc1a0d40
Parents: 0e47e11
Author: DO YUNG YOON <st...@apache.org>
Authored: Tue May 2 20:11:11 2017 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Tue May 2 20:11:11 2017 +0900

----------------------------------------------------------------------
 .../org/apache/s2graph/core/JSONParser.scala    |  3 +-
 .../scala/org/apache/s2graph/core/S2Edge.scala  |  9 +--
 .../apache/s2graph/core/io/Conversions.scala    |  8 +--
 .../core/tinkerpop/S2GraphProvider.scala        | 62 +++++++++++---------
 4 files changed, 45 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ed035a32/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala b/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala
index 2324e8e..a0767ae 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala
@@ -22,7 +22,7 @@ package org.apache.s2graph.core
 import org.apache.s2graph.core.GraphExceptions.IllegalDataTypeException
 import org.apache.s2graph.core.mysqls.LabelMeta
 import org.apache.s2graph.core.rest.TemplateHelper
-import org.apache.s2graph.core.types.{InnerValLikeWithTs, InnerVal, InnerValLike}
+import org.apache.s2graph.core.types.{InnerVal, InnerValLike, InnerValLikeWithTs, VertexId}
 import org.apache.s2graph.core.utils.logger
 import play.api.libs.json._
 
@@ -189,6 +189,7 @@ object JSONParser {
     val dType = InnerVal.toInnerDataType(dataType)
     val isNumeric = isNumericType(dType)
     any match {
+      case v: VertexId => v.innerId
       case a: InnerValLike => a
       case n: BigDecimal =>
         if (isNumeric) InnerVal.withNumber(n, version)

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ed035a32/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 eca8f18..5712754 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala
@@ -692,10 +692,11 @@ case class S2Edge(innerGraph: S2Graph,
     // NOTE: xxxForVertex makes direction to be "out"
     val timestamp = if (this.innerLabel.consistencyLevel == "strong") 0l else ts
 //    EdgeId(srcVertex.innerId, tgtVertex.innerId, label(), "out", timestamp)
+    val (srcColumn, tgtColumn) = innerLabel.srcTgtColumn(dir)
     if (direction == "out")
-      EdgeId(srcVertex.id.innerId, tgtVertex.id.innerId, label(), "out", timestamp)
+      EdgeId(VertexId(srcColumn, srcVertex.id.innerId), VertexId(tgtColumn, tgtVertex.id.innerId), label(), "out", timestamp)
     else
-      EdgeId(tgtVertex.id.innerId, srcVertex.id.innerId, label(), "out", timestamp)
+      EdgeId(VertexId(tgtColumn, tgtVertex.id.innerId), VertexId(srcColumn, srcVertex.id.innerId), label(), "out", timestamp)
   }
 
   override def id(): AnyRef = edgeId
@@ -721,8 +722,8 @@ object EdgeId {
   }
 }
 
-case class EdgeId(srcVertexId: InnerValLike,
-                  tgtVertexId: InnerValLike,
+case class EdgeId(srcVertexId: VertexId,
+                  tgtVertexId: VertexId,
                   labelName: String,
                   direction: String,
                   ts: Long) {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ed035a32/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala b/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
index f9cc861..077bb84 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
@@ -105,16 +105,16 @@ object Conversions {
     )(unlift(VertexId.unapply))
 
   implicit val s2EdgeIdReads: Reads[EdgeId] = (
-    (JsPath \ "srcVertexId").read[InnerValLike] and
-      (JsPath \ "tgtVertexId").read[InnerValLike] and
+    (JsPath \ "srcVertexId").read[VertexId] and
+      (JsPath \ "tgtVertexId").read[VertexId] and
       (JsPath \ "labelName").read[String] and
       (JsPath \ "direction").read[String] and
       (JsPath \ "ts").read[Long]
     )(EdgeId.apply _)
 
   implicit val s2EdgeIdWrites: Writes[EdgeId] = (
-    (JsPath \ "srcVertexId").write[InnerValLike] and
-      (JsPath \ "tgtVertexId").write[InnerValLike] and
+    (JsPath \ "srcVertexId").write[VertexId] and
+      (JsPath \ "tgtVertexId").write[VertexId] and
       (JsPath \ "labelName").write[String] and
       (JsPath \ "direction").write[String] and
       (JsPath \ "ts").write[Long]

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ed035a32/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
index d0761e1..74edd6d 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
@@ -4,10 +4,11 @@ import java.util
 
 import com.typesafe.config.ConfigFactory
 import org.apache.commons.configuration.Configuration
+import org.apache.s2graph.core.GraphExceptions.LabelNotExistException
 import org.apache.s2graph.core.Management.JsonModel.Prop
 import org.apache.s2graph.core.S2Graph.{DefaultColumnName, DefaultServiceName}
 import org.apache.s2graph.core._
-import org.apache.s2graph.core.mysqls.{ColumnMeta, Service, ServiceColumn}
+import org.apache.s2graph.core.mysqls.{ColumnMeta, Label, Service, ServiceColumn}
 import org.apache.s2graph.core.types.{HBaseType, InnerVal, VertexId}
 import org.apache.s2graph.core.utils.logger
 import org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData
@@ -239,31 +240,35 @@ class S2GraphProvider extends AbstractGraphProvider {
           options = Option("""{"skipReverse": false}"""))
       }
 
-    val friend = if (testClass.getSimpleName.contains("IoEdgeTest")) {
-      mnt.createLabel("friend", defaultService.serviceName, "person", "integer", defaultService.serviceName, "person", "integer",
-        true, defaultService.serviceName, Nil,
-        Seq(
-          Prop("name", "-", "string"),
-          Prop("location", "-", "string"),
-          Prop("status", "-", "string"),
-          Prop("weight", "0.0", "double"),
-          Prop("acl", "-", "string")
-        ), "strong", None, None,
-        options = Option("""{"skipReverse": false}"""))
-    } else {
-      mnt.createLabel("friend", defaultService.serviceName, defaultServiceColumn.columnName, defaultServiceColumn.columnType, defaultService.serviceName, defaultServiceColumn.columnName, defaultServiceColumn.columnType,
-        true, defaultService.serviceName, Nil,
-        Seq(
-          Prop("name", "-", "string"),
-          Prop("location", "-", "string"),
-          Prop("status", "-", "string"),
-          Prop("weight", "0.0", "double"),
-          Prop("acl", "-", "string")
-        ),
-        "strong", None, None,
-        options = Option("""{"skipReverse": false}""")
-      )
-    }
+    val friend =
+      if (testClass.getSimpleName == "IoEdgeTest") {
+        mnt.createLabel("friend",
+          defaultService.serviceName, "person", "integer",
+          defaultService.serviceName, "person", "integer",
+          true, defaultService.serviceName, Nil,
+          Seq(
+            Prop("name", "-", "string"),
+            Prop("location", "-", "string"),
+            Prop("status", "-", "string"),
+            Prop("weight", "0.0", "double"),
+            Prop("acl", "-", "string")
+          ), "strong", None, None,
+          options = Option("""{"skipReverse": false}"""))
+      } else {
+        mnt.createLabel("friend",
+          defaultService.serviceName, defaultServiceColumn.columnName, defaultServiceColumn.columnType,
+          defaultService.serviceName, defaultServiceColumn.columnName, defaultServiceColumn.columnType,
+          true, defaultService.serviceName, Nil,
+          Seq(
+            Prop("name", "-", "string"),
+            Prop("location", "-", "string"),
+            Prop("status", "-", "string"),
+            Prop("weight", "0.0", "double"),
+            Prop("acl", "-", "string")
+          ), "strong", None, None,
+          options = Option("""{"skipReverse": false}""")
+        )
+      }
 
     val hate = mnt.createLabel("hate", defaultService.serviceName, defaultServiceColumn.columnName, defaultServiceColumn.columnType, defaultService.serviceName, defaultServiceColumn.columnName, defaultServiceColumn.columnType,
       true, defaultService.serviceName, Nil, Nil, "strong", None, None,
@@ -325,9 +330,10 @@ class S2GraphProvider extends AbstractGraphProvider {
     if (isVertex) {
       VertexId(ServiceColumn.findAll().head, InnerVal.withStr(id.toString, HBaseType.DEFAULT_VERSION))
     } else {
+      val label = Label.findByName("_s2graph").getOrElse(throw new LabelNotExistException("_s2graph"))
       EdgeId(
-        InnerVal.withStr(id.toString, HBaseType.DEFAULT_VERSION),
-        InnerVal.withStr(id.toString, HBaseType.DEFAULT_VERSION),
+        VertexId(label.srcColumn, InnerVal.withStr(id.toString, HBaseType.DEFAULT_VERSION)),
+        VertexId(label.tgtColumn, InnerVal.withStr(id.toString, HBaseType.DEFAULT_VERSION)),
         "_s2graph",
         "out",
         System.currentTimeMillis()